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

Assign values to arrow marker starting position

asked 2021-05-20 12:17:06 -0500

RaphaelHoefer gravatar image

updated 2021-05-20 13:43:54 -0500

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

edit retag flag offensive close merge delete

Comments

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

gvdhoorn gravatar image gvdhoorn  ( 2021-05-20 13:09:10 -0500 )edit

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

RaphaelHoefer gravatar image RaphaelHoefer  ( 2021-05-20 13:29:06 -0500 )edit

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?

gvdhoorn gravatar image gvdhoorn  ( 2021-05-20 13:41:06 -0500 )edit

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

RaphaelHoefer gravatar image RaphaelHoefer  ( 2021-05-20 13:45:30 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-22 01:49:40 -0500

miura gravatar image
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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-05-20 12:17:06 -0500

Seen: 713 times

Last updated: May 22 '21