1 package org.opentrafficsim.road.gtu.lane; 2 3 import java.util.Map; 4 5 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent; 6 7 import org.djunits.value.vdouble.scalar.Length; 8 import org.djunits.value.vdouble.scalar.Time; 9 import org.opentrafficsim.core.dsol.OTSSimTimeDouble; 10 import org.opentrafficsim.core.gtu.GTU; 11 import org.opentrafficsim.core.gtu.GTUDirectionality; 12 import org.opentrafficsim.core.gtu.GTUException; 13 import org.opentrafficsim.core.gtu.RelativePosition; 14 import org.opentrafficsim.road.gtu.lane.perception.LanePerceptionFull; 15 import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner; 16 import org.opentrafficsim.road.network.lane.Lane; 17 18 /** 19 * This interface defines a lane based GTU. 20 * <p> 21 * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 22 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 23 * <p> 24 * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $, 25 * initial version Oct 22, 2014 <br> 26 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 27 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 28 */ 29 public interface LaneBasedGTU extends GTU 30 { 31 /** {@inheritDoc} */ 32 @Override 33 // TODO change into LanePerception interface! 34 LanePerceptionFull getPerception(); 35 36 /** {@inheritDoc} */ 37 @Override 38 LaneBasedStrategicalPlanner getStrategicalPlanner(); 39 40 /** 41 * @return a safe copy of the lanes on which the GTU is registered. 42 */ 43 Map<Lane, GTUDirectionality> getLanes(); 44 45 /** 46 * insert GTU at a certain position. This can happen at setup (first initialization), and after a lane change of the GTU. 47 * The relative position that will be registered is the referencePosition (dx, dy, dz) = (0, 0, 0). Front and rear positions 48 * are relative towards this position. 49 * @param lane the lane to add to the list of lanes on which the GTU is registered. 50 * @param gtuDirection the direction of the GTU on the lane (which can be bidirectional). If the GTU has a positive 51 * velocity, it is moving in this direction. 52 * @param position the position on the lane. 53 * @throws GTUException when positioning the GTU on the lane causes a problem 54 */ 55 void enterLane(Lane lane, Length position, GTUDirectionality gtuDirection) throws GTUException; 56 57 /** 58 * Unregister the GTU from a lane. 59 * @param lane the lane to remove from the list of lanes on which the GTU is registered. 60 * @throws GTUException when leaveLane should not be called 61 */ 62 void leaveLane(Lane lane) throws GTUException; 63 64 /** 65 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 66 * vehicle is registered. <br> 67 * <b>Note:</b> If a GTU is registered in multiple parallel lanes, the lateralLaneChangeModel is used to determine the 68 * center line of the vehicle at this point in time. Otherwise, the average of the center positions of the lines will be 69 * taken. 70 * @param relativePosition the position on the vehicle relative to the reference point. 71 * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU. 72 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered. 73 */ 74 Map<Lane, Length> positions(RelativePosition relativePosition) throws GTUException; 75 76 /** 77 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 78 * vehicle is registered. 79 * @param relativePosition the position on the vehicle relative to the reference point. 80 * @param when the future time for which to calculate the positions. 81 * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of 82 * the GTU. 83 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered. 84 */ 85 Map<Lane, Length> positions(RelativePosition relativePosition, Time when) throws GTUException; 86 87 /** 88 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane at the current 89 * simulation time. <br> 90 * @param lane the position on this lane will be returned. 91 * @param relativePosition the position on the vehicle relative to the reference point. 92 * @return DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane. 93 * @throws GTUException when the vehicle is not on the given lane. 94 */ 95 Length position(Lane lane, RelativePosition relativePosition) throws GTUException; 96 97 /** 98 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane. 99 * @param lane the position on this lane will be returned. 100 * @param relativePosition the position on the vehicle relative to the reference point. 101 * @param when the future time for which to calculate the positions. 102 * @return DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane. 103 * @throws GTUException when the vehicle is not on the given lane. 104 */ 105 Length position(Lane lane, RelativePosition relativePosition, Time when) throws GTUException; 106 107 /** 108 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 109 * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are 110 * next to each other and we compare an 'inner' and 'outer' curve.<br> 111 * @param relativePosition the position on the vehicle relative to the reference point. 112 * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU. 113 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered. 114 */ 115 Map<Lane, Double> fractionalPositions(RelativePosition relativePosition) throws GTUException; 116 117 /** 118 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 119 * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are 120 * next to each other and we compare an 'inner' and 'outer' curve. 121 * @param relativePosition the position on the vehicle relative to the reference point. 122 * @param when the future time for which to calculate the positions. 123 * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of 124 * the GTU. 125 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered. 126 */ 127 Map<Lane, Double> fractionalPositions(RelativePosition relativePosition, Time when) throws GTUException; 128 129 /** 130 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction 131 * of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 132 * 'inner' and 'outer' curve. 133 * @param lane the position on this lane will be returned. 134 * @param relativePosition the position on the vehicle relative to the reference point. 135 * @param when the future time for which to calculate the positions. 136 * @return the fractional relative position on the lane at the given time. 137 * @throws GTUException when the vehicle is not on the given lane. 138 */ 139 double fractionalPosition(Lane lane, RelativePosition relativePosition, Time when) throws GTUException; 140 141 /** 142 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction 143 * of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 144 * 'inner' and 'outer' curve.<br> 145 * @param lane the position on this lane will be returned. 146 * @param relativePosition the position on the vehicle relative to the reference point. 147 * @return the fractional relative position on the lane at the given time. 148 * @throws GTUException when the vehicle is not on the given lane. 149 */ 150 double fractionalPosition(Lane lane, RelativePosition relativePosition) throws GTUException; 151 152 /** 153 * Return the longitudinal position that this GTU would have if it were to change to another Lane with a / the current 154 * CrossSectionLink. 155 * @param projectionLane Lane; the lane onto which the position of this GTU must be projected 156 * @param relativePosition RelativePosition; the point on this GTU that must be projected 157 * @param when Time; the time for which to project the position of this GTU 158 * @return Length; the position of this GTU in the projectionLane 159 * @throws GTUException when projectionLane it not in any of the CrossSectionLink that the GTU is on 160 */ 161 Length projectedPosition(Lane projectionLane, RelativePosition relativePosition, Time when) 162 throws GTUException; 163 164 /** 165 * Add an event to the list of lane triggers scheduled for this GTU. 166 * @param lane Lane; the lane on which the event occurs 167 * @param event SimeEvent<OTSSimTimeDouble> the event 168 */ 169 void addTrigger(Lane lane, SimEvent<OTSSimTimeDouble> event); 170 171 }