A DMC controller is implemented to control a linear system. The linear system is actually the linearized version of a nonlinear system, which as an example is considered to be a cart with a nonlinear spring, as that used for the EPFC controller in here.
A very simple explanation of DMC is included in this file.
The functions and scripts are as follows:
- simulate_linear_system and simulate_nonlinear_system simulate the systems by running the whole simulation, calling the MPC controller at each timestep to get the control input, applying the control input to the systems and moving the dynamics forward.
- The DMC logic is in this controller class.
- update_linear_state moves the linear system's dynamics forward one step. You can insert your linear system dynamics here.
- update_nonlinear_state moves the nonlinear system's dynamics forward one step. You can insert your nonlinear system dynamics here.
A considerably smaller step size (compared to control sample time) should be considered when simulating the nonlinear system itself. The substeps parameter can be tuned for that (keep it at least at 10 for a realistic simulation).
- plot_simulation_results, plot_comparison_results, plot_comparison_results_for_Q and plot_comparison_results_for_alpha are used for plotting the results.
- plot_static_gain is used for analyzing the nonlinear system's static gain at a given point
- plot_step_response is used to analyzing the linearized system's step response to obtain a reliable model horizon N
- main runs the simulation with the set parameters and saves the results. Parameters include:
Tssampling timetffinal simulation timeNmodel horizonu0_nonlinearthe nonlinear system's operating point control inputu0_linearinitial value of the linearized system's control inputbiasandspanused for generating the reference signalPprediction horizonMcontrol horizonalphafilter coefficient for filtering the desired referenceQweight of each future output sample (set not as a matrix, but as a vector. This will be later used to construct a diagonal Q)Rweight of each future input sample (set not as a matrix, but as a vector. This will be later used to construct a diagonal Q)N_modelnot actually used. Set it equal toNx0initial condition of the systemis_programmedif set to true, the reference will be considered programmed, meaning that the controller is aware of the future values of the reference signal.is_open_loopif set to true, the disturbanceDterm will not benoise_powerpower of white noise on the output (in dB)dist_ampthe amplitude of disturbance on the output. The disturbance is considered to be a pulse signal.dist_start_timethe time when the disturbance is applied
- compare_Ms compares different values of M.
- compare_Ns compares different values of N.
- compare_Ps compares different values of P.
- compare_Qs compares different values of Q.
- compare_Rs compares different values of R.
- compare_alphas compares different values of alpha.
- pulse pulse reference signal
- sinusoid sinusoid reference signal