How to publish array of velocities?
Hello guys, so I am very new to ROS and python. Now I understand the following: to publish on a topic, for example Twist() you write something like this and you publish one value for a couple of seconds (4 seconds in this case):
1 #!/usr/bin/env python
2 import rospy
3 from geometry_msgs.msg import Twist
4
5 def move():
6 # Starts a new node
7 rospy.init_node('robot_cleaner', anonymous=True)
8 velocity_publisher = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
9 vel_msg = Twist()
10
11 vel_msg.linear.x = 0.5
12 vel_msg.linear.y = 0
13 vel_msg.linear.z = 0
14 vel_msg.angular.x = 0
15 vel_msg.angular.y = 0
16 vel_msg.angular.z = 0
17
18 now = rospy.Time.now()
19
20 while rospy.Time.now() < now + rospy.Duration.from_sec(4):
21 pub.publish(vel_msg)
22
23 move()
But so instead of publishing one velocity for a couple of seconds I want now to publish like an array of velocities. For example vel_msg.linear.x = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]. So every timestep there will be another velocity published until the last value is reached.
How can you do this? And maybe another question: how do you know the timestep that ROS is using between the values of the array? Thanks in advance!