the construct [ROS Q&A] 205 How to publish velocity array

[ROS Q&A] 205 How to publish velocity array

https://www.youtube.com/watch?v=rqA7h37k9gw&list=PLK0b4e05LnzbrLrLhOhSvLdaQZOsJl59N&index=2

1. 安装turtlebot3

clone3个github

https://github.com/ROBOTIS-GIT/turtlebot3.git
https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git

在这里插入图片描述

2.学习python publisher和subscriber

在这里插入图片描述

#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist

def publisher():
	pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
	rospy.init_node('cmd_vel_array_publisher')
	rate = rospy.Rate(1) # 1 Hz
	cmd_vel_array = [0.01,0.02,0.03,0.04]
	vel = Twist()
	while not rospy.shutdown():
		for i in range(len(cmd_vel_array)):
			vel.linear.x = cmd_vel_array[i]
			print("publishing velocity" + str(cmd_vel_arrsy[int(i)]))
			pub.publish()
			i = i+1
			rate.sleep()
if __name__ == '__main__':
	publisher()
# python代码publish_vel_array.py放在catkin_ws/src/
cd catkin_ws/src/
chmod +x publish_vel_array.py
cd ..
source devel/setup.bash
cd src
python publish_vel_array.py


版权声明:本文为weixin_44900096原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。