如果想要在rviz中看到真是机器人是如何运动的,那么需要读取机器人状态的实时反馈信息。
思路如下:1.读取串口中输入的数据并且接收它
2.把数据广播出去
3.机器人控制程序订阅话题,接收数据
4.使用数据改变机器人的状态
接下来的代码就是读取串口中输入的数据,在试验的时候,可以用两个可以发送和接受数据的U盘,一个发一个收。
这里要主义一下,有一个ros的serial的串口包.
在这里分享其他博友的一篇文章,详细介绍了rosserial.
这里写链接内容
include “ros/ros.h”
include “serial/serial.h” //ROS已经内置了的串口包
include “std_msgs/String.h”
include “std_msgs/Empty.h”
include
include “string”
include
include
include “stdio.h”
using namespace std;
serial::Serial ser; //声明串口对象
//回调函