package org.opentrafficsim.road.gtu.lane; import java.util.Map; import org.djunits.value.vdouble.scalar.Acceleration; import org.djunits.value.vdouble.scalar.Direction; import org.djunits.value.vdouble.scalar.Length; import org.djunits.value.vdouble.scalar.Speed; import org.djunits.value.vdouble.vector.PositionVector; import org.djutils.draw.point.OrientedPoint3d; import org.djutils.event.EventType; import org.djutils.event.TimedEventType; import org.djutils.metadata.MetaData; import org.djutils.metadata.ObjectDescriptor; import org.opentrafficsim.core.gtu.Gtu; import org.opentrafficsim.core.gtu.GtuDirectionality; import org.opentrafficsim.core.gtu.GtuException; import org.opentrafficsim.core.gtu.RelativePosition; import org.opentrafficsim.core.gtu.TurnIndicatorStatus; import org.opentrafficsim.road.network.RoadNetwork; import org.opentrafficsim.road.network.lane.DirectedLanePosition; import org.opentrafficsim.road.network.lane.Lane; /** * This interface defines a lane based GTU. *

* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $, * initial version Oct 22, 2014
* @author Alexander Verbraeck * @author Peter Knoppers */ public interface LaneBasedGtu extends Gtu { /** @return the road network to which the LaneBasedGTU belongs */ RoadNetwork getNetwork(); /** * Return the location without a RemoteException. {@inheritDoc} */ @Override OrientedPoint3d getLocation(); /** * Get projected length on the lane. * @param lane Lane; lane to project the vehicle on * @return Length; the length on the lane, which is different from the actual length during deviative tactical plans * @throws GtuException when the vehicle is not on the given lane */ default Length getProjectedLength(final Lane lane) throws GtuException { Length front = position(lane, getFront()); Length rear = position(lane, getRear()); return getDirection(lane).isPlus() ? front.minus(rear) : rear.minus(front); } /** * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the * vehicle is registered.
* Note: If a GTU is registered in multiple parallel lanes, the lateralLaneChangeModel is used to determine the * center line of the vehicle at this point in time. Otherwise, the average of the center positions of the lines will be * taken. * @param relativePosition RelativePosition; the position on the vehicle relative to the reference point. * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU. * @throws GtuException when the vehicle is not on one of the lanes on which it is registered. */ Map positions(RelativePosition relativePosition) throws GtuException; /** * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane at the current * simulation time.
* @param lane Lane; the position on this lane will be returned. * @param relativePosition RelativePosition; the position on the vehicle relative to the reference point. * @return DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane. * @throws GtuException when the vehicle is not on the given lane. */ Length position(Lane lane, RelativePosition relativePosition) throws GtuException; /** * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the * vehicle is registered, as fractions 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 'inner' and 'outer' curve.
* @param relativePosition RelativePosition; the position on the vehicle relative to the reference point. * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU. * @throws GtuException when the vehicle is not on one of the lanes on which it is registered. */ Map fractionalPositions(RelativePosition relativePosition) throws GtuException; /** * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction * 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 * 'inner' and 'outer' curve.
* @param lane Lane; the position on this lane will be returned. * @param relativePosition RelativePosition; the position on the vehicle relative to the reference point. * @return the fractional relative position on the lane at the given time. * @throws GtuException when the vehicle is not on the given lane. */ double fractionalPosition(Lane lane, RelativePosition relativePosition) throws GtuException; /** * Return the current Lane, position and directionality of the GTU. * @return DirectedLanePosition; the current Lane, position and directionality of the GTU * @throws GtuException in case the reference position of the GTU cannot be found on the lanes in its current path */ DirectedLanePosition getReferencePosition() throws GtuException; /** * Return the directionality of a lane on which the GTU is registered for its current operational plan. * @param lane Lane; the lane for which we want to know the direction * @return GTUDirectionality; the direction on the given lane * @throws GtuException in case the GTU is not registered on the Lane */ GtuDirectionality getDirection(Lane lane) throws GtuException; /** * The default implementation returns {@code true} if the deceleration is larger than a speed-dependent threshold given * by:
*
* c0 * g(v) + c1 + c3*v^2
*
* where c0 = 0.2, c1 = 0.15 and c3 = 0.00025 (with c2 = 0 implicit) are empirically derived averages, and g(v) is 0 below * 25 km/h or 1 otherwise, representing that the engine is disengaged at low speeds. * @return boolean; whether the braking lights are on */ default boolean isBrakingLightsOn() { return ((InternalLaneBasedGtu) this).isBrakingLightsOn(getSimulator().getSimulatorTime()); } /** * Returns the lateral position of the GTU relative to the lane center line. Negative values are towards the right. * @param lane Lane; lane to consider (most important regarding left/right, not upstream downstream) * @return Length; lateral position of the GTU relative to the lane center line * @throws GtuException when the vehicle is not on the given lane. */ Length getLateralPosition(Lane lane) throws GtuException; /** @return the status of the turn indicator */ TurnIndicatorStatus getTurnIndicatorStatus(); /** * The lane-based event type for pub/sub indicating the initialization of a new GTU.
* Payload: [String gtuId, PositionVector initialPosition, Direction initialDirection, Length length, Length width, String * linkId, String laneId, Length positionOnReferenceLane, GTUDirectionality direction, GTUType gtuType] */ TimedEventType LANEBASED_INIT_EVENT = new TimedEventType("LANEBASEDGTU.INIT", new MetaData("Lane based GTU created", "Lane based GTU created", new ObjectDescriptor[] {new ObjectDescriptor("GTU id", "GTU id", String.class), new ObjectDescriptor("initial position", "initial position", PositionVector.class), new ObjectDescriptor("initial direction", "initial direction", Direction.class), new ObjectDescriptor("Length", "Length", Length.class), new ObjectDescriptor("Width", "Width", Length.class), new ObjectDescriptor("Link id", "Link id", String.class), new ObjectDescriptor("Lane id", "Lane id", String.class), new ObjectDescriptor("Longitudinal position on lane", "Longitudinal position on lane", Length.class), new ObjectDescriptor("Driving direction", "Driving direction", String.class), new ObjectDescriptor("GTU type name", "GTU type name", String.class)})); /** * The lane-based event type for pub/sub indicating a move.
* Payload: [String gtuId, PositionVector currentPosition, Direction currentDirection, Speed speed, Acceleration * acceleration, TurnIndicatorStatus turnIndicatorStatus, Length odometer, Link id of referenceLane, Lane id of * referenceLane, Length positionOnReferenceLane, GTUDirectionality direction] */ TimedEventType LANEBASED_MOVE_EVENT = new TimedEventType("LANEBASEDGTU.MOVE", new MetaData("Lane based GTU moved", "Lane based GTU moved", new ObjectDescriptor[] {new ObjectDescriptor("GTU id", "GTU id", String.class), new ObjectDescriptor("Position", "Position", PositionVector.class), new ObjectDescriptor("Direction", "Direction", Direction.class), new ObjectDescriptor("Speed", "Speed", Speed.class), new ObjectDescriptor("Acceleration", "Acceleration", Acceleration.class), new ObjectDescriptor("TurnIndicatorStatus", "Turn indicator status", String.class), new ObjectDescriptor("Odometer", "Odometer value", Length.class), new ObjectDescriptor("Link id", "Link id", String.class), new ObjectDescriptor("Lane id", "Lane id", String.class), new ObjectDescriptor("Longitudinal position on lane", "Longitudinal position on lane", Length.class), new ObjectDescriptor("Driving direction", "Driving direction", String.class)})); /** * The lane-based event type for pub/sub indicating destruction of the GTU.
* Payload: [String gtuId, PositionVector finalPosition, Direction finalDirection, Length finalOdometer, Link referenceLink, * Lane referenceLane, Length positionOnReferenceLane, GTUDirectionality direction] */ TimedEventType LANEBASED_DESTROY_EVENT = new TimedEventType("LANEBASEDGTU.DESTROY", new MetaData("Lane based GTU destroyed", "Lane based GTU destroyed", new ObjectDescriptor[] {new ObjectDescriptor("GTU id", "GTU id", String.class), new ObjectDescriptor("Position", "Position", PositionVector.class), new ObjectDescriptor("Direction", "Direction", Direction.class), new ObjectDescriptor("Odometer", "Odometer value", Length.class), new ObjectDescriptor("Link id", "Link id", String.class), new ObjectDescriptor("Lane id", "Lane id", String.class), new ObjectDescriptor("Longitudinal position on lane", "Longitudinal position on lane", Length.class), new ObjectDescriptor("Driving direction", "Driving direction", String.class)})); // TODO: the next 2 events are never fired... /** * The event type for pub/sub indicating that the GTU entered a new lane (with the FRONT position if driving forward; REAR * if driving backward).
* Payload: [String gtuId, String link id, String lane id] */ @Deprecated EventType LANE_ENTER_EVENT = new EventType("LANE.ENTER", new MetaData("Lane based GTU entered lane", "Front of lane based GTU entered lane", new ObjectDescriptor[] {new ObjectDescriptor("GTU id", "GTU id", String.class), new ObjectDescriptor("Link id", "Link id", String.class), new ObjectDescriptor("Lane id", "Lane id", String.class)})); /** * The event type for pub/sub indicating that the GTU exited a lane (with the REAR position if driving forward; FRONT if * driving backward).
* Payload: [String gtuId, String link id, String lane id] */ @Deprecated EventType LANE_EXIT_EVENT = new EventType("LANE.EXIT", new MetaData("Lane based GTU exited lane", "Rear of lane based GTU exited lane", new ObjectDescriptor[] {new ObjectDescriptor("GTU id", "GTU id", String.class), new ObjectDescriptor("Link id", "Link id", String.class), new ObjectDescriptor("Lane id", "Lane id", String.class)})); /** * The event type for pub/sub indicating that the GTU change lane.
* Payload: [String gtuId, LateralDirectionality direction, DirectedLanePosition from] */ TimedEventType LANE_CHANGE_EVENT = new TimedEventType("LANE.CHANGE", new MetaData("Lane based GTU changes lane", "Lane based GTU changes lane", new ObjectDescriptor[] {new ObjectDescriptor("GTU id", "GTU id", String.class), new ObjectDescriptor("Lateral direction of lane change", "Lateral direction of lane change", String.class), new ObjectDescriptor("Link id", "Link id", String.class), new ObjectDescriptor("Lane id of vacated lane", "Lane id of vacated lane", String.class), new ObjectDescriptor("Position along vacated lane", "Position along vacated lane", Length.class)})); }