Home | Tutorials | Wiki | Issues
Ask Your Question
0

GetJointController() equivalent function for a link to handle control to links

asked 2019-03-26 22:32:56 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Running Gazebo 7.14 on Ubuntu 16.04

http://gazebosim.org/tutorials?cat=gu...

I tried implementing this tutorial and it works fine. In the plugin code used in this tutorial, a function from Gazebo API called GetJointController()is used to get a handle to the controller for the joints in the model. In my particular project, I am trying to apply a torque to Polaris Ranger XP900 (http://models.gazebosim.org/polaris_r...) to the rear wheel link. Similar to the GetJointController() function, I wasn't able to find a GetLinkController() function to handle control to the links in the API documentation. Is there any similar function which serves this purpose?

edit retag flag offensive close merge delete

Comments

1

Attach a joint to your link and control it through the joint. There is no justification from physics point of view for having a link controller. In the real world you need some kind of actuator to move things. A joint is the actuator.

kumpakri gravatar imagekumpakri ( 2019-03-28 09:17:57 -0500 )edit

Thank you for your reply. In that case, how do you apply a torque? From a physics point of view, it wouldn't be possible to apply torque to a joint

mukund24 gravatar imagemukund24 ( 2019-03-28 12:30:24 -0500 )edit

There is no method in the API documentation that seems to do this. But the documentation is very bad, so either there is no such method or one of the methods do what you need but is documented and named badly. If you only need to apply some forces to the joint to test something, you can also use the terminal command gz joint -m <model_name> -j <joint_name> -f <force>

kumpakri gravatar imagekumpakri ( 2019-03-29 05:20:08 -0500 )edit

Thank you, but I'm trying to apply a torque to a wheel (link) via a plugin, and not applying directly via the terminal. Hence I wanted to know if there's any specific function called GetLinkController() to handle control to the links!

mukund24 gravatar imagemukund24 ( 2019-04-03 15:27:53 -0500 )edit

In that case look at the SetForce and SetTorque methods in Link and Joint objects API.

kumpakri gravatar imagekumpakri ( 2019-04-09 05:17:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-04-09 10:43:37 -0500

The simulation of actuators in Gazebo occurs through joints, not through applying force directly to links. The API allows applying force directly to links, but that's for cases such as wind, buoyancy and other external forces that would push the link, not for wheel actuation.

Therefore, to move your your wheels, you should use the controllers of the revolute joints connecting the wheels to the chassis, and it seems you already found a way to get to it though GetJointController.

edit flag offensive delete link more

Comments

Yes, I figured that out, thank you! But I've run into another problem:

So I'm using the same model (http://models.gazebosim.org/polaris_r...). In my plugin, I'm using GetJoint() command to read the joint, and then using SetForce() command:

physics::JointPtr rear_left_wheel_joint=this->model->GetJoint("rear_left_wheel_joint"); rear_left_wheel_joint->SetForce(0,20.0);

Somehow, GetJoint command doesn't work, and a null ptr is being returned. Any idea where I'm going wrong?

mukund24 gravatar imagemukund24 ( 2019-04-09 15:36:50 -0500 )edit

The correct way of getting a joint is following: std::string joint_ptr_name = this->model->GetName() + "::" + this->joint_name; this->joint_ptr_ = this->model->GetJoint(joint_ptr_name);

kumpakri gravatar imagekumpakri ( 2019-04-10 10:52:15 -0500 )edit

std::string joint_ptr_name = this->model->GetName() + "::" + this->joint_name;

this->joint_ptr_ = this->model->GetJoint(joint_ptr_name);

Since I've never come across this kind of declaration ever, I have a silly doubt-Do you declare the name of the joint(from model) within the double quotes in first line, in place of the "::"? Or rather, could you briefly explain what the right hand side of the declaration in the first line means?

mukund24 gravatar imagemukund24 ( 2019-04-10 11:36:13 -0500 )edit

@mukund24, I suggest you start new questions instead of asking follow ups in comments. Make sure each question is clearly scoped to a specific issue you're having. And when a question has been successfully answered, mark it as accepted so other users can benefit from it.

chapulina gravatar imagechapulina ( 2019-04-10 12:04:34 -0500 )edit

Sorry I didn't have time back then to rewrite it into your context. This code below should be directly applicable in your code as you described it.

std::string joint_ptr_name = this->model->GetName() + "::" + "rear_left_wheel_joint";
physics::JointPtr rear_left_wheel_joint=this->model->GetJoint(joint_ptr_name); 
rear_left_wheel_joint->SetForce(0,20.0);

The point is to preface the joint name with the model name.

kumpakri gravatar imagekumpakri ( 2019-04-11 11:05:03 -0500 )edit

Works perfectly! Thank you, @kumpakri and @chapulina!

mukund24 gravatar imagemukund24 ( 2019-04-12 17:38:28 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-03-26 22:32:56 -0500

Seen: 79 times

Last updated: Apr 09