This repository implements MPC-based planning and tracking for nonlinear mobile robots using solvers generated by ForcesPro. The solver generation and runtime code are implemented in an efficient and modular way. Therefore, it is relatively straightforward to customize it to your own setting by changing the model, objective function, constraints and runtime system- or interface-specific code. Refer to How to customize? for more information.
Contents:
Install
Generate solver
Build
Run
How to customize?
-
The solver generation code is implemented using Python 3. Therefore, make sure to have Python 3 installed. The code is tested using Python 3.8.10.
-
Install ForcesPro Python solver client using the instructions provided in the documentation. The code is tested using ForcesPro client 6.3.0. A few notes:
- Make sure to have a floating license, since the code runs in a Dockerized environment.
- Unzip the downloaded client into the user home directory (~/ or /home/USERNAME), since this directory is checked to find the client in the solver generation code.
To generate a solver, use the file setup_script.sh in the mpc_solver package. This script requires the following arguments:
-c
or--config
to specify the configuration file(s) that contain the solver settings. The available options are pmpc_settings.py, tmpc_settings.py and smpc_settings.py.-s
or--system
to specify the system for which the solver should be generated. The available option ishovergames
.-f
or--floating_license_platform
to specify the platform for which the solver should be generated. The available options areARM
andx86
.-n
or--no-build
to only build the solver interface, not the solver itself.
To generate the solver for hierarchical MPC (HMPC), execute the following command:
./setup_script.sh -c tmpc_settings.py -c pmpc_settings.py -s hovergames -f ARM
To generate the solver for single-layer MPC (SMPC), execute the following command:
./setup_script.sh -c smpc_settings.py -s hovergames -f ARM
💡 Add the following lines to your ~/.bashrc file to easily navigate to the solver generation directory and generate the solver:
alias cdmpcsolver='cd <path_to_repo>/src/catkin_ws/src/mpc/mpc_solver' alias mpc_generate_solver_hmpc='cdmpcsolver; ./setup_script.sh -c tmpc_settings.py -c pmpc_settings.py -s hovergames -f ARM' alias mpc_generate_solver_smpc='cdmpcsolver; ./setup_script.sh -c smpc_settings.py -s hovergames -f ARM'
💡 You can play around with the sampling times and predictions horizons of the PMPC and TMPC to improve performance. See pmpc_settings.py and tmpc_settings.py for more details.
After generating the solver and solver interface, you can build the runtime C++ code. Generally, this is automatically built when using a catkin workspace and running catkin build <package_name>
. Before building, make sure to take care of the following:
- Install all dependencies of your code.
- The platform interface should be selected in CMakeLists.txt by either setting the
PLATFORM
variable tohovergames_simplesim
or tohovergames_px4
. Thehovergames_simplesim
interface is used in simple simulations, while thehovergames_px4
interface is used in Gazebo simulations and lab experiments. - When running the SMPC solver on the onboard computer, take care that a few lines of code need to be changed in reconfigure_callback.h. More information is provided in the file itself.
For example, to build the code for HMPC on the hovergames platform, run the following command:
catkin build mpc_hovergames
To run the code using ROS, make sure to include a proper launch file in the launch directory of the package of your system. For example, to the run the HMPC solver on the hovergames platform, we use main.launch and correspondingly use the following command:
roslaunch mpc_hovergames main.launch
and provide the launch file with the required arguments for running PMPC, TMPC, SMPC, or the ROS environment required to run the MPC schemes.
Interested in using this MPC package for your setup? This is relatively straightforward by following these steps:
- Define the solver generation settings in the mpc_solver package:
- Add a new directory with your system name to the systems directory.
- Add a settings file to the new system directory. This file should contain the solver settings, such as the model, objective function, constraints, and solver settings.
- Implement the system model in dynamics.py, the system constraints in systems.py, the objective function in objective.py, and the inequality constraints in inequality.py.
- When defining a new type of objective or inequality constraint, make sure to add it as a new control module to control_modules.py. These control modules are used to bridge between offline Python solver generation and online C++ code since they usually require a specific number of parameters to be set in the runtime code.
- Implement the offline computations in offline_computations.py. For the offline computations you might want to leverage the mpc-sdp package.
- See hovergames system for an example.
- Define the system-specific runtime code in the mpc_systems package:
- Add a new directory with your system name to the mpc_systems package.
- Implement the system-specific code in the new system directory. This code should contain the ROS interface, the system-specific runtime code, and the system-specific launch files.
- See the mpc_hovergames package for an example.
- Define the runtime code corresponding to the new control modules to the mpc_modules package in a similar way as the currently implemented control modules are defined. Do not forget to include the new control modules in the corresponding CMakeLists.txt file.