当前位置:   article > 正文

ROS下订阅/cmd_vel节点_cmdvelhaiti

cmdvelhaiti

在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/

  1. #include<ros/ros.h>
  2. #include<tf/transform_broadcaster.h>
  3. #include<nav_msgs/Odometry.h>
  4. #include<geometry_msgs/Twist.h>
  5. #include<iostream>
  6. void callback(const geometry_msgs::Twist& cmd_vel)
  7. {
  8. ROS_INFO("Received a /cmd_vel message!");
  9. ROS_INFO("Linear Components:[%f,%f,%f]",cmd_vel.linear.x,cmd_vel.linear.y,cmd_vel.linear.z);
  10. ROS_INFO("Angular Components:[%f,%f,%f]",cmd_vel.angular.x,cmd_vel.angular.y,cmd_vel.angular.z);
  11. // Do velocity processing here:
  12. // Use the kinematics of your robot to map linear and angular velocities into motor commands
  13. // v_l = ...
  14. // v_r = ...
  15. // Then set your wheel speeds (using wheel_left and wheel_right as examples)
  16. // wheel_left.set_speed(v_l)
  17. // wheel_right.set_speed(v_r)
  18. }
  19. int main(int argc, char** argv)
  20. {
  21. ros::init(argc, argv, "cmd_vel_listener");
  22. ros::NodeHandle n;
  23. //ros::Subscriber sub = n.subscribe("cmd_vel", 1000, callback);
  24. ros::Subscriber sub = n.subscribe("/turtle1/cmd_vel", 1000, callback);//用/turtle1/cmd_vel做测试哈
  25. ros::spin();
  26. /*
  27. //http://answers.ros.org/question/129506/subscriber-not-seeing-cmd_vel-messages/
  28. ros::Rate loop_rate(10);
  29. while( n.ok() )
  30. {
  31. ros::spin();
  32. }
  33. */
  34. return 1;
  35. }

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

节点结果:




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/674722
推荐阅读
相关标签
  

闽ICP备14008679号