Ask Your Question
0

Apply force to a joint using plugins

asked 2015-08-21 00:18:13 -0500

Fayeem gravatar image

Hi,

I am very new in Gazebo and ROS. I have a model for simple pendulum and I need to control the force applying on the joint. I can control the force using "rosservice" by external command. But I need to have a program to control that. I have followed the tutorials and I understand that this could be done by plugins but I cannot find any tutorials how to use the "rosservice" commands in a plugin. The venison of ROS is "Jade" and Gazebo is "5.1.0". I also found that there is a isuue in ros_control with Jade. I appreciate your help by giving a simple solution of my question.

Fayeem

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-08-22 18:40:13 -0500

Hi ! I just made a plugin so I might be able to help! I supposed you saw this link : Gazebo_plugin_tutorial the way i would do it is to call a function from the gazebo API in the function onUpdate() instead of a service.

re use the same class body as in the tutorial gazebo, but add it the function OnUpdate, which is called anytime gazebo update.

The plugin I did was to control the angle of the joints but I found the function setForce in the API which should be what you are looking for.

#include <gazebo/gazebo.hh>

    namespace gazebo
    {
      class WorldPluginTutorial : public WorldPlugin
      {
        public: WorldPluginTutorial() : WorldPlugin()
                {
                  printf("Hello World!\n");
                  gazebo::physics::ModelPtr this->model ;
                }

        public: void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
                {
                    this->model = world->GetModel("my_robot");
                }
        public : void OnUpdate(const common::UpdateInfo & /*_info*/)
     {
      // Apply a small linear velocity to the model.
      //this->model->SetLinearVel(math::Vector3(0, 0, 0)); // just in case needed

      // pose of the footprint
      gazebo::math::Pose mapose(this->vect3_pose_model, this->rot_pose_model);
      this->model->SetLinkWorldPose(mapose,"WheelFR_link");
    //pose of every joint 
     this.vecteur_str = ["head","base","joint3","whatever"];
      for (int i = 0 ; i < this->vecteur_str.size(); i++)
      {
         //what I used to control the joints 
        //this->model->GetJoint(vecteur_str[i])->SetAngle(0, vecteur_effort[i]);  
        // This is what you want
        this->model->GetJoint(vecteur_str[i])->SetForce(unsigned int _index, double _effort) 
      }
    }
  };
  GZ_REGISTER_WORLD_PLUGIN(WorldPluginTutorial)
}

If you need the "subscriber/publisher" functions of ROS, just instantiates them in the onLoad() as in any other ROS node.

PS: maybe you'll have more answers on answers.gazebo

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-08-21 00:18:13 -0500

Seen: 1,823 times

Last updated: Aug 22 '15