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

Subscriber to /scan

asked 2014-06-20 15:30:50 -0600

aniket gravatar image

updated 2014-06-20 15:31:33 -0600

This the error i'm getting for the code m writting below. I'm trying to write a subscriber to /scan and a callback function which prints the angle_min on the terminal (ranges[] later). However i guess im making a mistake in the ROS_INFO(....) part. Please have a look and Please help. Thank You.

In function ‘void poseMessageReceived(const ConstPtr&)’: error: ‘const ConstPtr’ has no member named ‘angle_min’ make[2]: * [beginner_tutorials/CMakeFiles/lms.dir/src/lms.cpp.o] Error 1 make[1]: * [beginner_tutorials/CMakeFiles/lms.dir/all] Error 2

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

    void poseMessageReceived(const sensor_msgs::LaserScan::ConstPtr& scan)
    {
        ROS_INFO("position=: [%f]",scan.angle_min);
    }

    int main(int argc,char **argv)
    {
        ros::init(argc,argv,"subscribe_to_scan");
        ros::NodeHandle n;

        //Create a subscriber object
        ros::Subscriber sub = n.subscribe("/Scan",1000, poseMessageReceived);

        //Let ROS take over
        ros::spin();

        return 0;
    }
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2014-06-20 15:44:44 -0600

bvbdort gravatar image

use scan->angle_min instead of scan.angle_min

edit flag offensive delete link more

Comments

i guess it kind of worked but now it gives me this error Scanning dependencies of target lms [ 66%] [ 66%] Built target talker Built target listener [100%] Building CXX object beginner_tutorials/CMakeFiles/lms.dir/src/lms.cpp.o Linking CXX executable lms [100%] Built target lms

aniket gravatar image aniket  ( 2014-06-20 16:00:13 -0600 )edit
1

can you post error clearly.

bvbdort gravatar image bvbdort  ( 2014-06-20 16:17:10 -0600 )edit

i cant edit my comment. so i have asnwered it. Please look at the second asnwer above. Thanx

aniket gravatar image aniket  ( 2014-06-20 16:45:51 -0600 )edit

its not showing any error, you can share your CMakeLists file from http://pastebin.com/

bvbdort gravatar image bvbdort  ( 2014-06-20 16:56:43 -0600 )edit

http://pastebin.com/G12Gxbki

aniket gravatar image aniket  ( 2014-06-20 16:59:45 -0600 )edit

i assume you are using only lms.cpp and not talker.cpp,listener.cpp. ....remove add_executable(talker src/talker.cpp) and add_executable(listener src/listener.cpp) and build use this CMake file http://pastebin.com/w8nfMk0E

bvbdort gravatar image bvbdort  ( 2014-06-20 17:08:15 -0600 )edit

http://pastebin.com/5NmrBvFV It shows no error. But i still cant find the executable. And when i try to run rosrun beginner_tutorials lms, it gives me this error ====>>> [rosrun] Couldn't find executable named lms below /home/melab/catkin_ws/src/beginner_tutorials

aniket gravatar image aniket  ( 2014-06-20 17:24:05 -0600 )edit
1

do source devel/setup.bash in your workspace

bvbdort gravatar image bvbdort  ( 2014-06-20 18:12:07 -0600 )edit
0

answered 2014-06-20 16:46:43 -0600

aniket gravatar image

updated 2014-06-20 16:50:50 -0600

lms.cpp is the name of the file. catkin_make gives the below mentioned output. But i cannot find the executable file insisde devel/lib/....Please help

  catkin_make
        Base path: /home/melab/catkin_ws
        Source space: /home/melab/catkin_ws/src
        Build space: /home/melab/catkin_ws/build
        Devel space: /home/melab/catkin_ws/devel
        Install space: /home/melab/catkin_ws/install
        ####
        #### Running command: "make cmake_check_build_system" in "/home/melab/catkin_ws/build"
        ####
        ####
        #### Running command: "make -j4 -l4" in "/home/melab/catkin_ws/build"
        ####
        [ 66%] [ 100%] [100%] Built target lms 
        Built target listener
        Built target talker
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-06-20 15:30:50 -0600

Seen: 1,925 times

Last updated: Jun 20 '14