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.
Originally posted by sloretz with karma: 558 on 2017-06-15
This answer was ACCEPTED on the original site
Post score: 1
Original comments
Comment by quanke0801 on 2017-06-15:
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?
Comment by sloretz on 2017-06-15:
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="libMyFancyPlugin.so"><max_brake_torque>12345</max_brake_torque></plugin>
. See the random velocity plugin for an example http://gazebosim.org/tutorials?tut=plugins_random_velocity
Comment by sloretz on 2017-06-15:
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.