ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How can I clone the class which is a parameter of chatterCallback function?

asked 2019-11-03 07:42:33 -0500

umut gravatar image

I want to use sensor_msgs::Range::ConstPtr class in main function.

I'm trying to use '='(assignment) oparetor to a gloabal variable in callback function but I get segmantation fault error.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-03 17:02:33 -0500

FailFTW gravatar image

Are your trying to copy the pointer, or are you trying to copy the data itself? Because it looks like you're trying to copy the pointer. You should be able to simply declare the object elsewhere in your program and use the '=' operator without any real fuss.

Take from this thread:

Here's a complete example of copying the actual data:

#include <ros/ros.h>
#include <sensor_msgs/Range.h>

sensor_msgs::Range bar;

myCallbackFunction(const sensor_msgs::Range& foo) {
    bar = foo;
    ROS_INFO("Data Received: [%f]", bar.range);

int main(int argc, char **argv) {
    ros::init(argc, argv, "my_node");
    ros::NodeHandle _nh;
    ros::Subscriber _sub = _nh.subscribe("range_topic", 10, &myCallbackFunction);
    return 1;
edit flag offensive delete link more

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: 2019-11-03 07:42:33 -0500

Seen: 77 times

Last updated: Nov 03 '19