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

hokuyo node laser message publishing

asked 2011-12-16 03:13:43 -0600

searchrescue gravatar image

Hi Everyone, I am trying to publish the data of the laser scans of Hokuyo node.

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "sensor_msgs/LaserScan.h"

void scanValues(const sensor_msgs::LaserScan laser)
{
    ROS_INFO("size[%d]: ", laser.intensities.size());
    for (unsigned int i=0; i<laser.intensities.size();i++)
    {
        intensities[i] = laser.intensities[i];
        ROS_INFO("intens[%f]: ", intensities[i]);

    }
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "hLaserReader");
  ros::NodeHandle n;
  ros::Subscriber hokuyoSubscriber = n.subscribe("/scan", 1, scanValues);
  ros::spin();
  return 0;
}

this is the code, but i am getting this error

In function ‘void scanValues(sensor_msgs::LaserScan)’: x.cpp:10:9: error: ‘intensities’ was not declared in this scope

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
2

answered 2011-12-16 03:34:12 -0600

dornhege gravatar image

It should be laser.intensities instead of intensities...

edit flag offensive delete link more
1

answered 2011-12-16 05:06:43 -0600

searchrescue gravatar image

This code works correctly. My mistake was in CMakeLists.txt file. I put rosbuild_add_executable(hLaser_node src/hLaserReader.cpp) very top of the file. Now that i moved this line to the bottom. Now it works. thanks.

edit flag offensive delete link more
0

answered 2011-12-16 03:43:07 -0600

searchrescue gravatar image

i have changed the function into this one

void scanValues(const sensor_msgs::LaserScan laser)
{
    ROS_INFO("size[%d]: ", laser.intensities.size());
    for (unsigned int i=0; i<laser.intensities.size();i++)
    {
        //intensities[i] = laser.intensities[i];
        ROS_INFO("intens[%f]: ", laser.intensities[i]);

    }
}

but i still get errors, i double-checked that rostopic echo /scan publishes tons of messages.

edit flag offensive delete link more
0

answered 2013-05-31 04:10:22 -0600

Xpecttrum gravatar image

updated 2013-05-31 04:10:51 -0600

Hi there, I was having the same problem, and changing the intensities to ranges it worked, try this:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "sensor_msgs/LaserScan.h"

void scanValues(const sensor_msgs::LaserScan laser)
{
    fprintf(stderr,"\n -------- size[%d] ---------- ", laser.ranges.size());
    for (unsigned int i=0; i<laser.ranges.size();i++)
    {
        fprintf(stderr,"range[%d]=[%f]: ", i, laser.ranges[i]);

    }
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "hLaserReader");
  ros::NodeHandle n;
  ros::Subscriber hokuyoSubscriber = n.subscribe("/scan", 1, scanValues);
  ros::spin();
  return 0;
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-12-16 03:13:43 -0600

Seen: 1,759 times

Last updated: May 31 '13