0
$\begingroup$

Rosanswers logo

I wrote a code to convert from laserscan points to sonar scan point from the following link

wiki.ros.org/laser_geometry where they provide the following code

Laser_geometry::LaserProjection projector_;
tf::TransformListener listener_;
void scanCallback (const sensor_msgs::LaserScan::ConstPtr& scan_in)
{
    if(!listener_.waitForTransform(
    scan_in->header.frame_id,
    "/base_link",
    scan_in->header.stamp + ros::Duration().fromSec(scan_in->ranges.size()*scan_in->time_increment),
    ros::Duration(1.0))){
 return;
 }

   sensor_msgs::PointCloud cloud;
   projector_.transformLaserScanToPointCloud("/base_link",*scan_in,
         cloud,listener_);

   // Do something with cloud.
}

This what I added only

Laser_geometry::LaserProjection projector_;
tf::TransformListener listener_;
void scanCallback (const sensor_msgs::LaserScan::ConstPtr& scan_in)
{
    if(!listener_.waitForTransform(
    scan_in->header.frame_id,
    "/base_link",
    scan_in->header.stamp + ros::Duration().fromSec(scan_in->ranges.size()*scan_in->time_increment),
    ros::Duration(1.0))){
 return;
 }

   sensor_msgs::PointCloud cloud;
   projector_.transformLaserScanToPointCloud("/base_link",*scan_in,
         cloud,listener_);

   // Do something with cloud.
    // this what I added it 

      for(int i=0; i< cloud->points.size(); ++i)
          {
             Eigen::Vector3d data(cloud->points[i].x,cloud->points[i].y,0.0);
          }

}

I got the following error base operand of ‘->’ has non-pointer type ‘sensor_msgs::PointCloud’

how can I solve it ?


Originally posted by RSA on ROS Answers with karma: 100 on 2014-04-12

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

This really is a C++ question, you probably want to read up on how pointers work in C++. Your "cloud" variable is allocated on the stack and not via a pointer, so you cannot access it´s elements using the -> operator. So everytime you access a member of cloud you have to use (for example)

cloud.points.size()

as opposed to

cloud->points.size()

Originally posted by Stefan Kohlbrecher with karma: 24361 on 2014-04-12

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by RSA on 2014-04-12:
thank you it worked

$\endgroup$

Your Answer

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