Hi The Construct Team,
I am on Chapter 4 of Basic Kinematics of Mobile Robots. The chapter with omniwheels / mecanum wheels for robot with strafing ability.
I am trying out the very first example basic_motions.py
and the robot does not move in the Gazebo simulation.
Here is the code (copied exactly as-is from the tutorial):
import rospy
import math
import numpy as np
from std_msgs.msg import Float32MultiArray
from utilities import reset_world
rospy.init_node('holonomic_controller', anonymous=True)
pub = rospy.Publisher('/wheel_speed', Float32MultiArray, queue_size=10)
forward = [1.0, 1.0, 1.0, 1.0]
msg = Float32MultiArray(data=forward)
pub.publish(msg)
rospy.sleep(5.0)
stop = [0.0, 0.0, 0.0, 0.0]
msg = Float32MultiArray(data=stop)
pub.publish(msg)
# End of Code
Please help!
Thanks,
Girish
Hello @girishkumar.kannan ,
The problem is that the first message (forward) is not published because the Publisher is not initialized yet. Add a sleep right after creating the Publisher:
rospy.init_node('holonomic_controller', anonymous=True)
pub = rospy.Publisher('wheel_speed', Float32MultiArray, queue_size=10)
rospy.sleep(1.0)
This should fix the problem.
Hi @albertoezquerro ,
That worked ! Also when I checked with rostopic echo /wheel_speed
, I noticed that the first message never got published. So I was assuming that the message structure was wrong since we are not filling out the layout, dim[…] parts of the Float32MultiArray message.
Anyways, problem is fixed.
@albertoezquerro , Please update the course notebook with this change!
Thanks,
Girish
In addition to what @albertoezquerro, you can check if the publisher is ready before sending data to it, instead of sleeping some random seconds (which does not guarantee that the topic would be ready anyways).
It’s a good idea to include this “publisher ready?” logic in your robotic applications as this will make it more robust.
I will update the ROS Basics notebook with this idea sometime.
1 Like