Your code example won't work, because topics always have a message type (not an array of primitives). So there are two options:
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);
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.