Create Driving Scenario Programmatically

조회 수: 4 (최근 30일)
Lukas
Lukas 2020년 6월 22일
답변: Chengshi 2023년 11월 17일
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
Surya Talluri
Surya Talluri 2020년 10월 13일
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 2021년 12월 20일
do you have solved the question, Now I have same Error

댓글을 달려면 로그인하십시오.

답변 (1개)

Chengshi
Chengshi 2023년 11월 17일
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

카테고리

Help CenterFile Exchange에서 Load Signal Data for Simulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by