Home | Tutorials | Wiki | Issues
Ask Your Question
1

publish a topic

asked 2012-09-26 16:31:31 -0500

Zara gravatar image

updated 2012-09-28 09:51:09 -0500

nkoenig gravatar image

Hello all,

I am don't how to write a program to interface with Gazebo (not a plugin) to send some velocity commands in shape of a message(topic) and receive it in a model plugin. Can you point me to an example?

I have already read this page http://gazebosim.org/wiki/Tutorials/beginner/topics , but it is not enough for me. If the message is not built-in how can I publish it using a separate program?

Thanks for your help,

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-09-28 10:02:41 -0500

nkoenig gravatar image

It's suggested that an external program link against the Gazebo libraries, specifically the transport library, and send messages using the interface provided by Gazebo Nodes.

You can send messages to Gazebo using your own transport mechanism. Construct your message with:

  1. An 8byte header that is the size of the message
  2. The message data (which must be a serialized protobuf message that Gazebo understands).

The following is a simple example in Python. Here we are assuming the python script is waiting for incoming requests from Gazebo, and then responds with a new message.

#!/usr/bin/env python

import socket
import struct
from sys import *
from xml.dom import minidom

import request_pb2

TCP_IP = '127.0.0.1'
TCP_PORT = 50199
BUFFER_SIZE = 1024

models = {}

#################################################
# Read the main manifest file
def read_manifest():
  xmldoc = minidom.parse('manifest.xml')
  model_list = xmldoc.getElementsByTagName("model")

  for model in model_list:
    model_name = model.getElementsByTagName("name")[0].childNodes[0].data
    model_path = model.getElementsByTagName("path")[0].childNodes[0].data
    models[model_name] = model_path

read_manifest()

print 'here'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)
print 'here2'

conn, addr = s.accept()
print 'Connection address:', addr
while 1:
  request = request_pb2.Request()
  data = conn.recv(BUFFER_SIZE)
  if not data:
    break

  request.ParseFromString(data)

  print "Request: ", request.request

  response = request_pb2.Response()
  response.id = request.id
  response.request = request.request

  if request.request == "models":
    response.response = "success"

    model_list_msg = request_pb2.ModelList()
    response.type = model_list_msg.DESCRIPTOR.full_name
    for key in models:
      model_list_msg.model.append(key)
    response.data = model_list_msg.SerializeToString()

  print "Response Size:", len(response.SerializeToString())
  hex_size = hex(len(response.SerializeToString()))
  conn.send(hex_size.rjust(8))
  conn.send(response.SerializeToString())  # echo
conn.close()
edit flag offensive delete link more
0

answered 2012-09-28 11:43:00 -0500

Zara gravatar image

Thanks for you answer. Can You also point me to the list of functions that interface the msg class? For instance, in JointTestPlugin.cc, some functions are being called _msg.position() and _msg.force(). Where are these functions defined in API?

Also, there is a line in the load function:

this->velSub = this->node->Subscribe(std::string("~/") + this->model->GetName() + "/joint_test_cmd",
  &JointTestPlugin::OnJointCmdMsg, this);

I understand that the topic ~/modelname/jointtest_cmd is being subscribed but I don't know where this topic is advertised (perhaps in a separate program?). Where is that program in gazebo folder?

Thanks for you help and sorry for my very long question.

edit flag offensive delete link more

Comments

We are currently trying to figure out the best way to generate documentation for google protobufs. For now, take a look at the protobuf message definitions under: gazebo/msgs/*.proto

You can get topic information using the gztopic command (gztopic -h)

nkoenig gravatar imagenkoenig ( 2012-10-02 10:58:27 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2012-09-26 16:31:31 -0500

Seen: 2,135 times

Last updated: Sep 28 '12