Skip to content

Commit 3a0211c

Browse files
committed
python
1 parent 33ed233 commit 3a0211c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
########################################################################
5+
#### Copyright 2020 GuYueHome (www.guyuehome.com). ###
6+
########################################################################
7+
8+
# 该例程将订阅/turtle1/pose话题,消息类型turtlesim::Pose
9+
10+
import rospy
11+
from turtlesim.msg import Pose
12+
13+
def poseCallback(msg):
14+
rospy.loginfo("Turtle pose: x:%0.6f, y:%0.6f", msg.x, msg.y)
15+
16+
def pose_subscriber():
17+
# ROS节点初始化
18+
rospy.init_node('pose_subscriber', anonymous=True)
19+
20+
# 创建一个Subscriber,订阅名为/turtle1/pose的topic,注册回调函数poseCallback
21+
rospy.Subscriber("/turtle1/pose", Pose, poseCallback)
22+
23+
# 循环等待回调函数
24+
rospy.spin()
25+
26+
if __name__ == '__main__':
27+
pose_subscriber()

0 commit comments

Comments
 (0)