0
$\begingroup$

Rosanswers logo

Hi everybody, since my code is really long I will try to keep it minimal

in my program I wrote a class which defines 2 storing variables:

geometry_msgs::PoseWithCovarianceStamped initial_pose_;
geometry_msgs::PoseWithCovarianceStamped pose;

and subscribes to the /initialpose topic:

ros::topic::waitForMessage<geometry_msgs::PoseWithCovarianceStamped>( "initialpose", ros::Duration( 60.0 ) );
this->pose_sub_ = nh_.subscribe( "initialpose", 10, updateInitialPose );

the callback function has been defined as:

void updateInitialPose( const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& pose )
{
initial_pose_ = pose;
}

but compiling I get all the time the following error:

/home/wilhem/workspace_ros/src/turtlebot_guide/src/main.cpp: In member function ‘void robotMovement::updateInitialPose(const ConstPtr&)’: /home/wilhem/workspace_ros/src/turtlebot_guide/src/main.cpp:45:17: error: no match for ‘operator=’ (operand types are ‘geometry_msgs::PoseWithCovarianceStamped’ and ‘const ConstPtr {aka const boost::shared_ptr<const geometry_msgs::PoseWithCovarianceStamped_std::allocator<void

}’) initial_pose_ = pose; ^ /home/wilhem/workspace_ros/src/turtlebot_guide/src/main.cpp:45:17: note: candidate is: In file included from /home/wilhem/workspace_ros/src/turtlebot_guide/src/main.cpp:10:0: /opt/ros/indigo/include/geometry_msgs/PoseWithCovarianceStamped.h:57:8: note: geometry_msgs::PoseWithCovarianceStamped_std::allocator<void & geometry_msgs::PoseWithCovarianceStamped_std::allocator<void ::operator=(const geometry_msgs::PoseWithCovarianceStamped_std::allocator<void &) struct PoseWithCovarianceStamped_ ^

Even the candidated definitions are to me not really clear. I have already searched through the API and class definitions but I couldnt find a solution. Any help? Thanks in advance


Originally posted by Andromeda on ROS Answers with karma: 893 on 2014-08-22

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You are trying to assign a shared pointer geometry_msgs::PoseWithCovarianceConstPtr to an instance of geometry_msgs::PoseWithCovarianceStamped.

The operator= is not overloaded to perform deep copies (AFAIK).

The shared pointer cannot know the structure of the underlying object. A slightly annoying, but easy way of working around that is by copying the data field by field, such as:

initial_pose_.header = pose->header;
initial_pose_.pose = pose->pose;

Also note that your global variable named pose has the same name as the shared pointer (message) received in the callback.

Perhaps you could avoid using global variables in the process of making the necessary changes! :-)


Originally posted by Murilo F. M. with karma: 806 on 2014-08-22

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by ahendrix on 2014-08-22:
initial_pose_ = *pose should also work.

Comment by Andromeda on 2014-08-22:
It works!!!!!!!!!!!! Thanxxxxxxxxx!!!! But another question, how should I know that the operator = is not overloaded!?!??!?!!???

Comment by Murilo F. M. on 2014-08-22:
From the error you got, it said: error: no match for ‘operator=’ and showed the object types involved.

Comment by Andromeda on 2014-08-22:
Thanx Murilo, could you me explain please what is boost::shared_ptr ?

Comment by Murilo F. M. on 2014-08-22:
I think it is a hard topic to explain in this 'comments area'. Besides that, it falls out of the scope of the original question (we must keep the site tidy). A nice tutorial I read when I first learnt about smart pointers was this one.

$\endgroup$

Your Answer

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