0
$\begingroup$

Rosanswers logo

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,


Originally posted by bergercookie on ROS Answers with karma: 257 on 2016-04-13

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

What does *current_scan = *laser_in do?


Originally posted by dornhege with karma: 31395 on 2016-04-13

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by bergercookie on 2016-04-13:
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..

Comment by Felix Endres on 2016-04-14:
@dornhege: Shouldn't that be *current_scan = *laser_in; ?

Comment by dornhege on 2016-04-14:
Thanks @Felix Endres , Corrected.

Comment by bergercookie on 2016-04-14:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.