Gazebo Subscriber for a Ray Sensor

asked 2020-02-25 14:20:11 -0500

abed gravatar image

Hello, I created a Lidar sensor in gazebo and i want to receive data from it using a gazebo subscriber. I am creating the gazebo subscriber inside the load function of the gazebo plugin so it gets automatically activated with the simulation, but when after inserting the model into the gazebo environment i can't run the simulation. I have noticed using gz topic -i that the Lidar sensor's topic has two subscribers and no publisher. Apparently gazebo creates a subscriber and a publisher for the Lidar sensor on its own and when i have created a subscriber on my own something went wrong. So is there anyway to control the Lidar sensor's data (not just displaying the data using gz topic echo)? Is there anything wrong in my approach? Here is the code for my plugin:

#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/transport/transport.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/gazebo_client.hh>
#include <iostream>

namespace gazebo {

  class VelodynePlugin:public ModelPlugin{


       physics::JointPtr joint;
       // start
       transport::NodePtr gazeboNode;
       transport::SubscriberPtr gazeboSubscriber;
       void gazebo_callBack_fun(ConstLaserScanStampedPtr &msg){

   std::cout << "The minimum angle is:" << msg->scan().angle_min()<< std::endl;

       virtual void Load(physics::ModelPtr _model, sdf:: ElementPtr _sdf){
   joint = _model->GetJoint("Lidar_Joint");
   joint->SetVelocity(0, 3.14);
   gazeboNode = transport::NodePtr(new transport::Node());
   gazeboSubscriber = gazeboNode->Subscribe("~/Velodyne_Lidar/Top_Part/Lidar_Sensor/scan", &VelodynePlugin::gazebo_callBack_fun, this);


Here is the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.5)


#find the Gazebo required packages
find_package(gazebo REQUIRED)

add_library(Velodyne_Plugin SHARED
target_link_libraries(Velodyne_Plugin ${GAZEBO_LIBRARIES})

And this is my model.sdf file:

    <?xml version='1.0'?>
<sdf version='1.6'>
  <model name='Velodyne_Lidar'>
    <link name='Top_Part'>

< ixz>0</ixz>
        <pose frame=''>0 0 0 0 -0 0</pose>
      <pose frame=''>0 0 0.058674 0 -0 0</pose>


  <sensor name='Lidar_Sensor' type='ray'>
        <pose frame=''>0 0 0.03 0 -0 -1.57</pose>
  <visual name='visual'>
    <pose frame=''>0 0 0 0 -0 0</pose>
        <scale>1 1 1</scale>
      <shader type='pixel'>
      <ambient>0.3 0.3 0 ...
edit retag flag offensive close merge delete


What i have meant by controlling the Lidar sensor's data, is for example being able to store this data's values in some variables for monitoring purposes

abed gravatar imageabed ( 2020-02-25 15:00:35 -0500 )edit