How to use loop to generate driving scenarios from one scenario?

조회 수: 3 (최근 30일)
Muhammad Iqbal
Muhammad Iqbal 2022년 1월 12일
답변: Abhijeet 2022년 6월 27일
how to generate a number of driving scenarios from one scenario using loop:
for example, in my TMP.MAT scenario the initial ego speed is "10" like:
function [scenario, egoVehicle] = TMP()
% createDrivingScenario Returns the drivingScenario defined in the Designer
% Construct a drivingScenario object.
scenario = drivingScenario;
% Add all road segments
roadCenters = [0 0 0;
1000 0 0];
roadWidth = 10;
road(scenario, roadCenters, roadWidth);
% Add the ego vehicle
egoVehicle = vehicle(scenario, ...
'ClassID', 1, ...
'Position', [20 0 0]);
waypoints = [20 0 0;
150 0 0];
speed = 10;
speed=(speed*1000)/3600;
trajectory(egoVehicle, waypoints, speed);
% Add the non-ego actors
globalVehicleTarget = vehicle(scenario, ...
'ClassID', 1, ...
'Position', [36.7 0 0]);
waypoints = [36.7 0 0;
70 0 0;
118.23 0 0];
speed = [13.89;13.89;0];
trajectory(globalVehicleTarget, waypoints, speed);
In the next step, I want to generate more scenarios by increasing the ego speed to "n" keeping all other variables are same.
is there any way instead of increasing the speed one by one and exporting the scenario object like drivingscenariodesigner (scenario) to obtain the scenario.
How to load the orignal .MAT file and use loop to generate and save all the scenarios in one run ?
TIA,

답변 (1개)

Abhijeet
Abhijeet 2022년 6월 27일
I understand that you want to generate multiple driving scenarios using loops such that only speed is changing, and all the other properties remain the same.
Kindly follow these steps in order to resolve the issue:
  1. Create a driving scenario. You can either go with Driving Scenario Application and export the function for the same or you can go ahead creating driving scenario programmatically.
  2. To load the already created driving scenario, use open option available on the top panel and select the scenario file (.MAT).
  3. Pass a parameter “initialSpeed” which will hold the value of speed of an actor in the driving scenario.
  4. Initialize the speed parameter of the actor with initialSpeed.
  5. Using a for loop, iterate on the list of speed that you want to pass as an input in the driving scenario function.
  6. Store the returned driving scenario from the function in form of a list.
By following above steps, you will be able to generate a list of driving scenarios where the speed parameter of the actor will change, and the rest parameter remains the same.
You can also extend this idea over multiple parameters.
Kindly refer to this code for better understanding.
scenarioList=[]
for speed=(10:10:100)
scenarioList(end+1).scenario=TMP(speed);
end
function [scenario, egoVehicle] = TMP(initialSpeed)
% createDrivingScenario Returns the drivingScenario defined in the Designer
% Construct a drivingScenario object.
scenario = drivingScenario;
% Add all road segments
roadCenters = [0 0 0;
1000 0 0];
roadWidth = 10;
road(scenario, roadCenters, roadWidth);
% Add the ego vehicle
egoVehicle = vehicle(scenario, ...
'ClassID', 1, ...
'Position', [20 0 0]);
waypoints = [20 0 0;
150 0 0];
speed = initialSpeed;
speed=(speed*1000)/3600;
trajectory(egoVehicle, waypoints, speed);
% Add the non-ego actors
globalVehicleTarget = vehicle(scenario, ...
'ClassID', 1, ...
'Position', [36.7 0 0]);
waypoints = [36.7 0 0;
70 0 0;
118.23 0 0];
speed = [13.89;13.89;0];
trajectory(globalVehicleTarget, waypoints, speed);
end
For more information, kindly follow the documentation link below:

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by