ROS 2 Humble | C++ | Gazebo Classic | ros2_control | effort_controllers | PID motor control
This repository provides ros2 packages for the control of a simple 2 links - 1 joint system.The simple model is supposed to emulate a fixed motor moving a simple cylindrical load.
Differently from any other ros2_control projects, here I implement a custom node for the control of joint position, based on a cascade controller.
This project was born because of some difficulties in implementing transmissions in ros2_control, for simulating a motor's gearbox (still not working, any advice is welcome!).
Anyway, I found this valuable for anyone experimenting with ROS 2, Gazebo, ros2_control, URDF, PID tuning and anti-wind up experiments (for now Back calculation algorithm).
To better understand the control scheme and the tuning procedure, you can refer to MATLAB and Simulink files.
Soon I will update the README with additional information about the control scheme, for those who don't have a MathWorks License ;).
- system_description: Provide Rviz configuration and URDF of the model
- system_bringup: Just a bring-up node, storing all launcher
- system_command_interface: Map PS4 joypad commands or command line user commands into reference signals.
- system_control: Implement the control algorithm, and save results in a ".csv" file for reference-tracking performance analysis through a Python script.
read data from ros2_control state interface and write effort commands by an effort_controller.
Note
I have tested the code with humble, I'm not sure about older ros2 version compatibility
-
For newcomers in ROS 2, after setting up ROS 2 (desktop install) and creating the workspace as in the wiki, just clone this repo in your src:
git clone https://github.com/AlePuglisi/simple-system-control.git
be sure to have installed:
sudo apt install ros-humble-ros2-control ros-humble-ros2-controllers ros-humble-gazebo-ros2-control
build your ros2 workspace and source (follow one of the many the tutorial for adding in your bashrc the setup.bash and colcon argcomplete)...
-
# Terminal 1 ros2 launch system_bringup control_simulate.launch.py
will run the controller node, Rviz, Gazebo, joy node and set up the controllers.
Then in another terminal:
# Terminal 2 ros2 run system_command_interface system_command_interface
Show below all the joypad commands, or command line equivalent, with the terminal input to publish the command if no joypad is available:
# Terminal 3, for command line commands: ros2 topic pub --once /string std_msgs/msg/String '{data: YOUR_COMMAND}'
Now you are ready to move the load in the desired angle position!
-
During the simulation, several signals have been saved in ~/system_control/data_record.csv To visualize it, in a free terminal change the directory to ~/system_control/script and run:
python3 plot_result.py
The names of the plotted signals are intuitively chosen to understand what it is showing up.
Note
This Python script uses pandas and matplotlib, be sure to have those libraries installed.
I believe that this code could be of help to anyone struggling with Laplace domain controller implementation. It is always hard to go from theory to practice. Also, experimenting with anti-wind-up is very useful to understand the effect of actuator limitations, try to play with the anti-wind-up term, and the motor limits, to see what I'm talking about. Changing gains, removing gravity compensation terms, or increasing load length or mass, show the power of this cascade control scheme.
Consider that, for now the controller has been tested mainly on a regulation problem (step reference) or for a simple ramp signal in Simulink. It can be useful to analyze tracking performances instead of regulation ones, providing a time-varying trajectory on the joint position (like a sinusoidal reference).
As a final note, this controller could be implemented using a custom controller in ros2_control, to make it more real-time reliable and integrated with ros2_control itself. It is not an easy task, but for sure an improvement.
For any question, curiosity, or problem, don't hesitate to open an issue or contact me.