This interactive simulation allows users to explore and compare the performance of a two-wheeled differential drive robot as it follows waypoints using a PID controller or a Model Predictive Controller (MPC). Experience real-time parameter adjustments, different path types, and detailed controller performance analysis.
It is recommended to use a virtual environment venv
for this project. After set up the environment, make sure cooresponding dependencies are installed properly.
pip install -r requirements.txt
The robot simulation defaults to using a PID controller. To add waypoints interactively, use the left mouse button, and to remove them, use the right mouse button. Start the simulation with your desired path type (circle
or square
) using the following command:
python main.py --type [square|circle]
Parameters for the controllers can be modified directly in the main file. This allows you to observe how different parameters affect robot behavior in real time, which helps in fine-tuning the control settings. Here, two parameters of PID controller have been applied, and the difference of behavior could be direcly observe through the simulation
The objective of the model predictive control is to minimize a cost function over a finite prediction horizon (window)
- state cost: to penalize deviation of robot's state from target
- input cost: to penalize large control input
- input difference cost: encourage smooth control inputs by penalizing large difference between consecutive control inputs
Thus, the cost function to minimize is:
where:
-
$t$ is taget -
$x_k$ and$u_k$ is the robot state and control input at step$k$ -
$Q, R$ and$R_d$ are positive definite matrices representing the weight matrices for state error, control input and control input difference cost respectively
The optimization is subject to input constraints, which are bounds on the control inputs
where
This project includes multiple maps designed for comparing controller performance. The maps offer various environments that highlight the strengths and weaknesses of the different control strategies. In the visual outputs, orange
represents the PID-controlled robot, while blue
indicates the MPC-controlled robot. To run an example using a specific map, execute the following command in your terminal, replacing map00.txt
with the desired map file name:
python example.py --map map/maps/map00.txt
After running the simulation, you can utilize the pipeline.extract_history()
method to analyze the trajectory performance and control errors. This function allows you to capture the robot's historical data, including position, velocity, and the errors encountered along the way.
x, y, error, period = pipeline.extract_history()
The historical data extracted from the simulation can be invaluable for analyzing various aspects of the robot's performance like trajectory performances, control error analysis and comparative performance.
Additional map files are available in the map
folder. These maps can be used for developing or testing alternative control strategies or configurations. You can also create custom maps to suit your requirements.