View Javadoc
1   package org.opentrafficsim.core.network.lane;
2   
3   import org.opentrafficsim.core.gtu.RelativePosition;
4   import org.opentrafficsim.core.gtu.lane.LaneBasedGTU;
5   import org.opentrafficsim.core.unit.LengthUnit;
6   import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
7   
8   /**
9    * This is a sensor that is placed at the end of a Lane to unregister a GTU from the lane, and unregister the lane from
10   * the GTU when the back of the vehicle passes over the sensor.
11   * <p>
12   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
13   * reserved. <br>
14   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
15   * <p>
16   * @version Jan 1, 2015 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
19   */
20  public class SensorLaneEnd extends AbstractSensor
21  {
22      /** */
23      private static final long serialVersionUID = 20141231L;
24  
25      /**
26       * Place a sensor that is triggered with the back of the GTU one ulp (see <code>Math.ulp(double d)</code>) before
27       * the end of the lane to make sure it will always be triggered, independent of the algorithm used to move the GTU.
28       * @param lane The lane for which this is a sensor.
29       */
30      public SensorLaneEnd(final Lane lane)
31      {
32          super(lane, new DoubleScalar.Rel<LengthUnit>(lane.getLength().getSI() - Math.ulp(lane.getLength().getSI()),
33                  LengthUnit.METER), RelativePosition.REAR);
34      }
35  
36      /**
37       * {@inheritDoc} <br>
38       * For this method, we assume that the right sensor triggered this method. In this case the sensor that indicates
39       * the front of the GTU. The code triggering the sensor therefore has to do the checking for sensor type.
40       */
41      @Override
42      public final void trigger(final LaneBasedGTU<?> gtu)
43      {
44          gtu.removeLane(getLane());
45          getLane().removeGTU(gtu);
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      @SuppressWarnings("checkstyle:designforextension")
51      public String toString()
52      {
53          return "SensorLaneEnd [getLane()=" + this.getLane() + ", getLongitudinalPosition()="
54                  + this.getLongitudinalPosition() + ", getPositionType()=" + this.getPositionType() + "]";
55      }
56  
57  }