track-凯发k8网页登录
this example shows how to fuse tracks from two vehicles to provide a more comprehensive estimate of the environment than can be seen by each vehicle. the example demonstrates the use of a track-level fuser and the object track data format. in this example, you use the driving scenario and vision detection generator from automated driving toolbox™, the radar data generator from the radar toolbox™, and the tracking and track fusion models from sensor fusion and tracking toolbox™.
motivation
automotive safety applications rely on the fusion of data from different sensor systems mounted on the vehicle. individual vehicles fuse sensor detections either by using a centralized tracker or by taking a more decentralized approach and fusing tracks produced by individual sensors. in addition to intravehicle data fusion, the fusion of data from multiple vehicles provides added benefits, which include better coverage, situational awareness, and safety . this intervehicle sensor fusion approach takes advantage of the variety of sensors and provides better coverage to each vehicle, because it uses data updated by sensors on other vehicles in the area. governments and vehicle manufacturers have long recognized the need to share information between vehicles in order to increase automotive safety. for example, v2x protocols and cellular communication links are being developed.
while sensor fusion across multiple vehicles is beneficial, most vehicles are required to meet certain safety requirements even if only internal sensors are available. therefore, the vehicle is likely to be equipped with a tracker, a track fuser, or both. these tracking algorithms provide situational awareness at the single vehicle level. as a result, the assumption made in this example is that vehicles share situational awareness by broadcasting tracks and performing track-to-track fusion.
this example demonstrates the benefit of fusing tracks from two vehicles to enhance situational awareness and safety. this example does not simulate the communications systems. instead, the example assumes that a communications system provides the bandwidth required to transmit tracks between the two vehicles.
track-to-track architecture
the following block diagram depicts the main functions in the two vehicles, where:
vehicle 1 has two sensors, each providing detections to a local vehicle tracker. the tracker uses the detections from the local sensors to track objects and outputs these local tracks to the vehicle track fuser.
vehicle 2 has a single sensor, which is a tracking radar. the tracking radar outputs tracks and serves as the local tracker for vehicle 2. the tracks from the tracking radar are inputs to the vehicle track fuser on vehicle 2.
the track fuser on each vehicle fuses the local vehicle tracks with the tracks received from the other vehicle's track fuser. after each update, the track fuser on each vehicle broadcasts its fused tracks, which feed into the next update of the track fuser on the other vehicle.
in this example, you use a (sensor fusion and tracking toolbox) object to define the vehicle 1 tracker.
% create the tracker for vehicle 1 v1tracker = trackerjpda('trackerindex',1, 'deletionthreshold', [4 4], 'assignmentthreshold', [100 inf]); % vehicle 1 tracker posselector = [1 0 0 0 0 0; 0 0 1 0 0 0];
in this architecture, the fused tracks from one vehicle update the fused tracks on the other vehicle. these fused tracks are then broadcast back to the first vehicle. to avoid rumor propagation, be careful how tracks from another vehicle update the track fuser.
consider the following rumor propagation example: at some update step, vehicle 1 tracks an object using its internal sensors. vehicle 1 then fuses the object track and transmits it to vehicle 2, which now fuses the track with its own tracks and becomes aware of the object. up to this point, this is exactly the goal of track-to-track fusion: to enhance the situational awareness of vehicle 2 with information from vehicle 1. since vehicle 2 now knows about the object, it starts broadcasting the track as well, perhaps for the benefit of another vehicle (not shown in the example).
however, vehicle 1 now receives track information from vehicle 2 about the object that only vehicle 1 actually tracks. so, the track fuser on vehicle 1 must be aware that the tracks of this object it gets from vehicle 2 do not actually contain any new information updated by an independent source. to make the distinction between tracks that contain new information and tracks that just repeat information, you must define vehicle 2 as an external source to the track fuser on vehicle 1. similarly, vehicle 1 must be defined as an external source to the track fuser on vehicle 2. furthermore, you need to define only tracks that are updated by a track fuser based on information from an internal source as self-reported. by doing so, the track fuser in each vehicle ignores updates from tracks that bounce back and forth between the track fusers without any new information in them.
the local tracker of each vehicle tracks objects relative to the vehicle reference frame, called the ego frame. the track-to-track fusion is done at the scenario frame, which is the global-level frame. the helper egotoscenario
function transforms tracks from the ego frame to the scenario frame. similarly, the function scenariotoego
transforms tracks from the scenario frame to any of the ego frames. both transformations rely on the stateparameters
property of the (sensor fusion and tracking toolbox) objects. when the trackfuser
object calculates the distance of a central track in the scenario frame to a local track in any frame, it uses the stateparameters
of the local track to perform the coordinate transformation.
to achieve the previously described trackfuser
definitions, define the following sources as a (sensor fusion and tracking toolbox) object.
% define sources for each vehicle v1trackerconfiguration = fusersourceconfiguration('sourceindex',1,'isinternalsource',true, ... % v1tracker is internal to v1fuser "centraltolocaltransformfcn", @scenariotoego, 'localtocentraltransformfcn', @egotoscenario); % coordinate transformation v2fuserconfiguration = fusersourceconfiguration('sourceindex',4,'isinternalsource',false); % v2fuser is external to v2fuser v1sources = {v1trackerconfiguration; v2fuserconfiguration}; v2trackerconfiguration = fusersourceconfiguration('sourceindex',2,'isinternalsource',true, ... % v2tracker is internal to v2fuser "centraltolocaltransformfcn", @scenariotoego, 'localtocentraltransformfcn', @egotoscenario); % coordinate transformation v1fuserconfiguration = fusersourceconfiguration('sourceindex',3,'isinternalsource',false); % v1fuser is external to v2fuser v2sources = {v2trackerconfiguration; v1fuserconfiguration};
you can now define each vehicle track fuser as a (sensor fusion and tracking toolbox) object.
stateparams = struct('frame','rectangular','position',[0 0 0],'velocity',[0 0 0]); v1fuser = trackfuser('fuserindex',3,... 'assignmentthreshold', [100 inf], ... 'maxnumsources',2,'sourceconfigurations',v1sources,... 'statefusion','intersection','deletionthreshold',[3 3],... 'stateparameters',stateparams); v2fuser = trackfuser('fuserindex',4,... 'assignmentthreshold', [100 inf], ... 'maxnumsources',2,'sourceconfigurations',v2sources,'statefusion',... 'intersection','deletionthreshold',[3 3],... 'stateparameters',stateparams); % initialize the following variables fusedtracks1 = objecttrack.empty(0,1); fusedtracks2 = objecttrack.empty(0,1); wasfuser1updated = false; wasfuser2updated = false;
define scenario
the following scenario shows two vehicles driving down a street. vehicle 1 is the lead vehicle and is equipped with two forward-looking sensors: a short-range radar sensor and a vision sensor. vehicle 2, driving 10 meters behind vehicle 1, is equipped with a long-range radar. the right side of the street contains parked vehicles. a pedestrian stands between the vehicles. this pedestrian is shown as a dot at about x = 60 meters.
due to the short distance between vehicle 2 and vehicle 1, most of the vehicle 2 radar sensor coverage is occluded by vehicle 1. as a result, most of the tracks that the track fuser on vehicle 2 maintains are first initialized by tracks broadcast from vehicle 1.
% create the drivingscenario object and the two vehicles [scenario, vehicle1, vehicle2] = createdrivingscenario; % create all the sensors [sensors, numsensors, attachedvehicle] = createsensors(scenario); % create display [f,plotters] = createv2vdisplay(scenario, sensors, attachedvehicle);
the following chase plot is seen from the point of view of the second vehicle. an arrow indicates the position of the pedestrian that is almost entirely occluded by the parked vehicles and the first vehicle.
% define each vehicle as a combination of an actor, sensors, a tracker, and plotters v1=struct('actor',{vehicle1},'sensors',{sensors(attachedvehicle==1)},'tracker',{v1tracker},'detplotter',{plotters.veh1detplotter},'trkplotter',{plotters.veh1trkplotter}); v2=struct('actor',{vehicle2},'sensors',{sensors(attachedvehicle==2)},'tracker',{{}},'detplotter',{{}},'trkplotter',{plotters.veh2trkplotter}); % no detections or tracker on vehicle 2
run simulation
the following code runs the simulation.
running = true; % for repeatable results, set the random number seed s = rng; rng(2019) snaptimes = [0.5, 2.8, 4.4, 6.3, inf]; snaps = cell(numel(snaptimes,1)); i = 1; f.visible = 'on'; while running && ishghandle(f) time = scenario.simulationtime; % detect and track at the vehicle level [tracks1,wastracker1updated] = detectandtrack(v1,time,posselector); [tracks2,wastracker2updated] = detectandtrack(v2,time,posselector); % keep the tracks from the previous fuser update oldfusedtracks1 = fusedtracks1; oldfusedtracks2 = fusedtracks2; % update the fusers if wastracker1updated || wasfuser2updated trackstofuse1 = [tracks1;oldfusedtracks2]; if islocked(v1fuser) || ~isempty(trackstofuse1) [fusedtracks1,~,~,info1] = v1fuser(trackstofuse1,time); wasfuser1updated = true; pos = gettrackpositions(fusedtracks1,posselector); ids = string([fusedtracks1.trackid]'); plottrack(plotters.veh1fuseplotter,pos,ids); else wasfuser1updated = false; fusedtracks1 = objecttrack.empty(0,1); end else wasfuser1updated = false; fusedtracks1 = objecttrack.empty(0,1); end if wastracker2updated || wasfuser1updated trackstofuse2 = [tracks2;oldfusedtracks1]; if islocked(v2fuser) || ~isempty(trackstofuse2) [fusedtracks2,~,~,info2] = v2fuser(trackstofuse2,time); wasfuser2updated = true; pos = gettrackpositions(fusedtracks2,posselector); ids = string([fusedtracks2.trackid]'); plottrack(plotters.veh2fuseplotter,pos,ids); else wasfuser2updated = false; fusedtracks2 = objecttrack.empty(0,1); end else wasfuser2updated = false; fusedtracks2 = objecttrack.empty(0,1); end % update the display updatev2vdisplay(plotters, scenario, sensors, attachedvehicle) % advance the scenario one time step and exit the loop if the scenario is complete running = advance(scenario); % capture an image of the frame at specified times if time >= snaptimes(i) snaps{i} = takesnap(f); i = i 1; end end
the figure shows the scene and tracking results at the end of the scenario. subsequent sections of this example analyze the tracking results at key times.
analyze tracking at beginning of simulation
when the simulation begins, vehicle 1 detects the vehicles parked on the right side of the street. then, vehicle 1 tracker confirms the tracks associated with the parked vehicles. at this time, the only object detected and tracked by vehicle 2 tracker is vehicle 1, which is immediately in front of it. once the vehicle 1 track fuser confirms the tracks, it broadcasts them, and the vehicle 2 track fuser fuses them. as a result, vehicle 2 becomes aware of the parked vehicles before it can detect them on its own.
showsnap(snaps,1)
analyze tracking of pedestrian at side of street
as the simulation continues, vehicle 2 is able to detect and track the vehicles parked at the side as well and fuses them with the tracks coming from vehicle 1. vehicle 2 is able to detect and track the pedestrian about 4 seconds into the simulation, and vehicle 2 fuses the track associated with the pedestrian around 4.4 seconds into the simulation (see snapshot 2). however, it takes vehicle 2 about two seconds before it can detect and track the pedestrian by its own sensors (see snapshot 3). detecting a pedestrian in the street two seconds earlier can markedly improve safety.
showsnap(snaps,2)
showsnap(snaps,3)
avoiding rumor propagation
when the two vehicles communicate tracks to each other, there is a risk that they will continue communicating information about objects that they do not detect anymore just by repeating what the other vehicle communicated. this situation is called rumor propagation.
as the vehicles pass the objects, and these objects go out of their field of view, the fused tracks associated with these objects are dropped by both trackers (see snapshot 4). dropping the tracks demonstrates that the fused tracks broadcast back and forth between the two vehicles are not used to propagate rumors.
showsnap(snaps,4)
% 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 % return the random seed to its previous value rng(s)
summary
in this example, you saw how track-to-track fusion can enhance the situational awareness and increase the safety in automotive applications. you saw how to set up a trackfuser
to perform track-to-track fusion and how to define sources as either internal or external by using the fusersourceconfiguration
object. by doing so, you avoid rumor propagation and keep only the fused tracks that are really observed by each vehicle to be maintained.
references
[1] duraisamy, b., t. schwarz, and c. wohler. “track level fusion algorithms for automotive safety applications.” in 2013 international conference on signal processing , image processing & pattern recognition, 179–84, 2013. .
supporting functions
createdrivingscenario
create a driving scenario defined in the driving scenario designer app.
function [scenario, egovehicle, secondvehicle] = createdrivingscenario % construct a drivingscenario object scenario = drivingscenario('sampletime', 0.1); % add all road segments roadcenters = [50.8 0.5 0; 253.4 1.5 0]; roadwidth = 12; road(scenario, roadcenters, roadwidth); roadcenters = [100.7 -100.6 0; 100.7 103.7 0]; road(scenario, roadcenters); roadcenters = [201.1 -99.2 0; 199.7 99.5 0]; road(scenario, roadcenters); % add the ego vehicle egovehicle = vehicle(scenario, 'classid', 1, 'position', [65.1 -0.9 0], 'plotcolor', [0 0.7410 0.4470]); waypoints = [71 -0.5 0; 148.7 -0.5 0]; speed = 12; trajectory(egovehicle, waypoints, speed); % add the second vehicle secondvehicle = vehicle(scenario, 'classid', 1, 'position', [55.1 -0.9 0]); waypoints = [61 -0.5 0; 138.7 -0.5 0]; speed = 12; trajectory(secondvehicle, waypoints, speed); % add the parked cars vehicle(scenario, 'classid', 1, 'position', [111.0 -3.6 0]); vehicle(scenario, 'classid', 1, 'position', [140.6 -3.6 0]); vehicle(scenario, 'classid', 1, 'position', [182.6 -3.6 0]); vehicle(scenario, 'classid', 1, 'position', [211.3 -4.1 0]); % add pedestrian actor(scenario, 'classid', 4, 'length', 0.5, 'width', 0.5, ... 'height', 1.7, 'position', [130.3 -2.7 0], 'rcspattern', [-8 -8;-8 -8]); % add parked truck vehicle(scenario, 'classid', 2, 'length', 8.2, 'width', 2.5, ... 'height', 3.5, 'position', [117.5 -3.5 0]); end
createsensors
create the sensors used in the scenario and list their attachments to vehicles.
function [sensors, numsensors, attachedvehicle] = createsensors(scenario) % createsensors returns all sensor objects to generate detections % units used in createsensors and createdrivingscenario % distance/position - meters % speed - meters/second % angles - degrees % rcs pattern - dbsm % assign into each sensor the physical and radar profiles for all actors profiles = actorprofiles(scenario); % vehicle 1 radar reports clustered detections sensors{1} = radardatagenerator('no scanning', 'sensorindex', 1, 'updaterate', 10, ... 'mountinglocation', [3.7 0 0.2], 'rangelimits', [0 50], 'fieldofview', [60 5], ... 'rangeresolution', 2.5, 'azimuthresolution', 4, ... 'profiles', profiles, 'hasocclusion', true, 'hasfalsealarms', false, ... 'targetreportformat', 'clustered detections'); % vehicle 2 radar reports tracks sensors{2} = radardatagenerator('no scanning', 'sensorindex', 2, 'updaterate', 10, ... 'mountinglocation', [3.7 0 0.2], 'rangelimits', [0 120], 'fieldofview', [30 5], ... 'rangeresolution', 2.5, 'azimuthresolution', 4, ... 'profiles', profiles, 'hasocclusion', true, 'hasfalsealarms', false, ... 'targetreportformat', 'tracks', 'deletionthreshold', [3 3]); % vehicle 1 vision sensor reports detections sensors{3} = visiondetectiongenerator('sensorindex', 3, ... 'maxrange', 100, 'sensorlocation', [1.9 0], 'detectoroutput', 'objects only', ... 'actorprofiles', profiles); attachedvehicle = [1;2;1]; numsensors = numel(sensors); end
scenariotoego
perform coordinate transformation from scenario to ego coordinates.
trackinscenario
has stateparameters
defined to transform it from scenario coordinates to ego coordinates.
the state uses the constant velocity model [x;vx;y;vy;z;vz].
function trackinego = scenariotoego(trackinscenario) egoposinscenario = trackinscenario.stateparameters.originposition; egovelinscenario = trackinscenario.stateparameters.originvelocity; stateinscenario = trackinscenario.state; stateshift = [egoposinscenario(1);egovelinscenario(1);egoposinscenario(2);egovelinscenario(2);egoposinscenario(3);egovelinscenario(3)]; stateinego = stateinscenario - stateshift; trackinego = objecttrack('updatetime',trackinscenario.updatetime,'state',stateinego,'statecovariance',trackinscenario.statecovariance,'stateparameters',trackinscenario.stateparameters); end
egotoscenario
perform coordinate transformation from ego to scenario coordinates.
trackinego
has stateparameters
defined to transform it from ego coordinates to scenario coordinates.
the state uses the constant velocity model [x;vx;y;vy;z;vz].
function trackinscenario = egotoscenario(trackinego) egoposinscenario = trackinego.stateparameters.originposition; egovelinscenario = trackinego.stateparameters.originvelocity; stateinscenario = trackinego.state; stateshift = [egoposinscenario(1);egovelinscenario(1);egoposinscenario(2);egovelinscenario(2);egoposinscenario(3);egovelinscenario(3)]; stateinego = stateinscenario stateshift; trackinscenario = objecttrack('updatetime',trackinego.updatetime,'state',stateinego,'statecovariance',trackinego.statecovariance,'stateparameters',trackinego.stateparameters); end
detectandtrack
this function is used for collecting all the detections from the sensors in one vehicle and updating the tracker with them.
the agent is a structure that contains the actor information and the sensors, tracker, and plotter to plot detections and vehicle tracks.
function [tracks,wastrackerupdated] = detectandtrack(agent,time,posselector) % create detections from the vehicle poses = targetposes(agent.actor); [detections,isvalid] = vehicledetections(agent.actor.position,agent.sensors,poses,time,agent.detplotter); % update the tracker to get tracks from sensors that reported detections if isvalid agent.tracker.stateparameters = struct(... 'frame','rectangular', ... 'originposition', agent.actor.position, ... 'originvelocity', agent.actor.velocity); tracks = agent.tracker(detections,time); tracksinscenario = tracks; for i = 1:numel(tracks) tracksinscenario(i) = egotoscenario(tracks(i)); end pos = gettrackpositions(tracksinscenario,posselector); plottrack(agent.trkplotter,pos) wastrackerupdated = true; else tracks = objecttrack.empty(0,1); wastrackerupdated = false; end % get additional tracks from tracking sensors [sensortracks,wassensortrackerupdated] = vehicletracks(agent.actor,agent.sensors,poses,time,agent.trkplotter); tracks = vertcat(tracks,sensortracks); wastrackerupdated = wastrackerupdated || wassensortrackerupdated; end
vehicledetections
collect the detections from all the sensors attached to this vehicle that return detections.
function [objectdetections,isvalid] = vehicledetections(position, sensors, poses, time, plotter) numsensors = numel(sensors); objectdetections = {}; isvalidtime = false(1, numsensors); % generate detections for each sensor for sensorindex = 1:numsensors sensor = sensors{sensorindex}; if isa(sensor, 'visiondetectiongenerator') || ~strcmpi(sensor.targetreportformat,'tracks') [objectdets, ~, sensorconfig] = sensor(poses, time); if islogical(sensorconfig) isvalidtime(sensorindex) = sensorconfig; else isvalidtime(sensorindex) = sensorconfig.isvalidtime; end objectdets = cellfun(@(d) setatt(d), objectdets, 'uniformoutput', false); numobjects = numel(objectdets); objectdetections = [objectdetections; objectdets(1:numobjects)]; %#okend end isvalid = any(isvalidtime); % plot detections if numel(objectdetections)>0 detpos = cellfun(@(d)d.measurement(1:2), objectdetections, 'uniformoutput', false); detpos = cell2mat(detpos')' position(1:2); plotdetection(plotter, detpos); end end function d = setatt(d) % set the attributes to be a structure d.objectattributes = struct; % keep only the position measurement and remove velocity if numel(d.measurement)==6 d.measurement = d.measurement(1:3); d.measurementnoise = d.measurementnoise(1:3,1:3); d.measurementparameters{1}.hasvelocity = false; end end
vehicletracks
collect all the tracks from sensors that report tracks on the vehicle.
function [tracks,wastrackerupdated] = vehicletracks(actor, sensors, poses, time, plotter) % create detections from the vehicle numsensors = numel(sensors); tracks = objecttrack.empty; isvalidtime = false(1, numsensors); % generate detections for each sensor for sensorindex = 1:numsensors sensor = sensors{sensorindex}; if isa(sensor, 'radardatagenerator') && strcmpi(sensor.targetreportformat,'tracks') [sensortracks, ~, sensorconfig] = sensor(poses, time); if islogical(sensorconfig) isvalidtime(sensorindex) = sensorconfig; else isvalidtime(sensorindex) = sensorconfig.isvalidtime; end numobjects = numel(sensortracks); tracks = [tracks; sensortracks(1:numobjects)]; %#okend end wastrackerupdated = any(isvalidtime); if ~wastrackerupdated % no vehicle tracking sensor udpated return end % add vehicle position and velocity to track state parameters for i = 1:numel(tracks) tracks(i).stateparameters.originposition = tracks(i).stateparameters.originposition actor.position'; tracks(i).stateparameters.originvelocity = tracks(i).stateparameters.originvelocity actor.velocity'; end % plot tracks if numel(tracks)>0 trpos = arrayfun(@(t)t.state([1,3]), tracks, 'uniformoutput', false); trpos = cell2mat(trpos')' actor.position(1:2); plottrack(plotter, trpos); end end