Gazebo | Ignition | Community
Ask Your Question

Basic info about topics and their usage with python.

asked 2015-01-06 05:51:18 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hello! I installed on my pc pygazebo that provides python bindings for Gazebo. Pygazebo communicates with Gazebo through sockets using the Google Protobufs. I have some problems in understanding how a message must be structured, if I want to send it to Gazebo topic. For example I can apply a force on a revolute joint using the JointCmd topic, but when I try to use any other topic ( such as, for example , JointAnimation ) , I get a lot of errors like this :

Traceback (most recent call last):
  File "", line 24, in <module>
  File "/usr/local/lib/python2.7/dist-packages/trollius-1.0.2-py2.7.egg/trollius/", line 281, in run_until_complete
    return future.result()
  File "/usr/local/lib/python2.7/dist-packages/trollius-1.0.2-py2.7.egg/trollius/", line 277, in result
    raise self._exception
AttributeError: Assignment not allowed to repeated field "time" in protocol message object.

So, I'm a beginner and I need some basic info. I understood that every topic has a particular function and it need a particular message to work. So where can I learn how to use the topics through the sockets? For example where can I understeand how works the JointAnimation topic? In the JointAnimation topic what is the 'magic' attribute time? Long story short.... Where can I find the basic info to use the socket with pygazebo?

Every little info will be very helpful! Thanks in advance!

P.S.: This is the script that returns the error above:

import trollius
from trollius import From

import pygazebo
import pygazebo.msg.joint_animation_pb2

def publish_loop():
   manager = yield From(pygazebo.connect())
   publisher = yield From(manager.advertise('/gazebo/default/3gl_robot/joint_animation','gazebo.msgs.JointAnimation'))
   message = pygazebo.msg.joint_animation_pb2.JointAnimation()
   message.model_name = '3gl_robot::collo_hinge'


   while True:

       yield From(publisher.publish(message))
       yield From(trollius.sleep(0.50))

loop = trollius.get_event_loop()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-01-06 07:36:00 -0500

When working with python objects, it can be useful to use them from an interactive shell, this lets you tell what operations are possible. Here, you are trying to perform an operation on the JointAnimation object's time member which isn't possible.

If you open up an interactive python shell and do:

import pygazebo
import pygazebo.msg.joint_animation_pb2
ja = pygazebo.msg.joint_animation_pb2.JointAnimation()

You can see what things you can do with the time member. In particular, it is a protobuf repeated field, which means you can call "add(1)" on it to add a single time member. Thus the following code would work:

ja.time.add(1)  # note, ja.time = 1 won't work

A good rule of thumb is if you are using a new message in pygazebo, you should find some sample C++ code which uses that and mimic it. Another good option is to look in the gazebo source code to figure out how the message is being used.

edit flag offensive delete link more

Question Tools


Asked: 2015-01-06 05:51:18 -0500

Seen: 1,203 times

Last updated: Jan 06 '15