1 package org.opentrafficsim.road.gtu.lane.perception.mental;
2
3 import org.djunits.value.vdouble.scalar.Duration;
4 import org.opentrafficsim.base.parameters.Parameters;
5 import org.opentrafficsim.core.gtu.Try;
6 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
7 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
8 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
9 import org.opentrafficsim.road.gtu.lane.perception.categories.NeighborsPerception;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class TaskCarFollowing extends TaskHeadwayBased
23 {
24
25
26 @Override
27 protected Duration getHeadway(final LanePerception perception, final LaneBasedGTU gtu, final Parameters parameters)
28 {
29 NeighborsPerception neighbors = Try.assign(() -> perception.getPerceptionCategory(NeighborsPerception.class),
30 "NeighborsPerception not available.");
31 Try.execute(() -> neighbors.updateLeaders(RelativeLane.CURRENT), "Exception while updating adjacent leaders.");
32 return neighbors.getLeaders(RelativeLane.CURRENT).collect(new TaskHeadwayCollector(getSpeed()));
33 }
34
35 }