Robotic enthusiast.
Finally, we have a model of the robot that you can use to visualize interviews or to simulate in Gazebo.
We can use this model to develop now new functionalities.
However, so far our robot is static and so we are not yet able to move the robot in the simulated environment
of gazebo.
For the moment, our robot is just a nice decoration.
In this section, we will talk about the first and perhaps the most elementary functionality that a
robot must implement, which is to actuate the joint motors in response to a received command.
This functionality, although the most basic, it is also fundamental as it will be used by all the
other modules that perform advanced operation with the robot to move it accordingly to the own logic.
The operation of sending a command to a robot following its movement and ensuring that it matches the
desired movement is called control, and it is an entire field of study that deals with the development
of the mathematics for creating a component called controller.
The goal of this discipline is very simple and practical.
It's to implement a logic that activates a certain system, in this case, a motor as required by the
input variable.
For example, a goal, an input variable that we can send to the control system is to rotate the motor
to reach a certain angle, let's say a position of 90 degrees.
So this goal, this input variable that we pass to the control system contains the desired value of
the system movements.
This input is compared with the current state of the system.
So with the current state of the motor, because it can also happen that the motor, for example, is
already at the desired position and therefore it doesn't need to move to reach it.
So the difference between the current state of the motor that is called output and the goal that we
assigned to the motor that is called input produces a new variable called error.
This variable indicates how far the current state of the motor.
So the output variable is from the desired state.
So the input variable.
For example, let's assume that the motor is currently in the zero degree position.
So in this case the output variable is zero.
And let's also say that we instruct the motor to move in the 90 degrees position, which means that
we are setting the input variable to 90.
Now the error variable will be the difference between the input variable, which is 90 degrees and the
output variable which is zero because the motor is indeed zero degree position.
So the error variable will be 90 degrees.
The purpose of developing a control system is to create a block called controller that receives the
error variable as input and converts it into a command to send to the motor.
This calculation is done with the aim of minimizing the error variable so that its value gets closer
and closer to zero and also as quickly as possible.
This calculation is done with the aim of minimizing the error variable so that its value gets closer
and closer to zero as quickly as possible.
Upon receiving the comment, the motor starts to rotate and gradually change its angle.
So it's position and then the control loop is executed again.
As the motor moves to reach the desired position, the error variable will no longer be equal to 90
degrees because the motor is getting closer to it and the closer it gets, the smaller the error variable
becomes and consequently the comments sent by the motor and consequently also the command that is sent
by the control system to the motor.
When the motor finally reaches the desired position that is 90 degree, then the output variable finally
matches the input variable.
And so the difference.
So the error variable is finally zero.
The control problem is common to all robots.
Whether you want to develop a manipulator or a mobile base or even a drone.
Sooner or later in the development of your robots, you will have to deal with the control problem,
which means sending commands to actuators and receiving feedback from the sensors on how the actuators
we commanded have actually moved.
For this reason, since this is a common problem for all robots, there is a fantastic framework in
Ros two called Ros to control.
At the core of this framework, there are components called hardware resources.
This can be composed of actuators to which we can send commands or sensors from which we can retrieve
information about the state of an actuator, such as its velocity or position.
Additionally, an hardware resource can also represent an entire complex system composed of several
actuators and sensors.
All these components can be both real or also simulated within the physical engines, including Gazebo.
To interface with the hardware resources.
The Ros2 Control Library provides two interfaces.
The command interface and the state interface.
With the command interface, we can send commands to the robot's hardware.
We can basically write commands with the state interface instead.
We can only receive information, so we can only read the current state of the hardware.
In short, with the command interface, we write commands to the hardware and with the state interface
we read from the hardware.
Managing this interface with the hardware resource is a component called resource manager, which is
an abstraction of the actual hardware components of the robot and its drivers.
It allows the reuse of already implemented hardware components without the need to implement new ones.
The resource manager can load one or more hardware components and make them available and thus interactable
with the other components of the control library and so with the controller manager.
At this component provides an additional level of abstraction and acts as a middleware, a connection
point between the resource manager and the actual controllers that implement the control logic of the
specific system or actuator.
In fact, the controller manager can load multiple controllers simultaneously that implement different
control logics and connect them to the hardware or more precisely, connect them to the resource manager
that manage the robot's hardware components.
The controllers loaded by the controller manager are the components where the control logic is implemented.
The one that ensures that the system output equals the desired input.
In addition to developing new controllers, it is also possible to use many controllers that are already
available in the Ros two Controllers library.
Beware of being misled by the names of these two libraries.
The Ros2 Control Library contains the definition of the controller manager and the resource manager
instead.
The Ros two Controllers library contains the definition of some controllers which already implement
some specific control logic, for example, to move differential drive, robot and so on.
In addition to connecting the controllers which implement the control logic and the hardware components
which must execute the logic, the controller manager also provides an interface to others to application
and even to the user who can use the command line interface, for example, to obtain the list of all
the controllers or the list of all the hardware components, and then can also load the new controllers
and can in general interact with the control library.
Likewise other ros2 nodes and application that want to use that want to activate the hardware or obtain
information about its state can do so directly through the services and the topics that are provided
by the controller manager.