Switching velocity profiles with matlab function

4 views (last 30 days)
Hello everyone,
I am currently working on a project with Simulink. I am relatively fresh to the topic, hence I encounter a lot of problems.
Simplified description of the model goes: Model follows main sample velocity profile (ex. from lookup table) through entire simulation, after longitudinal controller, velocity signal goes to Matlab function block. Matlab function block should have the capabilitiy of recognizing the signal and based on some factors (not yet implemented) switch to the short snippets of different velocity profiles - 'events' (from workspace block). Use of a From Workspace block to import the data is forced by existing database that has to be used for this project.
Here is simplified version of the model to show the problem:
#1:
How to make 'events' time independet? Here you can see that function switches to 2 different velocity snippets (since reaching desired speed) while there are already finished (due to From Workspace block time based structure). Those snippets are 5 seconds long and goes like (10, 11, 12, 13, 14). I would like the snippets to start only when the function switches to them.
#2:
In the future, model should be able to decide which 'event' to use based on best fitting factors e.g. velocity. For example I would like the function to decide which 'event' to use through comparison of the basic profile velocity to 'events'. Is it possible to implement in Simulink/Matlab the functionality of a function reading into From Workspace and making decision from this level?
Hope I presented the problem clearly enough. I will be very greatful for any tips and anwsers.
Greetings and thank you in advance.

Answers (1)

Kartik
Kartik on 17 Apr 2023
Hi,
For #1: To make the 'events' time-independent, you can use the "Triggered Subsystem" block in Simulink. This block can be used to switch between different subsystems based on a trigger signal. You can use a condition in the trigger signal that switches between the different subsystems based on the factors that you want to consider.
Inside each subsystem, you can use the "From Workspace" block to read the data for the corresponding event. You can set the "Start Time" and "End Time" parameters of the "From Workspace" block to zero, and use the trigger signal to start and stop the subsystems at the desired times.
Here's a brief overview of the steps to implement this:
  1. Create a Triggered Subsystem block and connect it to the output of your longitudinal controller.
  2. Inside the Triggered Subsystem, create two subsystems (or more if needed) corresponding to your events.
  3. Inside each subsystem, add a "From Workspace" block to read the data for the corresponding event.
  4. Set the "Start Time" and "End Time" parameters of the "From Workspace" blocks to zero.
  5. Use a condition in the trigger signal to switch between the subsystems based on the factors that you want to consider.
For more information on how to use the Triggered Subsystem block in Simulink, you can refer to the following documentation:
For #2: To implement the functionality of a function reading into From Workspace and making decision from this level, you can use a MATLAB Function block in Simulink. Inside the MATLAB Function block, you can write the code to compare the basic profile velocity to 'events' and make a decision based on the comparison result.
You can use the "From Workspace" block to import the data for the basic profile velocity and 'events' into the MATLAB Function block. Then, you can write the code to compare the data and output the decision signal.
Here's a brief overview of the steps to implement this:
  1. Create a MATLAB Function block and connect it to the output of your longitudinal controller.
  2. Inside the MATLAB Function block, use the "From Workspace" block to import the data for the basic profile velocity and 'events'.
  3. Write the code to compare the data and output the decision signal.
  4. Connect the output of the MATLAB Function block to the Triggered Subsystem block that switches between the different subsystems based on the decision signal.
For more information on how to use the MATLAB Function block in Simulink, you can refer to the following documentation:
  1 Comment
Michal Pedzich
Michal Pedzich on 18 May 2023
Thank you for the anwser and sorry for my delayed response.
I am still working on this model. I changed the way I input the data into my function blocks (as constants) and got good results so far.
I have gone thorugh your anwser and it makes sense to me. However, I tried first part of your proposed soultion and cannot find the "Start Time" and "End Time" under properties of "From Workspace" block. I created a simple model with Triggered Subsystem the way you described it but still the final signal doesn't have the intented outcome.

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!