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

subscribe to a message with a pointer

asked 2019-03-08 07:05:58 -0500

Markus gravatar image

Hey there,

I have:

Header (snipped):

protected:
    #include <geometry_msgs/PoseWithCovarianceStamped.h>
    void inputPoseCb(const geometry_msgs::PoseWithCovarianceStampedConstPtr& msg);
    geometry_msgs::PoseWithCovarianceStampedConstPtr input_pose_;
    ros::Subscriber sub_pose1_;

Source code (snipped):

//..
sub_pose1_  = nh.subscribe("/cam_pose_in_world", 1, &SimpleKfNode::inputPoseCb, this);
//...
void SimpleKfNode::inputPoseCb(const geometry_msgs::PoseWithCovarianceStampedConstPtr& msg)
{
  input_pose_ = msg;
  ROS_INFO("Received a pose");
}

my code compiles fine however I get this runntime error:

/usr/include/boost/smart_ptr/shared_ptr.hpp:648: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = const geom
etry_msgs::PoseWithCovarianceStamped_<std::allocator<void> >; typename boost::detail::sp_member_access<T>::type = const geometry_msgs::PoseWithCovarianceStamped_<std::allocator
<void> >*]: Assertion `px != 0' failed.

However without pointers it works fine (no runtime error) Header (snipped):

protected:
    #include <geometry_msgs/PoseWithCovarianceStamped.h>
    void inputPoseCb(geometry_msgs::PoseWithCovarianceStamped msg);
    geometry_msgs::PoseWithCovarianceStamped input_pose_;
    ros::Subscriber sub_pose1_;

Source code (snipped):

//..
sub_pose1_  = nh.subscribe("/cam_pose_in_world", 1, &SimpleKfNode::inputPoseCb, this);
//...
void SimpleKfNode::inputPoseCb(geometry_msgs::PoseWithCovarianceStamped msg)
{
  input_pose_ = msg;
  ROS_INFO("Received a pose");
}

What is the problem here why do I get a runntime error using pointers to subscribe a message?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-03-08 09:54:28 -0500

Wolf gravatar image

Your snippets are not sufficient to determine where your error is caused. However Assertionpx != 0' failed.` of the shared pointer means that you have created a shared pointer instance and tried to access it with -> operator without having assigned it before (i.e., it is not yet pointing anywhere).

For the workaround without the shared pointer this will clearly not cause an error, because you are accessing the instance directly. However, your code (if that's everything you changed) won't do senseful operations if you have not assigned the message with contents before accessing it. Note that, by default in ROS messages all fields will be filled with zeros as they are created (bools with false).

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-03-08 07:05:58 -0500

Seen: 1,267 times

Last updated: Mar 08 '19