Ask Your Question
0

segmentation fault (core dumped) caused by ros::spinOnce?

asked 2013-06-01 08:31:42 -0600

anthonyli gravatar image

updated 2014-01-28 17:16:43 -0600

ngrennan gravatar image

In these days, I spent all my time with coding, but there always problems with me, the newbie to ROS. And I try to search the answer here, but I still need some help.

For the question, main point is that I need to grab a picture from ROS message, then do some image processing, then grab another one.....

when I try to get cvimage from ROS, I use the callback function which is called by ros::spin(). Then the program will always stay in callback function. So I try to do it with several ways.

The first method, I use ros::spin() to call the callback function and get a frame, then I use ros::shutdown() in order to exit the callback function. This method is works, but for each frame I need to init the ros again with ros::init(argc,argv,"XXX") and redefine the node....So the final result is unsatisfactory because init the ros again cost a long time.

The second way, I try to deal the callback function with ros::spinOnce(), it also works when I don't attend the image processing part.(I can get the frame and show it) Then I add the image processing part, it show the qustion "segmentation fault". According to some related question, I add launch-prefix="xterm -e gdb --args" in the launch file, the final result is:

Temporary breakpoint 1, main( argc=<error reading variable: Cannot access memory at address 0x4>,argv=<error reading variable: Cannot access memory at address 0x4>)

So could someone help me to solve this problem? Thank you !

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-06-01 13:31:00 -0600

updated 2013-06-01 19:33:17 -0600

The standard design approach is to put your image processing steps in a callback, then call ros::spin() in the main program, as shown here.

You should not need to call ros::shutdown() and ros::init() for every callback. If your code is getting stuck in the callback function, then the issue probably lies with the contents of your callback. If you post the callback function here, we might be able to help.

Edit:
I still don't quite understand your issues. It would help if you could provide more detail in your original question: callback code, what you expect to see, what is actually happening, etc.

If your callback takes longer to execute than new messages are received, the new messages will be buffered by ROS behind the scenes. Your callback should not be interrupted when new messages are received. The messages will be delivered in the order received, as long as there is space remaining in the message buffer. Eventually, when the message buffer is full, the oldest message will be dropped to make room for new messages. If you always want to process the last-received message, set the queue size to 1 in the ros::subscriber constructor.

So, if your intent is to always process the most-recent image, you shouldn't need to worry about how long your image-processing steps take. Set the subscriber queue size to 1, and ROS will automatically call your callback with the most-recent message as soon as you've finished processing the previous image.

edit flag offensive delete link more

Comments

Yes, at first, I try to realize image processing in the callback function, but thereis a problem that the image processing(last for maybe 50ms) will be distrub by the next image and the data will be refresh earlier than I want.

anthonyli gravatar imageanthonyli ( 2013-06-01 14:55:27 -0600 )edit

As I described in the beginning of thequestion, I need grabbing image then do processing. But not trigger by the each image passively.

anthonyli gravatar imageanthonyli ( 2013-06-01 14:55:43 -0600 )edit

So now mine method is getting cvImage in the callback function and process it in another function. And there is still the question I asked.

anthonyli gravatar imageanthonyli ( 2013-06-01 15:01:56 -0600 )edit

To be honest, I have the same thought as you described in the answer, but when I use this method(http://www.ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages), the image will always be refreshed.

anthonyli gravatar imageanthonyli ( 2013-06-01 22:43:00 -0600 )edit

Now I am trying to not use a calss(http://www.ros.org/wiki/image_transport/Tutorials/SubscribingToImages), I hope it will works. Thank you!

anthonyli gravatar imageanthonyli ( 2013-06-01 22:43:47 -0600 )edit

Fine, I finally solve the problem! Thank you ~~

anthonyli gravatar imageanthonyli ( 2013-06-02 08:05:51 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-06-01 08:31:42 -0600

Seen: 4,048 times

Last updated: Jun 01 '13