Gazebo | Ignition | Community
Ask Your Question
0

Using Pygazebo with Gazebo to receive a 2d Vector: AssertionError

asked 2017-03-08 08:08:51 -0500

lnair gravatar image

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
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-03-09 14:19:31 -0500

Carlos Agüero gravatar image

I'm not familiar with pygazebo but I'd like to give you a workaround if you cannot solve it and can use Gazebo 8. We integrated a plotting utility that let you visualize in real time your data within Gazebo.

edit flag offensive delete link more

Comments

1

Thank you. Unfortunately I couldn't get it to work with Pygazebo so I used the plotting utility in Gazebo 8 like you suggested and it worked well! I'm glad I don't have to worry about this anymore.

lnair gravatar imagelnair ( 2017-03-10 18:59:27 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-03-07 20:07:03 -0500

Seen: 351 times

Last updated: Mar 09 '17