iCub-main
|
This tutorial shows how to use the following interfaces:
yarp::dev::IControlMode
yarp::dev::ITorqueControl
yarp::dev::IImpedanceControl
yarp::dev::IInteractionControl
Prerequisites, see Getting accustomed with motor interfaces
The code described in this tutorial can be found at src/motorControlImpedance/tutorial_arm_joint_impedance.cpp
The example is based on the previous tutorial src/motorControlBasic/tutorial_arm.cpp
The example shows how to open the ITorqueControl to show the arm joint torques and how to change the control mode of the elbow joint from position to impedance control.
A detailed reference of the yarp interfaces used in this tutorial (IControlMode, ITorqueControl, IImpedanceControl, IInteractionControl) can be found in the YARP doxygen documentation and in the YARP Control Modes documentation.
Let us assume the module wholeBodyDynamics is up and running. The wholeBodyDynamics module, based on the iDyn library acts as a server and is responsibile for the calculation of the joint torques. In order to access to the torque values, our program has to declare and open the yarp ITorqueControl interface, in the same manner as you open the IPositionControl interface (see previous tutorial: Getting accustomed with motor interfaces). We can also open the IControlMode interface (resposibile to set the control mode of each joint (position/velocity/impedance etc.), the IImpedanceControl interface, used to set the impedance parameters (joint stiffness/ joint damping etc) and the IInteractionControl interface, used to set a joint in stiff or compliant interaction mode.
and:
We can thus start with checking how many axes we can control by doing:
Let's create some vectors for later use:
Let's now initialize the controllers and start up the amplifiers:
if needed we can check the position of our axes by doing:
which reads the values of the motor encoders into a vector of doubles of size ''jnts''.
First do:
which sets the reference speed for all axes to 40 degrees per second. The reference speed is used to interpolate the trajectory between the current and the desired position.
Now you can do:
where ''command_position'' is the desired position. This starts a movement of all axes toward the desired position.
You can use the ITorqueControl interface to read the torque at a specific joint.
You can change the impedence parameters of a joint at any time:
You can use IInteractionMode interface to change the interaction mode of a specific joint to compliant interaction mode:
When in position control mode with compliant interaction mode, the low level controller (DSP) computes a refence torque Td as:
\[ T_d = K_{spring} * (q_d-q) - K_{damp} * \dot{q} + F_{offset} \]
which is tracked by the internal PID regulator.
You can specify a new equilibrium position using the usual position interface, because the control mode of the joint is still VOCAB_CM_POSITION even if the interaction mode has changed:
If you need to change the interaction mode back to stiff mode:
An ImpedanceVelocity control mode is also available. In this control modality you can use vel->VelocityMove() command in order to command a velocity while mantaining the impedance specified with the iimp->setImpedance(joint, stiffness, damping, dorce_offset) command.
Torque control mode can be used to directly specify a reference torque at a joint.
The gains of the PID controller resposibile of tracking the torque reference can be obtained using ITorqueControl::getTorquePid() method.
NOTE: the reference torque that you can specify on the icub joints is limited (clamped) to a given value. You can check this value in the yarprobotinterface configuration files for your robot.
NOTE2: near the hardware limits of the robot, the torque PID controlled is disabled, in order to prevent to command a torque againts the hardware limits. The PID controller is automatically re-enabled as soon as the joint is moved far the limits (You can view the value of the limites using the IControlLimits interface).
NOTE3: during calibration/parking of the robot, yarprobotinterface automatically sets the control mode of all the joints to position control mode with stiff interaction mode.
NOTE4: If your application changes the control mode/interaction mode of one joint, it's good practice to reset it to the previous modality when your application quits.
When you are done with controlling the robot don't forget to close the device:
To read more about the interfaces that are available in YARP read the doxygen online documentation and in the YARP Control Modes documentation.
See code in: src/motorControlImpedance/tutorial_arm_joint_impedance.cpp