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

Copy sensor_msgs::LaserScanPtr& from callback function

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

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
1

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

dornhege gravatar image

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

What does *current_scan = *laser_in do?

edit flag offensive delete link more

Comments

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 -0600 )edit
1

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

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

Thanks @Felix Endres , Corrected.

dornhege gravatar image dornhege  ( 2016-04-14 11:09:29 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 966 times

Last updated: Apr 14 '16