-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.m
More file actions
41 lines (33 loc) · 1.33 KB
/
Driver.m
File metadata and controls
41 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
classdef Driver
%DRIVER Summary of this class goes here
% Detailed explanation goes here
properties
end
methods
function action = Agent(obj, car)
actSpeed = car.velocity;
desiredSpeed = car.targetVelocity;
distanceToCarInFront = VehicleMgr.DistanceAhead(car); %miles
if distanceToCarInFront < 3 * actSpeed / 3600 % 3 second rule (x mph for 3 seconds)
if VehicleMgr.IsLeftClear(car)
car.MoveLeft();
else
if VehicleMgr.IsRightClear(car)
car.MoveRight();
else
car.SlowDown(1.0); %0 to 100% of deceleration rate
end
end
else
if abs( (actSpeed-desiredSpeed)/desiredSpeed) < 0.05 %within 5 percent of desired speed
%everything is copacetic
action = 0;
else
%increase speed is the default behavior of the vehicle
% action = 1;
% car.SpeedUp(1.0); %0 to 100% of deceleration rate
end
end
end
end
end