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

Assign value to axes Joy message

asked 2017-05-09 06:33:25 -0500

tonio gravatar image

Hi guys, my problem is that I got a segmentation fault when I assign a value to the axes of a joy message.

Here I post my code:

sensor_msgs::Joy out;
double linear_, angular_;

out.axes[1] = linear_;
out.axes[3] = angular_;
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-05-09 07:08:44 -0500

gvdhoorn gravatar image

I'm assuming this is C++.

Most likely out.axes -- a std::vector -- currently has a zero-length, and you're trying to assign values to the first and third element. That leads to your program trying to access memory it does not have access to, which leads to SEGFAULTs. See std::vector - operator [].

You either have to use .reserve(..), use .push_back(..) or use one of the c'tors of std::vector that initialises it with sufficient capacity.

edit flag offensive delete link more

Comments

1

PS: this is really a C++ question. We're happy to help, but please keep in mind that ROS Answers is not a generic programming support forum.

gvdhoorn gravatar image gvdhoorn  ( 2017-05-09 07:09:10 -0500 )edit

Sorry, I didn't know! :) By the way, thanks for the answer, it's helped!

tonio gravatar image tonio  ( 2017-05-09 11:14:00 -0500 )edit

Glad to hear it worked.

And no problem, just keep it in mind.

gvdhoorn gravatar image gvdhoorn  ( 2017-05-09 11:15:56 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-09 06:33:25 -0500

Seen: 453 times

Last updated: May 09 '17