How to make a geometry_msgs/PoseArray?

asked 2019-12-01 23:09:18 -0600

Parth2851 gravatar image

updated 2019-12-02 01:35:13 -0600

mgruhler gravatar image

I understand what a PoseArray is but I'm having a tough time trying to implement in roscpp.

There aren't many examples on how to code and use it and as a beginner it's really tough for me to figure it out using the documentation.

If anyone can guide me to an example or even write a small example, that would be great.

edit retag flag offensive close merge delete

Comments

2

So, what is your question exactly? Do you have a problem with the contents or the coding?

geometry_msgs::PoseArray  posearray;
posearray.header.stamp = ros::Time::now(); // timestamp of creation of the msg
posearray.header.frame_id = "map" // frame id in which the array is published
geometry_msgs::Pose p; // one pose to put in the array
// fill p appropriately
p.header.stamp = ...
p.pose.position.x = ...
p.pose.orientation.x = ...
// push in array (in C++ a vector, in python a list)
posearray.poses.push_back(p);
mgruhler gravatar image mgruhler  ( 2019-12-02 01:40:10 -0600 )edit

@mgruhler Good example that should answer OP's question, I just wanted to notify you that you declared p as a Pose but used it as a PoseStamped.

Delb gravatar image Delb  ( 2019-12-02 03:49:16 -0600 )edit
3

@Delb, thanks. good catch, old habits die hard (I almost never use Poses/Posearrays :-) ). As I couldn't edit the above comment, here is the corrected example:

geometry_msgs::PoseArray  posearray;
posearray.header.stamp = ros::Time::now(); // timestamp of creation of the msg
posearray.header.frame_id = "map" // frame id in which the array is published
geometry_msgs::Pose p; // one pose to put in the array
// fill p appropriately
p.position.x = ...
p.orientation.x = ...
// push in array (in C++ a vector, in python a list)
posearray.poses.push_back(p);
mgruhler gravatar image mgruhler  ( 2019-12-02 06:22:58 -0600 )edit

This question and its answer (ROS1) could help you with implementing publish/subscribe of arrays.

ljaniec gravatar image ljaniec  ( 2021-11-24 02:23:24 -0600 )edit