RosSerial:Windows与ROS通信(二):向Windows传输数据

运行环境:

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 <string>
#include <stdio.h>
#include "ros.h"
#include <geometry_msgs/Twist.h>
#include <windows.h>
#include <tchar.h> 

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,需要添加很多库文件,我还没有尝试成功,一直在报错,如果有人成功了,不妨写个教程。

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值