1 package org.opentrafficsim.road.gtu.lane.perception; 2 3 import java.util.EnumSet; 4 5 import org.djunits.value.vdouble.scalar.Acceleration; 6 import org.djunits.value.vdouble.scalar.Length; 7 import org.djunits.value.vdouble.scalar.Speed; 8 import org.opentrafficsim.core.gtu.GTUException; 9 import org.opentrafficsim.core.gtu.GTUType; 10 11 /** 12 * Container for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs 13 * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to 14 * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived) 15 * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br> 16 * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether 17 * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or 18 * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is 19 * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line 20 * 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 21 * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU 22 * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane 23 * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional 24 * positions. See examples in <a href= 25 * "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>. 26 * <p> 27 * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 28 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 29 * <p> 30 * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $, 31 * initial version 11 feb. 2015 <br> 32 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 33 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 34 */ 35 public class HeadwayGTU extends AbstractHeadway 36 { 37 /** */ 38 private static final long serialVersionUID = 20160410L; 39 40 /** The perceived GTU Type, or null if unknown. */ 41 private final GTUType gtuType; 42 43 /** Observable characteristics of a GTU. */ 44 public enum GTUStatus 45 { 46 /** Braking lights are on when observing the headway. */ 47 BRAKING_LIGHTS, 48 49 /** Left turn indicator was on when observing the headway. */ 50 LEFT_TURNINDICATOR, 51 52 /** Right turn indicator was on when observing the headway. */ 53 RIGHT_TURNINDICATOR, 54 55 /** Alarm lights are on. */ 56 EMERGENCY_LIGHTS, 57 58 /** GTU was honking (car) or ringing a bell (cyclist) when observing the headway. */ 59 HONK; 60 } 61 62 /** The observable characteristics of the GTU. */ 63 private final EnumSet<GTUStatus> gtuStatus = EnumSet.noneOf(GTUStatus.class); 64 65 /** 66 * Construct a new Headway information object, for a moving GTU ahead of us or behind us. 67 * @param id the id of the GTU for comparison purposes, can not be null. 68 * @param gtuType the perceived GTU Type, or null if unknown. 69 * @param distance the distance to the other object; if this constructor is used, distance cannot be null. 70 * @param speed the (perceived) speed of the other object; can be null if unknown. 71 * @param acceleration the (perceived) acceleration of the other object; can be null if unknown. 72 * @param gtuStatus the observable characteristics of the GTU. 73 * @throws GTUException when id is null, objectType is null, or parameters are inconsistent 74 */ 75 public HeadwayGTU(final String id, final GTUType gtuType, final Length distance, final Speed speed, 76 final Acceleration acceleration, final GTUStatus... gtuStatus) throws GTUException 77 { 78 super(ObjectType.GTU, id, distance, speed, acceleration); 79 this.gtuType = gtuType; 80 for (GTUStatus status : gtuStatus) 81 { 82 this.gtuStatus.add(status); 83 } 84 } 85 86 /** 87 * Construct a new Headway information object, for a non-moving GTU ahead of us or behind us. 88 * @param id String; the id of the GTU for comparison purposes, can not be null. 89 * @param gtuType GTUType; the perceived GTU Type, or null if unknown. 90 * @param distance Length; the distance to the other GTU; if this constructor is used, distance cannot be null. 91 * @throws GTUException when id is null, or parameters are inconsistent 92 */ 93 public HeadwayGTU(final String id, final GTUType gtuType, final Length distance) throws GTUException 94 { 95 super(ObjectType.GTU, id, distance); 96 this.gtuType = gtuType; 97 } 98 99 /** 100 * Construct a new Headway information object, for a moving GTU parallel with us. 101 * @param id the id of the GTU for comparison purposes, can not be null. 102 * @param gtuType the perceived GTU Type, or null if unknown. 103 * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null. 104 * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null. 105 * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null. 106 * @param speed the (perceived) speed of the other GTU; can be null if unknown. 107 * @param acceleration the (perceived) acceleration of the other GTU; can be null if unknown. 108 * @throws GTUException when id is null, or parameters are inconsistent 109 */ 110 public HeadwayGTU(final String id, final GTUType gtuType, final Length overlapFront, final Length overlap, 111 final Length overlapRear, final Speed speed, final Acceleration acceleration) throws GTUException 112 { 113 super(ObjectType.GTU, id, overlapFront, overlap, overlapRear, speed, acceleration); 114 this.gtuType = gtuType; 115 } 116 117 /** 118 * Construct a new Headway information object, for a non-moving GTU parallel with us. 119 * @param id the id of the GTU for comparison purposes, can not be null. 120 * @param gtuType the perceived GTU Type, or null if unknown. 121 * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null. 122 * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null. 123 * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null. 124 * @throws GTUException when id is null, or parameters are inconsistent 125 */ 126 public HeadwayGTU(final String id, final GTUType gtuType, final Length overlapFront, final Length overlap, 127 final Length overlapRear) throws GTUException 128 { 129 super(ObjectType.GTU, id, overlapFront, overlap, overlapRear); 130 this.gtuType = gtuType; 131 } 132 133 /** 134 * @return gtuType 135 */ 136 public final GTUType getGtuType() 137 { 138 return this.gtuType; 139 } 140 141 /** @return were the braking lights on? */ 142 public final boolean isBrakingLightsOn() 143 { 144 return this.gtuStatus.contains(GTUStatus.BRAKING_LIGHTS); 145 } 146 147 /** @return was the left turn indicator on? */ 148 public final boolean isLeftTurnIndicatorOn() 149 { 150 return this.gtuStatus.contains(GTUStatus.LEFT_TURNINDICATOR); 151 } 152 153 /** @return was the right turn indicator on? */ 154 public final boolean isRightTurnIndicatorOn() 155 { 156 return this.gtuStatus.contains(GTUStatus.RIGHT_TURNINDICATOR); 157 } 158 159 /** @return were the emergency lights on? */ 160 public final boolean isEmergencyLightsOn() 161 { 162 return this.gtuStatus.contains(GTUStatus.EMERGENCY_LIGHTS); 163 } 164 165 /** @return was the vehicle honking or ringing its bell when being observed for the headway? */ 166 public final boolean isHonking() 167 { 168 return this.gtuStatus.contains(GTUStatus.HONK); 169 } 170 171 /** {@inheritDoc} */ 172 @Override 173 public final String toString() 174 { 175 return "HeadwayGTU [gtuType=" + this.gtuType + ", gtuStatus=" + this.gtuStatus + "]"; 176 } 177 178 }