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

is int8[] a valid data type in c++?

asked 2013-07-14 19:07:11 -0600

Bholms gravatar image

updated 2013-11-18 19:07:17 -0600

tfoote gravatar image

So I am trying to publish an array of int8 type. The following lines are used (not together).

ArbitraryLibrary::int8[] msg;
template<class int8[]>
ros::Publisher chatter_pub = n.advertise<std_msgs::int8[]>("Chatter", 1000);

I can't really test it right now, but will this allow me to publish an array of int8 type messages?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2013-07-15 00:30:54 -0600

Your code example won't work, because topics always have a message type (not an array of primitives). So there are two options:

  1. Use the std_msgs/Int8MultiArray; this is the message definition:

    # Please look at the MultiArrayLayout message definition for
    # documentation on all multiarrays.
    
    MultiArrayLayout  layout        # specification of data layout
    int8[]            data          # array of data
    

    Then instantiate your publisher like this:

    ros::Publisher chatter_pub = n.advertise<std_msgs::Int8MultiArray>("Chatter", 1000);
    
  2. Alternatively, define your own message type (my_pkg/Int8Array):

    int8[] data
    

    Then instantiate your publisher like this:

    ros::Publisher chatter_pub = n.advertise<my_pkg::Int8Array>("Chatter", 1000);
    

It's probably better to define your own message type, because message types should always have a semantic meaning. If the topic type is "array of integers", this doesn't tell the subscriber how the data should be interpreted (range measurements in meters? encoder readings? temperatures?). Depends on the circumstances, though.

edit flag offensive delete link more

Comments

hmm... In regards to your last comment, I would have thought the exact opposite. I like the message types simple and the topic names semantic. Might be a good topic for a best practice question...

thebyohazard gravatar image thebyohazard  ( 2013-07-15 04:12:34 -0600 )edit

Oh, there have been plenty of best practice discussions around that (e.g., this ros-users thread ).

Martin Günther gravatar image Martin Günther  ( 2013-07-15 05:43:21 -0600 )edit

Of course, the design decision depends on the specific case. If you want to represent a 6D pose, float[7] would be too generic, geometry_msgs/PoseStamped is just right, and my_pkg/PathPlanningTargetPose would be too specific.

Martin Günther gravatar image Martin Günther  ( 2013-07-15 05:46:31 -0600 )edit
1

answered 2013-07-14 21:39:26 -0600

tfoote gravatar image

int8 is a valid primative

It is not a message defined in std_msgs (You'll find Int8 is though. )

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-14 19:07:11 -0600

Seen: 3,352 times

Last updated: Jul 15 '13