ROS下订阅/cmd_vel节点

在ROS下测试订阅/cmd_vel节点,实际测试时采用/turtle1/cmd_vel节点

参考:

http://blog.csdn.net/heyijia0327/article/details/41823809 

http://answers.ros.org/question/129506/subscriber-not-seeing-cmd_vel-messages/

#include<ros/ros.h>
#include<tf/transform_broadcaster.h>
#include<nav_msgs/Odometry.h>
#include<geometry_msgs/Twist.h>
#include<iostream>

void callback(const geometry_msgs::Twist& cmd_vel)
{
	ROS_INFO("Received a /cmd_vel message!");
	ROS_INFO("Linear Components:[%f,%f,%f]",cmd_vel.linear.x,cmd_vel.linear.y,cmd_vel.linear.z);
	ROS_INFO("Angular Components:[%f,%f,%f]",cmd_vel.angular.x,cmd_vel.angular.y,cmd_vel.angular.z);
	// Do velocity processing here:  
    // Use the kinematics of your robot to map linear and angular velocities into motor commands  
//    v_l = ...  
//    v_r = ...  
  
    // Then set your wheel speeds (using wheel_left and wheel_right as examples)  
//    wheel_left.set_speed(v_l)  
//    wheel_right.set_speed(v_r) 
}

int main(int argc, char** argv)
{
	ros::init(argc, argv, "cmd_vel_listener");
	ros::NodeHandle n;
	//ros::Subscriber sub = n.subscribe("cmd_vel", 1000, callback);
	ros::Subscriber sub = n.subscribe("/turtle1/cmd_vel", 1000, callback);//用/turtle1/cmd_vel做测试哈
	ros::spin();

/*
//http://answers.ros.org/question/129506/subscriber-not-seeing-cmd_vel-messages/
	ros::Rate loop_rate(10);
	while( n.ok() ) 
	{
   		 ros::spin();
	}
*/
	return 1;
}

turtle使用:http://wiki.ros.org/cn/ROS/Tutorials/UnderstandingTopics

节点结果:




评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值