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

Error error in operand of ‘->’ which has non-pointer type ‘sensor_msgs::PointCloud’

asked 2014-04-12 21:33:20 -0500

RSA gravatar image

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 ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2014-04-12 22:17:27 -0500

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()
edit flag offensive delete link more

Comments

thank you it worked

RSA gravatar image RSA  ( 2014-04-12 23:16:17 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-04-12 21:33:20 -0500

Seen: 1,773 times

Last updated: Apr 12 '14