From 05c62b039d6a7fb0cfcf5a69c6985ad8383d23fe Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Thu, 22 Nov 2018 15:30:58 -0500 Subject: [PATCH] Update Workshop.m Added lanes, bicycle, opposing traffic and curvature of road in one direction --- Workshop.m | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 Workshop.m diff --git a/Workshop.m b/Workshop.m new file mode 100644 index 0000000..f79c990 --- /dev/null +++ b/Workshop.m @@ -0,0 +1,213 @@ +function [allData, scenario, sensors] = wORKSHOP() +%wORKSHOP - Returns sensor detections +% allData = wORKSHOP returns sensor detections in a structure +% with time for an internally defined scenario and sensor suite. +% +% [allData, scenario, sensors] = wORKSHOP optionally returns +% the drivingScenario and detection generator objects. + +% Generated by MATLAB(R) 9.5 and Automated Driving System Toolbox 1.3. +% Generated on: 19-Nov-2018 19:20:03 + +% Create the drivingScenario object and ego car +[scenario, egoCar] = createDrivingScenario; + +% Create all the sensors +[sensors, numSensors] = createSensors(scenario); + +allData = struct('Time', {}, 'ActorPoses', {}, 'ObjectDetections', {}, 'LaneDetections', {}); +running = true; +while running + + % Generate the target poses of all actors relative to the ego car + poses = targetPoses(egoCar); + time = scenario.SimulationTime; + + objectDetections = {}; + laneDetections = []; + isValidTime = false(1, numSensors); + + % Generate detections for each sensor + for sensorIndex = 1:numSensors + [objectDets, numObjects, isValidTime(sensorIndex)] = sensors{sensorIndex}(poses, time); + objectDetections = [objectDetections; objectDets(1:numObjects)]; %#ok + end + + % Aggregate all detections into a structure for later use + if any(isValidTime) + allData(end + 1) = struct( ... + 'Time', scenario.SimulationTime, ... + 'ActorPoses', actorPoses(scenario), ... + 'ObjectDetections', {objectDetections}, ... + 'LaneDetections', {laneDetections}); %#ok + end + + % Advance the scenario one time step and exit the loop if the scenario is complete + running = advance(scenario); +end + +% Restart the driving scenario to return the actors to their initial positions. +restart(scenario); + +% Release all the sensor objects so they can be used again. +for sensorIndex = 1:numSensors + release(sensors{sensorIndex}); +end + +%%%%%%%%%%%%%%%%%%%% +% Helper functions % +%%%%%%%%%%%%%%%%%%%% + +% Units used in createSensors and createDrivingScenario +% Distance/Position - meters +% Speed - meters/second +% Angles - degrees +% RCS Pattern - dBsm + +function [sensors, numSensors] = createSensors(scenario) +% createSensors Returns all sensor objects to generate detections + +% Assign into each sensor the physical and radar profiles for all actors +profiles = actorProfiles(scenario); +sensors{1} = visionDetectionGenerator('SensorIndex', 1, ... + 'SensorLocation', [1 0], ... + 'DetectorOutput', 'Objects only', ... + 'ActorProfiles', profiles); +sensors{2} = visionDetectionGenerator('SensorIndex', 2, ... + 'SensorLocation', [0 0], ... + 'Yaw', -180, ... + 'DetectorOutput', 'Objects only', ... + 'ActorProfiles', profiles); +sensors{3} = radarDetectionGenerator('SensorIndex', 3, ... + 'SensorLocation', [3.7 0], ... + 'MaxRange', 100, ... + 'ActorProfiles', profiles); +sensors{4} = radarDetectionGenerator('SensorIndex', 4, ... + 'SensorLocation', [-1 0], ... + 'Yaw', -180, ... + 'MaxRange', 100, ... + 'ActorProfiles', profiles); +sensors{5} = radarDetectionGenerator('SensorIndex', 5, ... + 'SensorLocation', [2.8 0.9], ... + 'Yaw', 90, ... + 'MaxRange', 50, ... + 'FieldOfView', [90 5], ... + 'ActorProfiles', profiles); +sensors{6} = radarDetectionGenerator('SensorIndex', 6, ... + 'SensorLocation', [2.8 -0.9], ... + 'Yaw', -90, ... + 'MaxRange', 50, ... + 'FieldOfView', [90 5], ... + 'ActorProfiles', profiles); +numSensors = 6; + +function [scenario, egoCar] = createDrivingScenario +% createDrivingScenario Returns the drivingScenario defined in the Designer + +% Construct a drivingScenario object. +scenario = drivingScenario; + +% Add all road segments +roadCenters = [80 -0.48 0; + 72.8 -0.48 0; + 0 -0.48 0]; +marking = [laneMarking('Solid', 'Color', [0.98 0.86 0.36]) + laneMarking('Dashed', 'Space', 0.5) + laneMarking('Dashed') + laneMarking('DoubleDashed', 'Color', [0.93 0.83 0.35]) + laneMarking('Dashed') + laneMarking('Solid')]; +laneSpecification = lanespec(5, 'Width', [1 3.6 3.6 3.6 3.6], 'Marking', marking); +road(scenario, roadCenters, 'Lanes', laneSpecification); + +% Add the ego car +egoCar = vehicle(scenario, ... + 'ClassID', 1, ... + 'Position', [25.9 -5.2 0]); +waypoints = [25.9 -5.2 0; + 36.6 -5.2 0; + 42.5 -5.2 0; + 49.1 -3.6 0; + 53 -2 0; + 56.6 -1.6 0; + 62.4 -1.6 0; + 66.1 -1.6 0; + 70 -1.6 0]; +speed = 18; +trajectory(egoCar, waypoints, speed); + +% Add the non-ego actors +cyclist = actor(scenario, ... + 'ClassID', 3, ... + 'Length', 1.7, ... + 'Width', 0.45, ... + 'Height', 1.7, ... + 'Position', [47 -7.6 0]); +waypoints = [47 -7.6 0; + 50.2 -7.6 0; + 52.2 -7.5 0; + 54.2 -6.1 0; + 57 -6.1 0; + 60.1 -7.3 0; + 64.4 -7.5 0]; +speed = 5; +trajectory(cyclist, waypoints, speed); + +actor(scenario, ... + 'ClassID', 5, ... + 'Length', 2.4, ... + 'Width', 0.76, ... + 'Height', 0.8, ... + 'Position', [55.7 -7.5 0]); + +car1 = vehicle(scenario, ... + 'ClassID', 1, ... + 'Position', [23.4 -1.4 0]); +waypoints = [23.4 -1.4 0; + 30 -1.4 0; + 40 -1.4 0; + 50 -1.4 0]; +speed = [18;14;12;14]; +trajectory(car1, waypoints, speed); + +truck = vehicle(scenario, ... + 'ClassID', 2, ... + 'Length', 8.2, ... + 'Width', 2.5, ... + 'Height', 3.5, ... + 'Position', [5 -1.4 0]); +waypoints = [5 -1.4 0; + 30 -1.4 0; + 33 -1.4 0]; +speed = [14;14;14]; +trajectory(truck, waypoints, speed); + +vehicle(scenario, ... + 'ClassID', 1, ... + 'Position', [37.1 6.4 0]); + +x = vehicle(scenario, ... + 'ClassID', 1, ... + 'Position', [66.6 2.4 0]); +waypoints = [66.1 2.4 0; + 59.5 2.4 0; + 29.5 2.4 0]; +speed = [18;22;18]; +trajectory(x, waypoints, speed); + +car2 = vehicle(scenario, ... + 'ClassID', 1, ... + 'Length', 4.4, ... + 'Position', [66.6 5.5 0]); +waypoints = [66.6 5.5 0; + 58.6 5.6 0; + 54 4.6 0; + 53 3.7 0; + 52 2.9 0; + 50 2.4 0; + 47 2.45 0; + 45 2.45 0; + 40 2.45 0]; +speed = [13;13;13;14;15;16;16;16;16]; +trajectory(car2, waypoints, speed); +