|Note: This tutorial assumes that you have completed the previous tutorials: connecting to Dynamixel bus.|
|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.|
Creating a joint torque controllerDescription: This tutorial describes how to create a joint torque controller with a Robotis Dynamixel motor.
Next Tutorial: Creating a dual joint torque controller
All files that are created in this tutorial should be saved into my_dynamixel_tutorial package which we have created in previous tutorial.
Step1: Specify controller parameters
First we need to create a configuration file that will contain all parameters that are necessary for our controller. Paste the text below following into pan.yaml file:
pan_controller: controller: package: dynamixel_controllers module: joint_torque_controller type: JointTorqueController joint_name: pan_joint joint_speed: 1.17 motor: id: 4 init: 0 min: 0 max: 4095
Note: Make sure that the motor id matches the id assigned to your dynamixel actuator and dynamixel motor is on wheel mode. You can use the set_servo_config.py with the --ccw-angle-limit=0 argument to turn the wheel mode ON.
Step 2: Create a launch file
Next we need to create a launch file that will load controller parameters to the parameter server and start up the controller. Paste the following text into start_pan_controller.launch file:
<launch> <!-- Start pan joint controller --> <rosparam file="$(find my_dynamixel_tutorial)/pan.yaml" command="load"/> <node name="pan_controller_spawner" pkg="dynamixel_controllers" type="controller_spawner.py" args="--manager=dxl_manager --port your_dynamixel_usb_port pan_controller" output="screen"/> </launch>
Step 3: Start the controller
We need to start up the controller manager node first. Please refer to the previous tutorial on how to do that.
After the controller manager is up and running we finally load our controller:
roslaunch my_dynamixel_tutorial start_pan_controller.launch
This node will load the controller and then exit, the output will look similar to the one below:
process[tilt_controller_spawner-1]: started with pid  [INFO] 1295304638.205076: ttyUSB0 controller_spawner: waiting for controller_manager to startup in global namespace... [INFO] 1295304638.217088: ttyUSB0 controller_spawner: All services are up, spawning controllers... [INFO] 1295304638.345325: Controller pan_controller successfully started. [tilt_controller_spawner-1] process has finished cleanly.
If everything started up cleanly, you should see "Controller pan_controller successfully started." message printed to the terminal.
Next, let's list the topics and services that the Dynamixel controller provides:
/motor_states/ttyUSB0 /pan_controller/command /pan_controller/state
/pan_controller/command topic expects a message of type std_msgs/Float64 which sets the velocity of the joint.
/pan_controller/state topic provides the current status of the motor, the message type used is dynamixel_msgs/JointState.
/restart_controller/ttyUSB0 /start_controller/ttyUSB0 /stop_controller/ttyUSB0 /pan_controller/set_compliance_margin /pan_controller/set_compliance_punch /pan_controller/set_compliance_slope /pan_controller/set_speed /pan_controller/set_torque_limit /pan_controller/torque_enable
A few services are provided that change the parameters of the joint, like speed, motor torque limit, compliance margin and slope, etc.
Step 4: Moving the motor
To actually move the motor we need to publish a desired velocity to /pan_controller/command topic, like so:
rostopic pub -1 /pan_controller/command std_msgs/Float64 -- 1.0
That's it, see the motor move!