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

Issue with creating Pose[] pose array

asked 2019-10-26 07:13:33 -0600

SunnyKatyara gravatar image

updated 2019-10-26 07:13:53 -0600

Since, i have created my own service whose requests are seven geometry_msgs/Pose point1, point2 ...point7. I am calling all of these request into my script in the following way;

std::vector<geometry_msgs::Pose> waypoints;
  int number_of_waypoints = 7;
  double x[number_of_waypoints];
  x[0] = request.point1.position.x;
  x[1] = request.point2.position.x;
  x[2] = request.point3.position.x;
  x[3] = request.point4.position.x;
  x[4] = request.point5.position.x;
  x[5] = request.point6.position.x;
  x[6] = request.point7.position.x;
  double y[number_of_waypoints];
  y[0] = request.point1.position.y;
  y[1] = request.point2.position.y;
  y[2] = request.point3.position.y;
  y[3] = request.point4.position.y;
  y[4] = request.point5.position.y;
  y[5] = request.point6.position.y;
  y[6] = request.point7.position.y;
  double z[number_of_waypoints];
  z[0] = request.point1.position.z;
  z[1] = request.point2.position.z;
  z[2] = request.point3.position.z;
  z[3] = request.point4.position.z;
  z[4] = request.point5.position.z;
  z[5] = request.point6.position.z;
  z[6] = request.point7.position.z;

Now i want to create an array instead of calling all of these separately on the run time. Because when i call my service from the terminal, it asks me to put all the seven poses, that is perfect but i want to it win such a way that from the terminal it asks the number of way-points and then it asks me to substitute the given number of poses for way-points. Right now, the seven way-points are hard coded, means if want to increase or decrease the number, i have to do it manually. I want to use geometry_msgs/Pose[] pose in my service instead of declaring the seven messages separately and then creating an array inside my script to ask me the number of way-points and then forms the size of array according and ask me the poses in the terminal. I am bit confused how to do it.

Looking forward to the help.

Thank You

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-26 18:17:17 -0600

updated 2019-10-26 18:18:41 -0600

So I'll admit that your question as written isn't entirely clear to me what you're trying to accomplish. What I do gather from it is you're interesting in how to use an array type in a ros message, where the example you want is a Pose. I can help with that. Though looking at your code you don't actually use the vector of Poses variable you create at the beginning. See sample below.

geometry_msgs::PoseArray my_poses;

// my_poses.poses is going to be your array of pose messages. In C++ its a vector.

// populate your messages, your example is 7
for (uint i = 0; i != 7; i++) {
  geometry_msgs::Pose curr_pose;
  curr_pose.position.x = 42.0;

so as you can see, its just a vector object your working with where the vector starts with size 0, so you have to either push_back new elements or reserve/resize with your known number of elements.

If you look at it, the definition of a geometry_msgs/PoseArray is

std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
geometry_msgs/Pose[] poses
  geometry_msgs/Point position
    float64 x
    float64 y
    float64 z
  geometry_msgs/Quaternion orientation
    float64 x
    float64 y
    float64 z
    float64 w

so this shows on a general basis has to use a variable[] type as a ros message.

edit flag offensive delete link more


Dear Steve, thanks for your response. The number of poses is seven this time but i want to make changeable from the terminal during run time. I mean when i can the service i should ask me for number of poses and then on the basis of that number it starts looping. My service has request geometry_msgs/Pose[] points and init32 number. But when i call my service i am unable to pass multiple poses at the same time.

Thank You

SunnyKatyara gravatar image SunnyKatyara  ( 2019-10-27 07:38:27 -0600 )edit

If you're just pushing back points, it doesn't matter what the size is. That's the point of a vector and the Pose[] is that it can be any number of poses you'd like

stevemacenski gravatar image stevemacenski  ( 2019-10-27 17:14:54 -0600 )edit

Question Tools

1 follower


Asked: 2019-10-26 07:13:33 -0600

Seen: 1,609 times

Last updated: Oct 26 '19