Robotics StackExchange | Archived questions

Assign values to arrow marker starting position

Hello,

I am trying to publish an arrow marker and want to display this arrow in rviz. I want the starting point of the arrow to be at a point of a sensor_msgs/PointCloud message. When I am defining a starting and end point of the arrow marker like the following, it works:

visualization_msgs::Marker markers_msg;
markers_msg.points.resize(2);
markers_msg.points[0].x = 0.0f;
markers_msg.points[0].y = 0.0f;
markers_msg.points[0].z = 0.0f;
markers_msg.points[1].x = 1.0f;
markers_msg.points[1].y = 1.0f;
markers_msg.points[1].z = 1.0f;

Now I am trying to assign a specific point of the point cloud to be the starting point of the arrow marker, but it is not working. When I am echoing the cloud.points[] message values are output.

sensor_msgs::PointCloud cloud;
visualization_msgs::Marker markers_msg;
markers_msg.points.resize(2);
markers_msg.points[0].x = cloud.points[...].x;
markers_msg.points[0].y = cloud.points[...].y;
markers_msg.points[0].z = cloud.points[...].z;
markers_msg.points[1].x = 1.0f;
markers_msg.points[1].y = 1.0f;
markers_msg.points[1].z = 1.0f;

I get the error message: "Segmentation fault (core dumped)"

Can someone may help me?

Thank you very much in advance!

Kind regards,

Raphael

Asked by RaphaelHoefer on 2021-05-20 12:17:06 UTC

Comments

I'm confused. Is this not the same issue as #q378596?

Asked by gvdhoorn on 2021-05-20 13:09:10 UTC

Not exactly, now I am trying so assgin values from a message to the sarting arrow marker, if I am assigning specific values like 1.0f the arrow appear without any error. But if I try to assign the starting point to a point from the pointcloud like in the secound code example the error appears

Asked by RaphaelHoefer on 2021-05-20 13:29:06 UTC

The code you show seems to do the exact same thing as you did earlier: without reserve(..) or resize(..) indexing into a std::vector. That's a good recipe for running into SEGFAULTs.

That's what I meant by: isn't the same issue?

Asked by gvdhoorn on 2021-05-20 13:41:06 UTC

Sorry, I forgot the part in my question, i edited it accordingly. I am using the resize(...).

Asked by RaphaelHoefer on 2021-05-20 13:45:30 UTC

Answers

markers_msg.points[0].x = cloud.points[...].x;
markers_msg.points[0].y = cloud.points[...].y;
markers_msg.points[0].z = cloud.points[...].z;

cloud.points[...] of This is probably because you are referring to an index that does not exist in

You can see how many data are in cloud.points.size(). If you access from cloud.points[0] to cloud.points[cloud.points.size()-1] after receiving the data, the error in question should not occur.

Asked by miura on 2021-05-22 01:49:40 UTC

Comments