Robotics StackExchange | Archived questions

How to make a geometry_msgs/PoseArray?

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.

Asked by Parth2851 on 2019-12-02 00:09:18 UTC

Comments

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);

Asked by mgruhler on 2019-12-02 02:40:10 UTC

@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.

Asked by Delb on 2019-12-02 04:49:16 UTC

@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);

Asked by mgruhler on 2019-12-02 07:22:58 UTC

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

Asked by ljaniec on 2021-11-24 03:23:24 UTC

Answers