VMware: Ubuntu 20.04
ROS:noetic
windows 10
Visual Studio 2019
操作完全一致。参考前一篇文章https://blog.csdn.net/weixin_42264818/article/details/119679646?spm=1001.2014.3001.5501
//#include "stdafx.h"
#include
#include
#include "ros.h"
#include
#include
#include
using std::string;
void cmd_vel_angular_callback(const geometry_msgs::Twist& cmd_vel)
{
printf("%f, %f, %f, %f, %f, %f\n",
cmd_vel.linear.x, cmd_vel.linear.y, cmd_vel.linear.z,
cmd_vel.angular.x, cmd_vel.angular.y, cmd_vel.angular.z);
//twist_msg = cmd_vel;
}
int _tmain(int argc, _TCHAR* argv[])
{
ros::NodeHandle nh;
char* ros_master = "192.168.3.241";
printf("正在连接 %s\n", ros_master);
nh.initNode(ros_master);
ros::Subscriber < geometry_msgs::Twist >
poseSub("/turtle1/cmd_vel", &cmd_vel_angular_callback);
nh.subscribe(poseSub);
printf("Waiting to receive messages\n");
while (1)
{
nh.spinOnce();
Sleep(100);
}
printf("All done!\n");
return 0;
}
在Ubuntu命令行分别输入以下代码:
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
rosrun rosserial_server socket_node /turtle1/cmd_vel
在Windows Visual Studio 2019点击绿色箭头运行
另外,如果订阅turtlesim::pose,需要添加很多库文件,我还没有尝试成功,一直在报错,如果有人成功了,不妨写个教程。