Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using Pygazebo with Gazebo

I have a 2d Vector from my simulation in Gazebo that I'd like to plot in realtime using Python. I'm trying to use Pygazebo to receive this vector. I have Gazebo v7.4 installed (no ROS) and I'm using Python 2.7.12. I've already looked at the Pygazebo documentation, numerous other questions/codes but I'm not able to achieve this. At this point, this is what I have at the pygazebo end:

import pygazebo

def callback(data):
     message = pygazebo.msg.vector2d_pb2.Vector2d(data)
     print('Received message:', message.x)

manager = pygazebo.Manager(('localhost', 11345))
manager.subscribe('~/vector2d','gazebo.msgs.Vector2d',callback)
manager.start()

On the gazebo end I have (just shown the relevant part of the code):

public: transport::PublisherPtr pub;
//Some code ...
public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
{ 
  transport::NodePtr node(new transport::Node());
  node->Init();
  pub = node->Advertise<msgs::Vector2d>("~/vector2d");
  pub->WaitForConnection();
}

public: void OnUpdate(const common::UpdateInfo &_info)
{ 
  ignition::math::Vector2d vect(5,5);
  msgs::Vector2d _msg;
  msgs::Set(&_msg, vect);
  pub->Publish(_msg);
}

Am I on the right track with this? The gazebo code doesn't throw any errors but I seem to be getting the following error when I run the Python code:

        Traceback (most recent call last):
  File "python_plot.py", line 8, in <module>
    manager.subscribe('~/vector2d','gazebo.msgs.Vector2d',callback)
  File "/usr/local/lib/python2.7/dist-packages/pygazebo-3.0.0_2014.1-py2.7.egg/pygazebo/pygazebo.py", line 512, in subscribe
    to_send.host = self._server.local_host
  File "/usr/local/lib/python2.7/dist-packages/pygazebo-3.0.0_2014.1-py2.7.egg/pygazebo/pygazebo.py", line 425, in local_host
    assert self._local_ready.is_set()
AssertionError