ROS操作,Ros入门
古月居活性氧簇(活性氧物种的缩写)入门21讲第十一讲订阅者订户的编程实现C
Pose _ subscriber。CPP #包括ro/ro。h #包括“海龟模拟/姿势”。h void Pose回调(const Turtle sim:Pose:const ptr msg){ ROS _ INFO( Turtle Pose:x:% 0.6f,y:%0.6f ,msg-x,msg-y);}int main(int argc,char痴情的书包argv){ ros:init(argc,argv, pose _ subscriber );ROS:节点句柄n;ROS:Subscriber pose _ sub=n . subscribe(/turtle 1/pose ,10,pose回调);ROS:spin();返回0;} vim src/learning _ topic/cmakelists。文本文件(textfile)在CMakelists.txt中添加
add _ executive(pose _ subscriber src/pose _ subscriber。CPP)target _ link _ LIBRARIES(pose _ subscriber $ {柔荑_LIBRARIES}) jddxg
CD ~/柳絮_ ws/source devel/setup。尝试柳絮_制作欢呼的黄豆
roscorerosrun turtle sim turtle sim _ noderorun learning _ topic pose _ subscriber Python #!/usr/bin/env python从Turtle sim导入rospy。消息导入姿态定义姿态回调(消息):rospy。日志信息(乌龟姿势:X:% 0.6f,y:%0.6f ,msg.x,msg。y)def pose _ subscriber():rospy。init _ node( pose _ subscriber ,anonymous=True) rospy .订户(/turtle1/pose ,pose,pose回调)rospy。spin()if _ _ name _ _= _ _ main _ _ :Pose _ subscriber()欢呼的黄豆
roscorerosrun turtle sim turtle sim _ no derosrun learning _ topic pose _ subscriber。巴拉圭
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。