Create Driving Scenario Programmatically

7 views (last 30 days)
Lukas
Lukas on 22 Jun 2020
Answered: Chengshi on 17 Nov 2023
Can anyone tell me how to properly hand over a scenario "from workspace" to the ScenarioReader block?
MATLAB Explanation says:
  1. Set Source of driving scenario to From workspace.
  2. Set MATLAB or model workspace variable name to the name of the drivingScenario variable in your workspace.
Therefore, I create a scenario:
Data is in the format: wayp_XX (11,3), v_XX(11,1) as I have eleven datapoints.
[allData, scenario, sensors] = ACCTestBenchScenario3(wayp_ego,v_ego,wayp_car1,v_car1);
and when looking at it using:
drivingScenarioDesigner(scenario,sensors);
the dataset seems to be acceptable.
However, when simulating the scenario using my model via:
sim('ACC_V1')
This error occurs:
MATLAB System block 'ACC_V1/Vehicle and Environment/Actors and Sensor Simulation/Scenario Reader' error occurred when invoking 'getOutputDataTypeImpl' method of 'driving.scenario.internal.ScenarioReader'. The error was
thrown from '
'C:\Program Files\MATLAB\R2020a\toolbox\shared\drivingscenario\+driving\+scenario\+internal\ScenarioReader.p' at line 0
Undefined variable "scenario". Specify a variable in the MATLAB or model workspace containing a valid drivingScenario object.
But when I don't automatically simulate this situation (directly "from workspace") but "from file" by storing the scenario to a .mat-file the Simulation works pretty nice.
Does anyone have an idea what might be the reason for the misconfiguration I obviously have?
Best regards,
Lukas
  2 Comments
Surya Talluri
Surya Talluri on 13 Oct 2020
Do you have the scenario variable in the workspace? If the error is still persisting even after having scenario variable in MATLAB workspace, try adding the scenario generation code to PreLoadFcn Callbacks.
Xiaoning.Wang
Xiaoning.Wang on 20 Dec 2021
do you have solved the question, Now I have same Error

Sign in to comment.

Answers (1)

Chengshi
Chengshi on 17 Nov 2023
Hi Lukas,
The error message you're seeing indicates that the ScenarioReader block in your Simulink model can't find the scenario variable in the MATLAB or model workspace.
Here are some reasons why this might happen:
  1. The variable is not in the workspace: Make sure that you have run the script or function that creates the scenario variable before running the Simulink model. You can check if the variable is in the workspace by typing the following code in the command window.
whos scenario
2. The variable is not in the correct workspace: If you're running a script or function that creates the scenario variable, make sure that it's in the base workspace, not a function workspace. Variables created inside a function are not accessible from the base workspace or from Simulink models. To put the scenario variable in the base workspace, you can use the assignin function:
assignin('base','scenario',scenario).
3. The variable is cleared before the model runs: If you have any clear commands in your script or function, make sure they're not clearing the scenario variable.
4. The variable is not a valid drivingScenario object: Make sure that the scenario variable is a valid drivingScenario object. You can check this by using the isa function:
isa(scenario,'drivingScenario')
If none of these suggestions solve the problem, could you please provide more information about how you're creating the scenario variable?
Best,
Chengshi

Categories

Find more on Event Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!