This is my first week with Gazebo. The tutorials are clear (except for my dearth of C++ knowledge) but now that I'm working to move out on my own things are getting cloudy. I made a model comprising two boxes and a revolute joint. The file one_r_test.world loads this model. A plugin is "loaded" (?) in model.sdf and that plugin, ModelControl, comes from model_push.cc in the "Model plugins" tutorial (http://gazebosim.org/tutorials?tut=plugins_model&cat=write_plugin), which uses SetLinearVel to move a box. I can get this same behavior out of model_control.cc if I just copy the tutorial code (and change the plugin name as appropriate), but that's not what I want. I'm seeking to eventually simulate joint control of robotic manipulators and what's not working in this basic simulation is my attempt to move the model joint via the ModelControl plugin. It moves in the GUI if I set the velocity (or torque) that way. The model_control.cc code is pasted below in hopes that you can identify a problem.


#include "boost/bind.hpp"
#include "gazebo/gazebo.hh"
#include "gazebo/physics/physics.hh"
#include "gazebo/common/common.hh"
#include "stdio.h"
// In the real file these quotes are greater-than and less-than but I
// don't know how to get that to show up in my question

namespace gazebo
  class ModelControl : public ModelPlugin
  public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
      // Store the pointer to the model
      this->model = _parent;

      // Store the pointers to the joints
      this->jointR1_ = this->model->GetJoint("r1");

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

    // Called by the world update start event
  public: void OnUpdate(const common::UpdateInfo & /*_info*/)
      // Apply a small linear velocity to the model.
      //this->model->SetLinearVel(math::Vector3(.03, 0, 0));

      // Apply angular velocity to joint
      this->jointR1_->SetParam("vel", 0, 99);
      this->jointR1_->SetParam("max_force", 0, 9999999999);

      double currAngle = this->jointR1_->GetAngle(0).Radian();
      printf("Current angle is \t %f\n", currAngle);

    // Maybe I want to keep track of time?
    common::Time last_update_time_;

    // Pointer to the model
  private: physics::ModelPtr model;

    // Pointer to the update event connection
  private: event::ConnectionPtr updateConnection;

    // Pointers to joints
    physics::JointPtr jointR1_;

  // Register this plugin with the simulator

edit: If I change

this->jointR1_->SetParam("vel", 0, 99);


this->jointR1_->SetVelocity(0, 99);

then the joint moves (yes, very, very quickly). What's wrong with SetParam vs SetVelocity?

  • $\begingroup$ I have very little knowledge about c++ and I am creating a model plugin in order to control a non-holonomic robot on gazebo. While tinkering and trying to figure stuff out, I ran into an issue, when trying to compile the code above, namespace gazebo { class HolonomicPlugin : public ModelPlugin { public: void Load(physics::ModelPtr parent, sdf::ElementPtr /*_sdf*/) { // Store the pointer to the model this->model = _parent; this->jointR1 = this->model->GetJoint()[0]; // Listen to the update event. This event is broadcast every // simulation iteration. this->updateConnection = event::Events::Co $\endgroup$
    – walkofsoul
    Aug 18, 2018 at 22:13

1 Answer 1


Your first line is:

virtual bool SetParam   (   const std::string &     _key,
unsigned int    _index,
const boost::any &  _value 
pure virtual
Set a non-generic parameter for the joint.

replaces SetAttribute(Attribute, int, double) List of parameters: "friction" Axis Coulomb joint friction coefficient. "hi_stop" Axis upper limit. "lo_stop" Axis lower limit.

[in]    _key    String key.
[in]    _index  Index of the axis.
[in]    _value  Value of the attribute.

And the second one is based on this member function of joint class from Gazebo API here:

virtual void SetVelocity    (   unsigned int    _index,
double  _vel 
pure virtual
Set the velocity of an axis(index).

[in]    _index  Index of the axis.
[in]    _vel    Velocity.

So yes your robot joint will move depending on the parameter _vel. Don't just depend on Gazebo Tutorials if you want to make your own robot, it's not enough. See also Gazebo API, if you're not good in C++ that much then first learn the important aspects of C++ like inheritance, access specifiers, object classes, friend functions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.