ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Publisher-related design problem

asked 2014-08-21 14:16:21 -0600

alfa_80 gravatar image

updated 2014-08-21 14:16:43 -0600

Let say I have some values set of Box attributes in a launch file as below:

<id="width" value="1"/>
<id="length" value="3"/>
<id="height" value="3"/>

<id="width2" value="3"/>
<id="length2" value="3"/>
<id="height2" value="4"/>

<id="width3" value="2"/>
<id="length3" value="3"/>
<id="height3" value="3"/>

These value I will read in a method and publish those. But the problem here how the publisher should look like as I don't want to limit the number of box only to 3, it could be set up to n, where n is a real number. Those all value will later be subscribed by another node that will construct a class like below:

Box
{ 
    ...
    ...
    double width;
    double length;
    double height;
    ...
    ...
}

How do I achieve this? Thanks in advance.

edit retag flag offensive close merge delete

Comments

1

The ROS parameter server supports arrays and maps. You should probably be using those.

ahendrix gravatar image ahendrix  ( 2014-08-21 16:28:47 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-08-22 04:53:22 -0600

Chrissi gravatar image

I agree with @ahendrix you should probably use the parameter server. You can create a yaml file like this:

my_node:
  boxes:
    box1:
      width: 1
      height: 1
      length: 2
    box2:
      width: 4
   ...

You can then include this in your launch file:

<launch>
  <arg name="box_file" default="$(find my_package)/config/boxes.yaml" />
  <rosparam command="load" file="$(arg box_file)"/>

  <node pkg="my_package" type="box_node" name="box_node"/>
</launch>

Afterwards in your box node you can query the parameter namespace boxes and get a dictionary of all the defined boxes (python) or an xmlrpc struct (C++) which you can then parse for the information you want. See this answer on how to use the xmlrpc struct. The usage of python dictionaries should be straight forward.

If you use the parameter server there is also no need to publish these box values you can just query the server in all the nodes you might need the boxes in.

edit flag offensive delete link more

Comments

In my case, I need to publish those box values. In the box node, is there a way to do that as the number of boxes are unknown before hand?

alfa_80 gravatar image alfa_80  ( 2014-08-22 08:31:54 -0600 )edit

In the yaml file you can define as many boxes as you like. When you querry the boxes parameter namspace you get a python dictonary or C++ xmlrpc struct of all the boxes inside. You can just iterate over all the boxes without knowing how many there are in advance. Please have a look at this question which is exactly what you want to do but with filters.

Chrissi gravatar image Chrissi  ( 2014-08-22 08:36:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-21 14:16:21 -0600

Seen: 190 times

Last updated: Aug 22 '14