Sequential calling to SIMULINK from a time marching MATLAB simulation

3 views (last 30 days)
I have a compex MATLAB simulation model of an aircraft. The simulation uses MATLAB's ode45 solver to integrate the equations of motions in time. I'm trying to implement a flight control system (FCS) in SIMULINK which will continuosly provide the required control commands to the simulation during each integration step (using the "sim" command). The only way I could achieve this is: 1. Integrate the aircraft state equations during a short time interval (say dt). 2. Call the sim command using the current aircraft states (speed, angular rates, etc...) and the last step complete SimState of the FCS, and advance the control system by this short time interval (dt), in order to produce the next time step control command to the aircraft. 3. Save a complete SimState to the workspace, which will be used during the next sim command as initial conditions. 4. Advance simulation time by dt and return to step 1.
The problem is that this technique (saving the complete SimState at the end of each time step, and reloading it prior to the next step "sim" command) is both time consuming, and prevents the use of the 'rapid' acceleration mode.
My question is: How can I run SIMULINK continuously, such that my model's internal workspace is kept between successive calls, so that I would just have to update the input ports values in between calls to the model, and continue the simulation for the next time step ? (Obviously, I would need access to the model input and output ports inorder to provide continuos input to the model, and extract the output command).

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 4 Jun 2012
Instead of calling SIM manually, I think a better approach might be to use one of three MATLAB custom blocks that will let you run MATLAB code inside a block. You can use this block to perform your ode45 computations and output the results to be used as inputs for the rest of the model.
  2 Comments
Kobi Enciu
Kobi Enciu on 4 Jun 2012
Kaustubha, thank you very much for youre response. Do you feel this approach would be more efficient than what I am doing now? My MATLAB code is fairly complex and involves intial computations, intensive data reading and sorting, frequent 2d interpolations, and numerical solutions of nonlinear equations during each integration step.
Kaustubha Govind
Kaustubha Govind on 4 Jun 2012
Kobi: Yes, intuitively speaking, calling your MATLAB code in the loop seems like the cleanest and most efficient way to me. This will help you avoid all the SimState save and restores. Also, Simulink compiles the model every you run the SIM command. If you just do everything in one loop, compilation is only done once at the beginning.

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!