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