Home | Tutorials | Wiki | Issues
Ask Your Question

Clarification on moving joint with model plugin

asked 2016-01-15 11:44:19 -0500

raequin gravatar image

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=pl...), 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.

I used SetParam based on this answer: http://answers.gazebosim.org/question....


#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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-21 01:31:54 -0500

gecastro gravatar image

updated 2016-01-21 01:33:47 -0500

After trying different ways of moving joints, like model->SetJointPositions(...) or joint->SetVelocity(...) they gave me very unexpected or none results... Apparently this part of the API has changed between versions.

I ended using force control + PID as explained in this answer: http://answers.gazebosim.org/question...

edit flag offensive delete link more


I'm glad to read your input. It seems like the force-control approach is less than ideal since the physics engine is supposed to be able to compute the forces necessary to obtain a prescribed motion. That is, having to tune a PID controller is doing work that could (better) be done by Open Dynamics Engine.

raequin gravatar imageraequin ( 2016-01-21 14:41:01 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-01-15 11:44:19 -0500

Seen: 1,603 times

Last updated: Jan 21 '16