ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
One way would be to create two custom messages, call them something like my_msgs/Pair.msg
and my_msgs/VectorPair.msg
. The contents would be:
my_msgs/Pair.msg
int a
int b
my_msgs/VectorPair.msg
my_msgs/Pair[] data
In your publishing node you would do:
#include <my_msgs/VectorPair.h>
vector_pub = nh.advertise<my_msgs::VectorPair>("vector", 100);
my_msgs::VectorPair vector_node_position;
vector_node_position.data[0].a = 1;
vector_node_position.data[0].b = 2;
vector_pub.publish(vector_node_position);
2 | No.2 Revision |
One way would be to create two custom messages, call them something like my_msgs/Pair.msg
and my_msgs/VectorPair.msg
. The contents would be:
my_msgs/Pair.msg
int a
int b
my_msgs/VectorPair.msg
my_msgs/Pair[] data
In your publishing node you would do:
#include <my_msgs/VectorPair.h>
vector_pub = nh.advertise<my_msgs::VectorPair>("vector", 100);
my_msgs Pair pair;
my_msgs::VectorPair vector_node_position;
vector_node_position.data[0].a pair.a = 1;
vector_node_position.data[0].b pair.b = 2;
vector_node_position.data.push_back(pair);
vector_pub.publish(vector_node_position);
Note that creating/populating the pair message and then pushing it into the vector message could happen inside a loop.