博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ROS下实现timed_out_and_back功能
阅读量:4031 次
发布时间:2019-05-24

本文共 1556 字,大约阅读时间需要 5 分钟。

借鉴《ROS by example》里边的timed_out_and_back.py实例,在CPP下复现了一下:(基本流程参考 过程)

中途参考了:

http://stackoverflow.com/questions/13213917/turtlebot-ros-moving-using-twist

http://www.clearpathrobotics.com/blog/ros-101-creating-node/

#include "ros/ros.h"//#include "std_msgs/String.h"//geometry_msgs#include "geometry_msgs/Twist.h"//包含elocity space消息#include "math.h"#include 
#include
int main(int argc, char **argv){ ros::init(argc,argv,"out_and_back");//指定节点“out_and_back” ros::NodeHandle n;//创造一个节点句柄 ros::Publisher cmd_vel_pub=n.advertise
("/cmd_vel",1000);//将在/cmd_vel话题上发布一个geometry_msgs::Twist消息 int rate=50;//定义更新频率 ros::Rate loop_rate(rate);//更新频率50Hz,它会追踪记录自上一次调用Rate::sleep()后时间的流逝,并休眠直到一个频率周期的时间 //初始化操作 float linear_speed=0.2;//向前的线速度0.2m/s float goal_distance=1.0;//行进记录1.0m float linear_duration=goal_distance/linear_speed;//行进时间 float angular_speed=1.0;//角度素1.0rad/s float goal_angle=M_PIl;//more /usr/include/math.h | grep pi可以查看pi的定义 float angular_duration=goal_angle/angular_speed;//旋转时间 geometry_msgs::Twist move_cmd;//定义消息对象 move_cmd.linear.x=move_cmd.linear.y=move_cmd.linear.z=0; move_cmd.angular.x=move_cmd.angular.y=move_cmd.angular.z=0; int count=0;//记录循环次数 while(ros::ok())//等待键盘ctrl+C操作则停止 { std::cout<<"Hello world:"<<"The "<
<<"th circle!"<<"\n"; //向前运动 move_cmd.linear.x=linear_speed; int ticks=int(linear_duration*rate); for(int i=0;i
最终结果:

Hello world:The 0th circle!

Hello world:The 1th circle!
Hello world:The 2th circle!
Hello world:The 3th circle!
Hello world:The 4th circle!

你可能感兴趣的文章
自然计算
查看>>
自然计算时间复杂度杂谈
查看>>
当前主要目标和工作
查看>>
系统菜单
查看>>
路漫漫其修远兮,吾将上下而求索(2)
查看>>
versions mac yosemite 下崩溃的修复
查看>>
github push 出现connection refused 的处理办法
查看>>
Linux配置sendmail实现PHP发送邮件
查看>>
c++ 特性回顾
查看>>
网站注册的时候,烦人的生日年份选择的改进想法
查看>>
游戏开发两年记 之 工程和理论需双剑合璧
查看>>
Nachos中switch汇编源码分析
查看>>
游戏开发两年之产品逻辑鸡肋么?
查看>>
secureCRT和Xshell登录Ubuntu
查看>>
secureCRT和Xshell登录ubuntu
查看>>
Apache下c语言的cgi如何获得Get,Post参数
查看>>
protobuf的使用初探
查看>>
ngx_http分析
查看>>
搭建一个php学习框架mycake
查看>>
MVC模式概念
查看>>