The MPC operates on a discrete time frame defined by its sample time (T_s), prediction horizon (T_p), and control horizon (T_c). If the sample time of the MPC is significantly different from the simulation step size of the plant model, synchronization issues may arise.
Here are some steps to verify:
Check the Sample Time Compatibility:
- Ensure that the sample time of the MPC (T_s = 1 second) is appropriate for the dynamics of your microgrid model.
- The sample time of the microgrid model is 1e-6, which is much finer than the MPC's sample time. This means the MPC will update its control action every 1 second, while the microgrid model updates every 1e-6 seconds.
Data Exchange Between Models:
- Verify that the input/output data exchange between the MPC and the plant model is correctly configured. The MPC should receive updated measurements from the plant at each MPC sample time, and the plant should receive updated control actions from the MPC likewise.
Synchronize Simulation Times:
- Match the simulation times: The parent model runs for 0.48 seconds, while the MPC's results are shown for 10 seconds. Ensure the end time for both simulations is the same. You might need to adjust the stop time of the plant model to match the duration for which the MPC calculates the control actions.
Adjusting MPC Parameters:
- The prediction horizon (T_p) and the control horizon (T_c) should be chosen based on the dynamics of the plant model. If changing these parameters causes errors, it might be an indication that the MPC's design is not well-suited for the plant's dynamics.
Running Co-Simulation:
- If the MPC is running as a referenced model, you should ensure that the data exchange during the co-simulation is correctly set up. This might require the use of special blocks or configurations to manage the timing and data flow.
Test with Step Responses:
- Use a step input or a known disturbance to test the response of the overall system. Check if the response of the plant model corresponds to the control actions taken by the MPC. The control actions should be in sync with the plant's response to confirm that they are working together.
Review Model Settings:
- Open the configuration settings of both the MPC block/model and the plant model to ensure that the solver settings are appropriate for discrete control. It may be necessary to use a fixed-step solver with a step size that matches the MPC sample time, or to configure the solver to handle multiple rates if the plant model requires a finer resolution.
You should be able to determine if the MPC and the plant model are working synchronously. If there are still issues, you may need to delve deeper into the MPC's design and its integration with the plant to ensure that the timing and data exchange are correctly aligned.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.