File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
catkin_wp/src/learning_topic/script Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ########################################################################
5
+ #### Copyright 2020 GuYueHome (www.guyuehome.com). ###
6
+ ########################################################################
7
+
8
+ # 该例程将发布turtle1/cmd_vel话题,消息类型geometry_msgs::Twist
9
+
10
+ import rospy
11
+ from geometry_msgs .msg import Twist
12
+
13
+ def velocity_publisher ():
14
+ # ROS节点初始化
15
+ rospy .init_node ('velocity_publisher' , anonymous = True )
16
+
17
+ # 创建一个Publisher,发布名为/turtle1/cmd_vel的topic,消息类型为geometry_msgs::Twist,队列长度10
18
+ turtle_vel_pub = rospy .Publisher ('/turtle1/cmd_vel' , Twist , queue_size = 10 )
19
+
20
+ #设置循环的频率
21
+ rate = rospy .Rate (10 )
22
+
23
+ while not rospy .is_shutdown ():
24
+ # 初始化geometry_msgs::Twist类型的消息
25
+ vel_msg = Twist ()
26
+ vel_msg .linear .x = 0.5
27
+ vel_msg .angular .z = 0.2
28
+
29
+ # 发布消息
30
+ turtle_vel_pub .publish (vel_msg )
31
+ rospy .loginfo ("Publsh turtle velocity command[%0.2f m/s, %0.2f rad/s]" ,
32
+ vel_msg .linear .x , vel_msg .angular .z )
33
+
34
+ # 按照循环频率延时
35
+ rate .sleep ()
36
+
37
+ if __name__ == '__main__' :
38
+ try :
39
+ velocity_publisher ()
40
+ except rospy .ROSInterruptException :
41
+ pass
You can’t perform that action at this time.
0 commit comments