The provided code is a Python script that creates a graphical user interface (GUI) using tkinter
for simulating a robot's movement based on Model Predictive Control (MPC). The robot follows a series of user-defined waypoints. The GUI allows users to input parameters and waypoints, then visualize the robot's path using Matplotlib.
anim_global
: Stores the animation object.canvas_widget
: Stores the Matplotlib canvas widget.waypoints
: List of waypoints, where each waypoint is a tuple of (x, y, orientation).
This function computes the control inputs (velocity v
and angular velocity omega
) using MPC.
- Objective Function: Minimizes the cost of deviating from the next waypoint.
- Constraints: No specific constraints in this implementation.
- Optimization: Uses
scipy.optimize.minimize
to find the optimal control inputs.
This function sets up the simulation and visualization of the robot's movement.
- Initial Setup: Converts initial orientation to radians and initializes position and orientation.
- Matplotlib Plot: Sets up the plot and draws the static planned path.
- Update Function: Updates the robot's position and orientation based on the control inputs and plots the new position.
Adds a waypoint to the list and updates the GUI listbox with the new waypoint.
Runs the simulation by calling differential_drive_simulation
and displaying the animation in the GUI.
- Checks if the simulation is already running.
- Validates user inputs.
- Starts the animation if inputs are valid.
Stops the animation and closes the GUI window.
The GUI is created using tkinter
:
- Input Frame: Contains entries for the robot's body radius, initial position, and orientation.
- Waypoint Frame: Contains entries for adding waypoints (x, y, orientation) and a listbox to display the added waypoints.
- Plot Frame: Area where the Matplotlib plot is displayed.
- Buttons: Buttons to add waypoints, run the simulation, and quit the program.
When the script is run, the user can:
- Enter the body radius, initial position, and orientation of the robot.
- Add waypoints to the list.
- Click "Run" to start the simulation.
- Visualize the robot's movement and its path towards the waypoints.
- Click "Quit" to exit the program.
- J. B. Rawlings and D. Q. Mayne, “Model Predictive Control: Theory and Design”, Madison, WI: Nob Hill Publishing, 2009.
- F. Borrelli, A. Bemporad, and M. Morari, “Predictive Control for Linear and Hybrid Systems”, Cambridge, UK: Cambridge University Press, 2017.
- D. Q. Mayne, J. B. Rawlings, C. V. Rao, and P. O. M. Scokaert, "Constrained model predictive control: Stability and optimality,“ vol. 36, no. 6, pp. 789-814, Jun. 2000, doi: 10.1016/S0005-1098(99)00214-9.
- Mathlab's Understanding MPC https://youtube.com/playlist?list=PLn8PRpmsu08ozoeoXgxPSBKLyd4YEHww8&si=w7yuGim3kMNhnvUn