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

How to retrieve data from xv-11 lidar using rviz?

asked 2018-08-02 08:13:54 -0600

dta800 gravatar image

I want to work with my xv-11 lidar but I am a newbie in ros, rviz. I connected the lidar succesfully and can see surroundings, data from it. Now I want to do a simple system that if it detects objects closer than 1 meter it will light red led connected with arduino, if there is no object closer than 1 meter, green led will be on. How can I define my function for getting that data from rviz? Can you at least give me a roadmap.

I am using odroid xu4, lidar xv-11, ubuntu 18.04 with ros melodic.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-04 03:15:16 -0600

updated 2020-02-04 03:16:13 -0600


I suppose that lidar you use provides LaserScan.msg type, which has fields as given in here

for your purpose ,to find points closer than 1m you can use a callback as following;


          bool red(false),green(false);
          float boundary = 1.0;
          lidar_sub_ = node_handle_ptr_->subscribe("lidar_topic", 1,&YourClass::callback, this);


       void YourClass::callback(const sensor_msgs::LaserScanConstPtr &scan){
          red = false;
          green = true;
          for (int i = 0 ; i < scan->ranges.size(); i++){
            if(scan->ranges[i] < boundary){
              red = true;
              green = false;

so after each call your green and red flags will be updated. You can use those flags to do the task you described.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-08-02 08:13:54 -0600

Seen: 103 times

Last updated: Feb 04 '20