Matlab:实现驾驶交通场景(附完整源码)

Matlab:实现驾驶交通场景

function [scenario, egoVehicle] = drivingScenarioTrafficExample()
scenario = drivingScenario;

% Add all road segments
roadCenters = [0 50 0;
    150 50 0;
    300 75 0;
    310 75 0;
    400 0 0;
    300 -50 0;
    290 -50 0;
    0 -50 0;
    0 -50 0];
laneSpecification = lanespec(4);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Road');

% Add the ego vehicle
egoVehicle = vehicle(scenario, ...
    'ClassID', 1, ...
    'Position', [10.7 51.4 0], ...
    'Name', 'Car');

% Add the non-ego actors
car1 = vehicle(scenario, ...
    'ClassID', 1, ...
    'Position', [34.7 49.3 0], ...
    'Name', 'Car1');
waypoints = [34.7 49.3 0;
    60.1 48.2 0;
    84.2 47.9 0;
    119 49.3 0;
    148.1 51.4 0;
    189.6 58.7 0;
    230.6 68 0;
    272.6 74.7 0;
    301.4 77.5 0;
    316.7 76.8 0;
    332.4 75.2 0;
    348.9 72.2 0;
    366.2 65.1 0;
    379.6 55.6 0];
speed = [10;10;10;10;10;10;10;10;10;10;10;10;10;10];
trajectory(car1, waypoints, speed);

car2 = vehicle(scenario, ...
    'ClassID', 1, ...
    'Position', [17.6 46.7 0], ...
    'Name', 'Car2');
waypoints = [17.6 46.7 0;
    43.4 45.5 0;
    71.3 43.8 0;
    102.3 43.5 0;
    123.5 45.5 0;
    143.6 47.4 0;
    162.4 50 0;
    198.5 61 0;
    241.1 70.1 0;
    272.3 74.1 0;
    292 76.6 0;
    312.8 77.2 0;
    350.3 75.2 0;
    362.5 70.4 0;
    375.9 63.3 0;
    390.7 49.9 0;
    401.3 33 0];
speed = [9;9;9;9;9;9;9;9;9;9;9;9;9;9;9;9;9];
trajectory(car2, waypoints, speed);

car3 = vehicle(scenario, ...
    'ClassID', 1, ...
    'Position', [62.6 51.9 0], ...
    'Name', 'Car3');
waypoints = [62.6 51.9 0;
    87.4 51.3 0;
    117.7 52.2 0;
    147.6 55 0;
    174.9 59.7 0;
    203.3 65.8 0;
    265 69.7 0;
    288.3 73.1 0;
    314.5 73.1 0;
    334.9 70.8 0;
    360 59.9 0];
speed = [6;6;6;6;6;6;6;6;6;6;6];
trajectory(car3, waypoints, speed);

car4 = vehicle(scenario, ...
    'ClassID', 1, ...
    'Position', [101.7 41.1 0], ...
    'Name', 'Car4');
waypoints = [101.7 41.1 0;
    124.6 42 0;
    148.5 43.9 0;
    171.9 48.2 0;
    197.1 52.8 0;
    222.3 58.5 0;
    252.4 64.4 0;
    281.4 68.5 0;
    307.7 69.5 0;
    329.9 68.2 0;
    352.7 62.8 0];
speed = [7;7;7;7;7;7;7;7;7;7;7];
trajectory(car4, waypoints, speed);

car5 = vehicle(scenario, ...
    'ClassID', 1, ...
    'Position', [251.3 75.6 0], ...
    'Name', 'Car5');
waypoints = [251.3 75.6 0;
    255.7 76.7 0];
speed = [0.01;0.01];
trajectory(car5, waypoints, speed);


该博文为原创文章,未经博主同意不得转。
本文章博客地址:https://cplusplus.blog.csdn.net/article/details/129369528

你可能感兴趣的:(matlab)