Transform issue in buiding point cloud [closed]
I've configuring a transform for accumulating clouds over time. In the code snippet below, temp_cloud is a local accumulator, cloud the final cloud accumulator(but not yet transformed), cloud2 the final cloud accumulator that should have been transformed.
It's compiled successfully, but when I run it, the node is killed. I suspect this is because I wrongly assigned my transform listener in the pcl_ros::transformPointCloud call.
The pcl_ros::transformPointCloud have just been introduced as I only obtained 2D point cloud by which it should be in 3D point cloud (Kindly refer here).
How do I resolve this?
Thanks in advance.
The code snippet:
//Class member variables
sensor_msgs::PointCloud2 cloud;
sensor_msgs::PointCloud2 cloud2;
laser_geometry::LaserProjection projector_;
tf::TransformListener tfListener_;
//Resides in a callback function
{
sensor_msgs::PointCloud2 c_tmp;
sensor_msgs::PointCloud2 temp_cloud;
cloud.header.frame_id = "/cloud";
cloud.header.stamp = pose3D_LDD.header.stamp;
c_tmp.header.frame_id = "/c_tmp";
c_tmp.header.stamp = pose3D_LDD.header.stamp;
temp_cloud.header.frame_id = "/temp_cloud";
temp_cloud.header.stamp = pose3D_LDD.header.stamp;
static tf::TransformBroadcaster tfb;
tf::Transform xform;
xform.setOrigin(tf::Vector3(pose3D_LDD.pose.position.x, pose3D_LDD.pose.position.y, pose3D_LDD.pose.position.z));
xform.setRotation(tf::Quaternion(pose3D_LDD.pose.orientation.x, pose3D_LDD.pose.orientation.y, pose3D_LDD.pose.orientation.z, pose3D_LDD.pose.orientation.w));
tfb.sendTransform(tf::StampedTransform(xform, pose3D_LDD.header.stamp, "/world", "/base_link"));
tfListener_.waitForTransform("/world", "/base_link", pose3D_LDD.header.stamp, ros::Duration(1.0));
try
{
projector_.transformLaserScanToPointCloud("/laser", previous_scan_, c_tmp, tfListener_);
if (!initialized_cloud_)
{
cloud = c_tmp;
initialized_cloud_ = true;
}
else
{
pcl::concatenatePointCloud(cloud, c_tmp, temp_cloud);
cloud = temp_cloud;
pcl_ros::transformPointCloud("/laser", cloud, cloud2, tfListener_);
ROS_INFO("From c_tmp: Got cloud with %u of width and %u of height", c_tmp.width, c_tmp.height);
ROS_INFO("From temp_cloud: Got cloud with %u of width and %u of height", temp_cloud.width, temp_cloud.height);
ROS_INFO("From cloud: Got cloud with %u of width and %u of height", cloud.width, cloud.height);
ROS_INFO("########################################################################");
}
}
catch (tf::TransformException ex)
{
ROS_WARN("Warning: %s", ex.what());
}
}
EDIT
Error message:
pointcloud_builder_node: /usr/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h:144: Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with BinaryOp = Eigen::internal::scalar_product_op<double, double>, Lhs = const Eigen::Array<double, -0x00000000000000001, -0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>, Rhs = const Eigen::Array<double, -0x00000000000000001, -0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>]: Assertion `lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()' failed.
[pointcloud_builder_node-6] process has died [pid 27970, exit code -6].
Improved code:
try
{
projector_.transformLaserScanToPointCloud("/base_link", previous_scan_, c_tmp, tfListener_);
if (!initialized_cloud_)
{
cloud = c_tmp;
initialized_cloud_ = true;
}
else
{
pcl::concatenatePointCloud(cloud, c_tmp, temp_cloud);
cloud = temp_cloud;
pcl_ros::transformPointCloud("/base_link", cloud, cloud2, tfListener_);
ROS_INFO("From c_tmp: Got cloud with %u of width and %u of height", c_tmp.width, c_tmp.height);
ROS_INFO("From temp_cloud: Got cloud with %u of width and %u of height", temp_cloud.width, temp_cloud.height);
ROS_INFO("From cloud: Got cloud with %u of width and %u of height", cloud.width, cloud.height);
ROS_INFO("########################################################################");
}
}