The objective of this tutorial is to control the robot's center of mass (CoM). As in the previous tutorial, we will write a function that moves the CoM down 20 centimeters and then moves it back to its original position.
Contacts
Before we start moving the CoM we need to consider contacts. In fact, in our previous controller we decided to keep an empty contact set and everything worked well. However, if we were trying to control the CoM now, the robot would simply sink into the ground or float in the air to follow our command. The reason is simply that without contacts, this is a perfect solution to moving the CoM while keeping a minimal posture error.
Therefore, we will add contacts between the robot's feet and the ground:
Until now we have run the controller in kinematics mode. We can switch to dynamics mode, this will enable us to:
Compute external forces and associated torques;
These forces remain in the contact friction cone;
The torques remain within the robot's torque limits;
To switch, simply change kinematicsConstraint into dynamicsConstraint in your code. All constraints enabled by kinematicsConstraints are also enabled by dynamicsConstraint.
In that particular example, we can say a few things about the task creation:
It depends on robots();
It will be applied to the robot with index 0, this is always the main robot loaded by mc_rtc;
It is attracted to the objective with a stiffness of 10.0; this parameter governs the strength of the "spring" that pulls the robot towards the objective;
It is associated a weight of 1000; this weight is the priority of the task in the optimization problem. In our case, the default posture weight is 5.0, thus the CoM task will have high priority. Please note that task errors are not normalized, and thus weights have to be tuned accordingly;
The posture task stiffness is decreased to make sure it doens't interfere with the CoM task;
Moving the CoM up and down
We will implement a method similar to the previous tutorial, using a switch_com_target() function. We will assume we have added a comDown boolean and a comZero which is an Eigen::Vector3d representing the initial CoM position.
Et voilà! You can run this controller and see that the robot is moving down and up. In the next tutorial we will see how to move an end-effector and to load the task configuration from the disk.
The full sources for this controller are available here.