ROS程序发布随机速到turltlesim
来源:互联网 发布:json后台传值到前台 编辑:程序博客网 时间:2024/06/07 12:33
参考自“机器人操作系统浅析”
ROS程序-helloworld
ROS程序-velocity-publish
软件包agitr——helloworld
src/agitr/hello.cpp
//This is first ros package of standard "hello world" program#include <ros/ros.h>int main(int argc ,char** argv){ ros::init(argc,argv,"hello_ros");//node name : ros::NodeHandle nh; ROS_INFO_STREAM("hello, ROS!");}
src/agitr/package.xml
<?xml version="1.0"?><package> <name>agitr</name> <version>0.0.0</version> <description>LEEMAN_CAFFEE</description> <maintainer email="mli@leemanchina.com">HOPPS</maintainer> <license>BSD</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>geometry_msgs</build_depend> <build_depend>turtlesim</build_depend> <run_depend>roscpp</run_depend> <run_depend>geometry_msgs</run_depend> <run_depend>turtlesim</run_depend>
src/agitr/CMakeList.txt
cmake_minimum_required(VERSION 2.8.3)project(agitr)find_package(catkin REQUIRED COMPONENTS roscpp geometry_msgs)##下面()中#不能去除catkin_package(# INCLUDE_DIRS include# LIBRARIES agitr# CATKIN_DEPENDS other_catkin_pkg# DEPENDS system_lib)add_executable(hello hello.cpp)target_link_libraries(hello ${catkin_LIBRARIES})
source devel/setup.bash
rosrun agitr hello
pubvel 随机速度发布
src/pubvel/pubvel.cpp
//This is a first Velocity topic publish program#include <ros/ros.h>#include <geometry_msgs/Twist.h>#include <stdlib.h>int main(int argc,char** argv){ ros::init(argc,argv,"velocitypublish"); ros::NodeHandle nh; ros::Publisher pub=nh.advertise<geometry_msgs::Twist>("turtle1/cmd_vel",1000); srand(time(0)); ros::Rate rate(2); while(ros::ok()){ geometry_msgs::Twist msg; msg.linear.x=double(rand())/double(RAND_MAX); msg.angular.z=2*double(rand())/double(RAND_MAX)-1; pub.publish(msg); ROS_INFO_STREAM("Sending random velocity command:"<<"linear="<<msg.linear.x<<"angular=msg.angular.z"<<msg.angular.z); rate.sleep();}}
src/pubvel/CMakeList.txt
<?xml version="1.0"?><package> <name>pubvel</name> <version>0.0.0</version> <description>LEEMAN_CAFFEE</description> <license>BSD</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>geometry_msgs</build_depend> <build_depend>turtlesim</build_depend> <run_depend>roscpp</run_depend> <run_depend>geometry_msgs</run_depend> <run_depend>turtlesim</run_depend></package>
src/pubvel/CMakeList.txt
cmake_minimum_required(VERSION 2.8.3)project(pubvel)find_package(catkin REQUIRED roscpp geometry_msgs)catkin_package( #INCLUDE_DIRS include #LIBRARIES agitr_pubVel #CATKIN_DEPENDS other_catkin_pkg #DEPENDS system_lib)add_executable(pubvel pubvel.cpp)target_link_libraries(pubvel ${catkin_LIBRARIES})
catkin_make
source devel/setup.bash
rosrun turtlesim turtlesim_node
rosrun pubvel pubvel
rostopic echo /turtle1/pose
rostopic echo /turtle1/cmd_vel
回掉函数与话题订阅
src/subturtlesimpose/subturtlesimpose.cpp
//This is a first Velocity topic publish program#include <ros/ros.h>#include <turtlesim/Pose.h>#include <iomanip>//callback funcitonvoid poseMessageReceived(const turtlesim::Pose& msg){ ROS_INFO_STREAM(std::setprecision(2)<<std::fixed<<"positon=("<<msg.x<<","<<msg.y<<")"<<"*direcion="<<msg.theta);}int main(int argc,char** argv){ ros::init(argc,argv,"subscribe_to_turtlesim_pose"); ros::NodeHandle nh; ros::Subscriber sub=nh.subscribe("turtle1/pose",1000,&poseMessageReceived); ros::spin();}
src/subturtlesimpose/package.xml
<?xml version="1.0"?><package> <name>subturtlesimpose</name> <version>0.0.0</version> <description>LEEMAN_CAFFEE</description> <maintainer email="mli@leemanchina.com">HOPPS</maintainer> <license>BSD</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>geometry_msgs</build_depend> <build_depend>turtlesim</build_depend> <run_depend>roscpp</run_depend> <run_depend>geometry_msgs</run_depend> <run_depend>turtlesim</run_depend></package>
src/subturtlesimpose/CMakeList.txt
cmake_minimum_required(VERSION 2.8.3)project(subturtlesimpose)find_package(catkin REQUIRED roscpp geometry_msgs)catkin_package( #INCLUDE_DIRS include #LIBRARIES agitr_pubVel #CATKIN_DEPENDS other_catkin_pkg #DEPENDS system_lib)add_executable(subturtlesimpose subturtlesimpose.cpp)target_link_libraries(subturtlesimpose ${catkin_LIBRARIES})
rosrun turtlesim turtlesim_node
rosrun pubvel pubvel
rosrun subturtlesimpose subturtlesimpose
阅读全文
0 0
- ROS程序发布随机速到turltlesim
- 将视频文件发布到ROS的topic上
- Python和C++程序发布和订阅ROS话题
- j2me程序发布到手机
- j2me程序发布到手机
- j2me程序发布到手机
- j2me程序发布到手机
- j2me程序发布到手机
- 发布程序到Android Market
- IOS 发布程序到AppStore
- IOS 发布程序到AppStore
- qtcreator 调试ros程序,附加到进程无法使用解决方法
- ROS发布&订阅字符串
- ROS编程示例---随机移动
- j2me程序发布到手机(Eclipse)
- RCP程序发布到不同的平台
- 如何发布程序到手机上?
- 将Silverlight程序发布到服务器上
- Docker之Docker镜像管理
- BS与CS的恩恩怨怨
- es6 笔记
- 关于在web页面乱码
- hibernate的list映射和map映射
- ROS程序发布随机速到turltlesim
- CodeForces 679A Bear and Prime 100【交互题+数论】
- 每天积累一点(二)--mysql事物级别
- POJ 3076 Sudoku 精确覆盖问题DLX
- mysql (三)存储引擎
- xhconn.js中需要注意的问题
- 2017 HDU 6105 多校联合赛 Gameia
- Java自定义类加载器与双亲委派模型
- 疯狂数队列 编程 python