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

Transforming PointCloud2

asked 2015-03-12 08:14:26 -0500

RosFan19 gravatar image

Hi,

So I'm trying to transform a PointCloud2 using the method: transformPointCloud (const std::string &target_frame, const sensor_msgs::PointCloud2 &in, sensor_msgs::PointCloud2 &out, const tf::TransformListener &tf_listener)

Here is my code:

class SubscribeAndPublish
{
public:
  SubscribeAndPublish()
  {
    sub_ = n_.subscribe("/camera/depth/points", 1, &SubscribeAndPublish::callback, this);

    base_link = new std::string("base_link");
  }

  void callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
  {
    tf::Transform transform;
    transform.setOrigin( tf::Vector3(0.0, 0.0, 0.0) );
    tf::Quaternion q;
    q.setRPY(0, 0, 0);
    transform.setRotation(q);
    br.sendTransform(tf::StampedTransform(transform, msg->header.stamp, "base_link", "camera_link"));

    pcl_ros::transformPointCloud(*base_link, transform, *msg, *msgOut);
}

private:
  ros::NodeHandle n_;
  ros::Subscriber sub_;
  tf::TransformBroadcaster br;
  boost::shared_ptr<sensor_msgs::PointCloud2> msgOut;
  boost::shared_ptr<tf::TransformListener> listener;
  std::string *base_link;
};

int main(int argc, char **argv)
{
  ros::init(argc, argv, "subscribe_and_publish");

  SubscribeAndPublish SAPObject;

  ros::Rate r(10);
  while(ros::ok()) {

    ros::spinOnce();
    r.sleep();
  }

  return 0;
}

I have created the transform broadcaster so that I could visualize the transform in rviz and using the same transform to transform the PointCloud since I need to do some calculations on it (find the highest z coordinate when the PointCloud is transformed to be horizontal, but I can't do it on the original cloud since the PointCloud is tilted). I haven't added any numbers to tf::Quaternion q; q.setRPY(0, 0, 0) atm, but I will later.

However when i run the code i get an error: Segmentation fault (core dumped).

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2015-03-12 08:20:21 -0500

dornhege gravatar image

Your msgOut is probably NULL.

edit flag offensive delete link more
0

answered 2015-03-12 11:34:37 -0500

RosFan19 gravatar image

Thanks! I was under the impression that the PointCloud2 object is created in the method and is assigned to the msgOut pointer and therefore I can add a null pointer as an argument. But it seems it was not the case. It works now!

edit flag offensive delete link more

Comments

This can't work. The function doesn't take a pointer. You're explicitly dereferencing it. The same goes for the string, which also doesn't need to be a pointer.

dornhege gravatar image dornhege  ( 2015-03-12 11:52:39 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2015-03-12 08:14:26 -0500

Seen: 2,300 times

Last updated: Mar 12 '15