[Documentation] [TitleIndex] [WordIndex

Note: This tutorial assumes that you have completed the previous tutorials: Moving the Robot.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Setting new Controller Parameters

Description: Learn how to change the PID parameters value on our real hardware using ROS.

Tutorial Level: ADVANCED

  Show EOL distros: 

Using a ROS Node

You can update the controller parameters from your node. Here is a simple example:

   1 import roslib; roslib.load_manifest('sr_hand')
   2 import rospy
   4 from sr_robot_msgs.msg import joint, sendupdate, contrlr
   6 def talker():
   7     pub2 = rospy.Publisher('contrlr', contrlr)
   8     data_to_send = ["p:0","i:0"]
   9     pub2.publish( contrlr( contrlr_name="smart_motor_ff2" , 
  10                            list_of_parameters = data_to_send, 
  11                            length_of_list = len(data_to_send) ) )
  13 if __name__ == '__main__':
  14     try:
  15         talker()
  16     except rospy.ROSInterruptException: pass

In the data_to_send vector, you have a list of possible parameters you can modify. The description of those parameters is made in the standard doc you received with the hardware, describing them is out of the scope for this tutorial.

  • int16 p
  • int16 i
  • int16 d
  • int16 imax
  • int16 target
  • int16 sensor
  • int16 valve
  • int16 deadband
  • int16 offset
  • int16 shift
  • int16 max
  • int16 motor_maxforce
  • int16 motor_safeforce
  • int16 force_p
  • int16 force_i
  • int16 force_d
  • int16 force_imax
  • int16 force_out_shift
  • int16 force_deadband
  • int16 force_offset
  • int16 sensor_imax
  • int16 sensor_deadband
  • int16 sensor_offset
  • int16 max_temperature
  • int16 max_current

Using the Command Line

You can publish the contrlr message using rostopic:

$ rostopic pub /srh/contrlr sr_robot_msgs/contrlr "{contrlr_name: smart_motor_ff2, list_of_parameters: [\"p:0\",\"i:0\"], length_of_list: 1}"

When using the Shadow hand you may wish to tune the PID parameters for different joints to meet your requirements. This only applies to the real hardware, you should not need to alter these parameters in simulation.

For the default mixed position and velocity controllers, you can tune the following parameters:

  • float64 position_p
  • float64 position_i
  • float64 position_d
  • float64 position_i_clamp
  • float64 min_velocity
  • float64 max_velocity
  • float64 position_deadband
  • float64 velocity_p
  • float64 velocity_i
  • float64 velocity_d
  • float64 velocity_i_clamp
  • float64 max_force
  • int32 friction_deadband

Using the GUI

The most straightforward way to adjust controller parameters is using the Shadow Robot controller plugins in rqt_gui. This is started by running:

$ rosrun rqt_gui rqt_gui

The under the plugins menu go to Shadow Robot > Controllers > Controller Tuner. From here select the type of controllers you want to tune, then you can easily adjust individual joint parameters update them, and save them to file.

Using a ROS Node

You can update the controller parameters from your node. Here is a simple example:

   1 import roslib; roslib.load_manifest('sr_hand')
   2 import rospy
   3 from sr_robot_msgs.srv import *
   5 def cont_param_client():
   6     rospy.wait_for_service('/sh_ffj0_mixed_position_velocity_controller/set_gains')
   7     try:
   8         ffj0_gains = rospy.ServiceProxy('/sh_ffj0_mixed_position_velocity_controller/set_gains', SetMixedPositionVelocityPidGains)
   9         ffj0_gains(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 1)
  10     except rospy.ServiceException, e:
  11         print "Service call failed: %s"%e
  13 if __name__ == "__main__":
  14     try:
  15         cont_param_client()
  16     except rospy.ROSInterruptException: pass

Using the Command Line

If you do not wish to use the GUI you can use the following method to adjust controllers:

From Fuerte onwards, each joint controller has its own set_gains service to adjust these parameters. Once the system is up and running, entering the following command will show you the running services:

$ rosservice list

You can easily update parameters for testing individual controllers by calling the appropriate service from the command line, however these will not be saved the next time the system is started. For example (with nonsense values):

$ rosservice call /sh_ffj0_mixed_position_velocity_controller/set_gains 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 1

You can then check the parameters have been updated by viewing the appropriate controller state topic:

$ rostopic echo /sh_ffj0_mixed_position_velocity_controller/state

Saving the Values

Once you have decided on the best controller values for your application, you can adjust them in the yaml file from which they are loaded when the controllers start. It is advisable to create a backup of these files before you adjust them, as they will have already been tuned for your specific hardware.

You can cd to the correct directory as follows:

$ roscd sr_ethercat_hand_config/controls/host

Here you can find the yaml files containing parameters for each of the different types of controllers.

Our stacks have not yet been released under Groovy, please use the Fuerte versions.

Our stacks have not yet been released under Hydro, please use the Fuerte versions.

2019-08-17 13:17