how to rotate joint like a drill?

asked 2018-03-07 02:10:37 -0500

nathanGroovy gravatar image

So I have a mobile rover, with a drill attached to it as a joint. I'm trying to make a plugin that will rotate the drill. But I'm having trouble figuring out how to properly rotate the drill. Here's my current code for the plugin:


#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>

namespace gazebo
  /// \brief A plugin to control a Velodyne sensor.
  class VelodynePlugin : public ModelPlugin
    /// \brief Constructor
    public: VelodynePlugin() {}

    /// \brief The load function is called by Gazebo when the plugin is
    /// inserted into simulation
    /// \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.
    public: virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
  // Safety check
  if (_model->GetJointCount() == 0)
    std::cerr << "Invalid joint count, Velodyne plugin not loaded\n";

  // Store the model pointer for convenience.
  this->model = _model;

  // Get the first joint. We are making an assumption about the model
  // having one joint that is the rotational joint.
  this->joint = _model->GetJoints()[0];

  // Setup a P-controller, with a gain of 0.1.
  this->pid = common::PID(0.1, 0, 0);

  // Apply the P-controller to the joint.
      this->joint->GetScopedName(), this->pid);

  // Set the joint's target velocity. This target velocity is just
  // for demonstration purposes.
      this->joint->GetScopedName(), 10.0);

/// \brief Pointer to the model.
private: physics::ModelPtr model;

/// \brief Pointer to the joint.
private: physics::JointPtr joint;

/// \brief A PID controller for the joint.
private: common::PID pid;

  // Tell Gazebo about this plugin, so that Gazebo can call Load on this plugin.

it's the code from one of the gazebo tutorial pages. If anybody knows what I could be doing wrong and make the joint rotate as a drill should, that would be most helpful.

edit retag flag offensive close merge delete


What are you having trouble figuring out: compiling the Gazebo plugin, using the plugin in Gazebo, sending commands to the plugin? Please clarify what the problem is.

josephcoombe gravatar imagejosephcoombe ( 2018-03-07 14:34:25 -0500 )edit

I can compile the plugin and use it in gazebo. The problem is when I try to use it on the joint it seems to struggle to rotate. Like it's rotation is locked in place and it cannot change.

nathanGroovy gravatar imagenathanGroovy ( 2018-03-07 14:39:26 -0500 )edit

Can you upload your urdf? Or the gazebo plugin bit as well as the joint it references?

josephcoombe gravatar imagejosephcoombe ( 2018-03-07 17:04:20 -0500 )edit

I'm pretty new to this, what's my urdf and where can I find it?

nathanGroovy gravatar imagenathanGroovy ( 2018-03-07 17:34:35 -0500 )edit

A better question is where did you get / how did you make your mobile rover model? I'd check the model's joints.

josephcoombe gravatar imagejosephcoombe ( 2018-03-08 08:38:28 -0500 )edit

Also that tutorial code assumes the model has a single joint (_model->GetJoints() returns an array of all the non-fixed joints if I remember correctly so _mode->GetJoints()[0]) returns the first joint in that array. Since you said you have a rover it seems likely that there are other rotational joints in your model. Check out this code from the the gazebo repo:

josephcoombe gravatar imagejosephcoombe ( 2018-03-08 08:43:08 -0500 )edit