Search code examples
c++rospoint-cloud-library

tpp.c:84: Assertion fails when using pcl_ros::transformPointCloud


I'm trying to make a node to use a tf listener and subscribe to a PointCloud2 topic and output a new PointCloud2 topic that has been transformed to ground frame, using the pcl_ros::transformPointCloud function. The code runs fine until it receives a message, when it fails upon the first call of the pcl_ros function with the following error message:

transf_vox_cloud: tpp.c:84: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= fifo_min_prio && new_prio <= fifo_max_prio)' failed. Aborted (core dumped)

#include <ros/ros.h>
#include <tf/tf.h>
#include <tf/transform_listener.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_ros/transforms.h>
#include <string>

class STP
{
    public:
    STP()
    {
        new_PCD_pub = n.advertise<sensor_msgs::PointCloud2>("new_voxel_cloud",500); //define publisher
        old_PCD_sub = n.subscribe("voxel_cloud",500, &STP::transformCallback, this); //define subscriber
        ros::spin();
    }

    private: //initialize node, define pub/sub, initialize tf listener, define destination frame for transforms
    ros::NodeHandle n;
    ros::Publisher new_PCD_pub;
    ros::Subscriber old_PCD_sub;
    tf::TransformListener *tf_listener;
    std::string dest_frame = "/map";

    void transformCallback(const sensor_msgs::PointCloud2::ConstPtr& camera_frame_cloud) //callback func to transform received pointcloud
        {
            sensor_msgs::PointCloud2 map_frame_cloud;
            pcl_ros::transformPointCloud(dest_frame, *camera_frame_cloud, map_frame_cloud, *tf_listener);
            new_PCD_pub.publish(map_frame_cloud);
        }
}; //end callback func
int main(int argc, char** argv){

    ros::init(argc, argv, "voxel_cloud_transformer");
    STP STPobject;

    return 0;

}

Solution

  • You have not initialized the tf_listener so you're dereferencing a nullpointer. The minimum change required should be:

    public:
      STP() :
          tf_listener {new tf::TransformListener}
      {
        new_PCD_pub = n.advertise<sensor_msgs::PointCloud2>("new_voxel_cloud", 500); //define publisher
        old_PCD_sub = n.subscribe("voxel_cloud", 500, &STP::transformCallback, this); //define subscriber
        ros::spin();
      }
    

    but I haven't tried so let me know.

    That said, I'd suggest having the listener not on the heap (I don't see a good reason why), or at least using a smart pointer if you do. I'd also suggest initializing n, not spinning inside the constructor, using tf2 instead of tf, among other things.