Ask Your Question

Copy sensor_msgs::LaserScanPtr& from callback function

asked 2016-04-13 09:03:52 -0500

bergercookie gravatar image

I have a local class member that I have defined as follows

sensor_msgs::LaserScan *current_scan_ = new sensor_msgs::LaserScan;

I also have a callback function which is called when a new laser scan is available on a /scan topic:

void CallbackHandler::getCurLaserScan(const sensor_msgs::LaserScanConstPtr& laser_in)

The question is, how can I assign a LaserScanConstPtr& object to a LaserScan* object? Is this assignment even possible? What is the advised way in manipulating incoming laser scans from the function?

The purpose of this, is to have a LaserScan object on the heap with the most recent laser scan contents.

Thanks in advance,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-04-13 11:01:45 -0500

dornhege gravatar image

updated 2016-04-14 11:09:03 -0500

What does *current_scan = *laser_in do?

edit flag offensive delete link more


My goal is to make the current LaserScan, given at the getLaserScan callback, available outside the scope of the callback function. So I thought I could assign the contents of laser_in to a pointer in the heap, and then refer to the current laser scan by dereferencing the pointer each time I need..

bergercookie gravatar image bergercookie  ( 2016-04-13 14:42:37 -0500 )edit

@dornhege: Shouldn't that be *current_scan = *laser_in; ?

Felix Endres gravatar image Felix Endres  ( 2016-04-14 04:55:43 -0500 )edit

Thanks @Felix Endres , Corrected.

dornhege gravatar image dornhege  ( 2016-04-14 11:09:29 -0500 )edit

As it turns out that's one way to do it, yes.. In my situation, given that the callback function is inside a class, i Initialised a sensor_msgs::LaserScan variable on the stack and assigned the contents of laser_in inside the callback function.

bergercookie gravatar image bergercookie  ( 2016-04-14 18:10:35 -0500 )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


Asked: 2016-04-13 09:03:52 -0500

Seen: 667 times

Last updated: Apr 14 '16