Gazebo | Ignition | Community
Ask Your Question

How to programatically set joint friction torque?

asked 2017-06-14 23:01:52 -0500

quanke0801 gravatar image

I have a car model in Gazebo. Each of the 4 wheels has a continuous joint with friction torque in the urdf file. I want to set the friction torque value dynamically in the source code (instead of hardcoded in the urdf) to simulate the brake pedal. How can I do this? Can I use some kind of Gazebo plugin?

P.S I cannot manually apply a reverse torque to the joint because the car will never truly stop if I push the brake pedal. Instead it will shake forward and backward with a low speed forever.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-06-15 09:24:18 -0500

sloretz gravatar image

You can use a model plugin to set the joint friction. Here are tutorials for creating plugins tutorials. I think you're interested in the model plugin tutorial.

The Load method is given a physics::ModelPtr. Call GetJoint(name) where name is an std::string with the name of the joint you would like to set friction on. This will return a physics::JointPtr. On this pointer call SetParam("friction", 0, 1.0). The second argument is the joint axis. 0 says use the first axis; revolute joints only have one. The last parameter is the minimum torque required to move the joint in newton-meters.

Note, SetParam is special in that the third parameter has to be exactly the right type. The compiler can't automatically cast it for you. In this case "friction" is a double. If the third parameter is 1.0f or 1 instead of 1.0 the call will fail.

edit flag offensive delete link more


Thanks! One follow-up question: any ideas on how to pass argument from source code to this plugin? Different cars will apply brake torque on different set of joints, but I'd like to use a same plugin. Also the required friction torque is computed in the source code. Can I use ros parameter server to set the joint names and use a subscriber in the plugin to get the required friction?

quanke0801 gravatar imagequanke0801 ( 2017-06-15 13:26:29 -0500 )edit

Sure, make the arguments part of the SDF for each instance of the plugin. SDF allows aribtrary XML tags to be passed to a plugin`<plugin name="my_fancy_plugin_instance" filename=""><max_brake_torque>12345</max_brake_torque></plugin>`. See the random velocity plugin for an example

sloretz gravatar imagesloretz ( 2017-06-15 13:35:32 -0500 )edit

Ah, sneaky edit about ROS parameters! I believe you can initialize a ROS node inside the plugin, and from there do whatever you like through the ROS API. The plugins will need a way of identifying which which ROS param belongs to them, but the SDF arguments gives a way to name the instances.

sloretz gravatar imagesloretz ( 2017-06-15 13:39:02 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-14 23:01:52 -0500

Seen: 2,265 times

Last updated: Jun 15 '17