Home | Tutorials | Wiki | Issues
Ask Your Question

Access Joint from Sensor Element to Detect Full LIDAR Rotation

asked 2017-05-22 11:57:02 -0500

ogunasekara gravatar image

updated 2017-05-22 13:42:26 -0500

sloretz gravatar image

I've been working on a sensor plugin for a LIDAR sensor simulation. We added a plugin element nested in a sensor element. However, we need to access a joint that is also in the model. We want to know when the LIDAR makes a full 360 degree rotation around it's rotating axis. Our sdf model is the following:

<sdf version="1.5">

<model name="RPLidar-A2">
  <!-- Give the base link a unique name -->
  <link name="base">
    <!-- added to make sure model doesn't move, should be remomved later when added to full robot-->
    <pose>0 0 0 0 0 0</pose>

    <!-- Offset the base by half the length of the cylinder -->
    <collision name="base_collision">
      <pose>0 0 0.0097 0 0 0</pose>
          <!-- Radius and length provided by Velodyne -->

    <visual name="base_visual">

  <!-- Give the base link a unique name -->
  <link name="top">

    <!-- See abouve about gravity--> 

    <!-- Add a ray sensor, and give it a name -->
    <sensor type="ray" name="sensor">
      <plugin name="rplidar_sensor" filename="libsensor_plugin.so"></plugin>

      <!-- Position the ray sensor based on the specification. Also rotate
           it by 90 degrees around the X-axis so that the <horizontal> rays
           become vertical -->
      <pose>0 0 0.0107 1.5707 0 0</pose>

      <!-- Enable visualization to see the rays in the GUI -->

      <!-- Set the update rate of the sensor -->

        <!-- The scan element contains the horizontal and vertical beams.
             We are leaving out the vertical beams for this tutorial. -->
          <!-- The horizontal beams -->
            <!-- The RPLidar has 1 beam(sample) -->

            <!-- Resolution is multiplied by samples to determine number of
                 simulated beams vs interpolated beams. See:

            <!-- Minimum angle in radians -->

            <!-- Maximum angle in radians -->

        <!-- Range defines characteristics of an individual beam -->

          <!-- Minimum distance of the beam -->

          <!-- Maximum distance of the beam -->

          <!-- Linear resolution of the beam -->


    <pose>0 0 0.01940 0 0 0</pose>
    <!-- Vertically offset the top cylinder by the length of the bottom
        cylinder and half the length of this cylinder. -->
    <collision name="top_collision">
      <pose>0 0 0.0107 0 0 0</pose>
          <!-- Radius and length provided by Velodyne -->

    <visual name="top_visual">
      </geometry ...
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-10-18 13:11:53 -0500

updated 2017-10-18 13:15:38 -0500

This tutorial gives an example of how to access the model (and its joints) via a Gazebo plugin:
also these two plugins provide slightly different approaches:

Your boilerplate code will look a little like this:

namespace gazebo
    YourPlugin::YourPlugin() {}

    YourPlugin::~YourPlugin() {}

     /// \brief Load function gets called by Gazebo when the plugin is inserted in simulation 
     /// via URDF/SDF
     /// \param[in] _model A pointer to the model that this plugin is attached to.
     /// \param[in] _sdf A pointer to the plugin's SDF element.
     void YourPlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
        // Store the model ptr for convenience.
        this->model_ = _model;

        // Get the name of your actuator/sensor joint from the URDF/SDF
        // Assuming:
        // <gazebo reference = "SENSORLINKNAME" />
        //     <actuatorJoint>NAMEOFJOINT</actuatorJoint>
        // </gazebo>
        std::string joint_name = "";
        if ( _sdf->HasElement("actuatorJoint") ) {
            joint_name = _sdf->Get<std::string>("actuatorJoint");
        } else {
            ROS_WARN_NAMED("your_plugin", "YourPlugin missing <actuatorJoint>!!!");

        // Store the actuatorjoint pointer.
        this->joint_ = this->model_->GetJoint(joint_name);


        // Listen to the update event. This event is broadcast every
        // simulation iteration.
        this->update_connection_ = event::Events::ConnectWorldUpdateBegin (
        boost::bind ( &YourPlugin::OnUpdate, this, _1 ) );


    /// \brief Function called at each simulation interation
    void YourPlugin::OnUpdate(const common::UpdateInfo & _info)
        current_joint_angle = this->joint_->GetAngle(0).Radian() // Get joint angle


     // Tell Gazebo about this plugin, so that Gazebo can call Load on this plugin.
edit flag offensive delete link more



This is for a ModelPlugin. Both I and the OP are implementing SensorPlugins. From the SensorPlugin there is no easy access to the Model object. I'm already using a derivative of the code from that tutorial to drive the motor, but the sensors being spun have no easy access to the angle of the motor. Use of physics::get_world() and drilling down through Model to Joint does provide that access though. I didn't quite get things working yesterday but did get access to the Joint object.

RedDave gravatar imageRedDave ( 2017-10-19 04:54:33 -0500 )edit

Whoops my bad.. Glad you found a solution!

josephcoombe gravatar imagejosephcoombe ( 2017-10-19 16:25:53 -0500 )edit

Thanks. And thanks for you original suggestions. @josephcoombe

RedDave gravatar imageRedDave ( 2017-10-20 01:44:20 -0500 )edit

answered 2017-10-18 10:48:58 -0500

Did you find a solution to this query? I have a very similar problem in that I want to access the joint's angle from the mounted sensor.

Accessing the parent of the _sdf does not seem to be the way to go. The _sdf is access to the underlying XML rather than Gazebo's objects (unless I'm wrong).

What I think we need is access to the parent model that contains the sensor for which this is the plugin. But I cannot see from the SDK how that is accessed.

Anyone have any suggestions on how to access either the World or the Model in which an element exists?

This question may have the answer: http://answers.gazebosim.org/question...

edit flag offensive delete link more


@RedDave Check out my answer - I think it answers your question too

josephcoombe gravatar imagejosephcoombe ( 2017-10-18 13:18:07 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-05-22 11:57:02 -0500

Seen: 234 times

Last updated: Oct 18 '17