Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You need to allow some time for poses to be received from Gazebo before you try to use them. Although you set up the subscriber for /gazebo/model_states in the MovetoGoals object's constructor, you do not give ROS any time to receive anything on the topic before you start calling move2goal which internally via the euclidean_distance function tries to use the value that will be set by update_pose. This means that update_pose has not yet been called when euclidean_distance is called so it tries to access a pose in the empty ModelStates object's array.

To solve this, you need to give some time to ROS to receive the data you want to use before you start trying to send movement commands based on received data. Add a function that allows ROS to receive a few methods (e.g. creating a rate object of 10 Hz and doing a rate.sleep() on it) until you see that the size of the ModelStates object has data.

Also make sure that the second pose in the list is the one you want. In Python, list indices are zero-based.