1 package org.opentrafficsim.road.gtu.lane.perception.headway;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.opentrafficsim.core.gtu.GTUException;
5 import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
6 import org.opentrafficsim.core.network.NetworkException;
7 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
8 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
9 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
10 import org.opentrafficsim.road.network.speed.SpeedLimitTypes;
11
12 /**
13 * Container for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs
14 * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to
15 * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived)
16 * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br>
17 * This particular version returns behavioral information about the observed GTU objects based on their real state.<br>
18 * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether
19 * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or
20 * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is
21 * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line
22 * when projected from lane 1 to lane 2 is the same as the projection from lane 2 to lane 1. The same holds for shapes with
23 * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU
24 * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane
25 * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional
26 * positions. See examples in <a href=
27 * "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>.
28 * <p>
29 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
30 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
31 * </p>
32 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
33 * initial version May 27, 2016 <br>
34 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
35 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
36 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
37 */
38 public class HeadwayGTUReal extends AbstractHeadwayGTU
39 {
40 /** */
41 private static final long serialVersionUID = 20160527L;
42
43 /** stored car following model of the observed GTU. */
44 private final CarFollowingModel carFollowingModel;
45
46 /** stored behavioral characteristics of the observed GTU. */
47 private final BehavioralCharacteristics behavioralCharacteristics;
48
49 /** stored speed limit info of the observed GTU. */
50 private final SpeedLimitInfo speedLimitInfo;
51
52 /**
53 * Construct a new Headway information object, for a GTU ahead of us or behind us.
54 * @param gtu the observed GTU, can not be null.
55 * @param distance the distance to the other object; if this constructor is used, distance cannot be null.
56 * @param gtuStatus the observable characteristics of the GTU.
57 * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
58 */
59 public HeadwayGTUReal(final LaneBasedGTU gtu, final Length distance, final GTUStatus... gtuStatus) throws GTUException
60 {
61 super(gtu.getId(), gtu.getGTUType(), distance, true, gtu.getLength(), gtu.getSpeed(), gtu.getAcceleration(), gtuStatus);
62 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
63 this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
64 this.speedLimitInfo = getSpeedLimitInfo(gtu);
65 }
66
67 /**
68 * Construct a new Headway information object, for a GTU parallel with us.
69 * @param gtu the observed GTU, can not be null.
70 * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
71 * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
72 * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
73 * @throws GTUException when id is null, or parameters are inconsistent
74 */
75 public HeadwayGTUReal(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap, final Length overlapRear)
76 throws GTUException
77 {
78 super(gtu.getId(), gtu.getGTUType(), overlapFront, overlap, overlapRear, true, gtu.getLength(), gtu.getSpeed(), gtu
79 .getAcceleration());
80 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
81 this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
82 this.speedLimitInfo = getSpeedLimitInfo(gtu);
83 }
84
85 /**
86 * Creates speed limit prospect for given GTU.
87 * @param gtu gtu to the the speed limit prospect for
88 * @return speed limit prospect for given GTU
89 */
90 // TODO this is a simple fix, and getReferenceLane()
91 private SpeedLimitInfo getSpeedLimitInfo(final LaneBasedGTU gtu)
92 {
93 SpeedLimitInfo sli = new SpeedLimitInfo();
94 sli.addSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED, gtu.getMaximumSpeed());
95 try
96 {
97 sli.addSpeedInfo(SpeedLimitTypes.FIXED_SIGN,
98 gtu.getReferencePosition().getLane().getSpeedLimit(gtu.getGTUType()));
99 }
100 catch (NetworkException | GTUException exception)
101 {
102 throw new RuntimeException("Could not obtain speed limit from lane for perception.", exception);
103 }
104 return sli;
105 }
106
107 /** {@inheritDoc} */
108 @Override
109 public final CarFollowingModel getCarFollowingModel()
110 {
111 return this.carFollowingModel;
112 }
113
114 /** {@inheritDoc} */
115 @Override
116 public final BehavioralCharacteristics getBehavioralCharacteristics()
117 {
118 return this.behavioralCharacteristics;
119 }
120
121 /** {@inheritDoc} */
122 @Override
123 public final SpeedLimitInfo getSpeedLimitInfo()
124 {
125 return this.speedLimitInfo;
126 }
127
128 }