View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.awt.Color;
4   import java.rmi.RemoteException;
5   
6   import javax.naming.NamingException;
7   
8   import org.djunits.value.vdouble.scalar.Length;
9   import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
10  import org.opentrafficsim.core.gtu.RelativePosition;
11  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
12  
13  /**
14   * Sensor that prints which GTU triggers it.
15   * <p>
16   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
17   * All rights reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
19   * <p>
20   * $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
21   * initial version an 30, 2015 <br>
22   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
24   */
25  public class SimpleReportingSensor extends AbstractSensor
26  {
27      /** */
28      private static final long serialVersionUID = 20150130L;
29  
30      /**
31       * @param lane the lane that triggers the deletion of the GTU.
32       * @param position the position of the sensor
33       * @param triggerPosition RelativePosition.TYPE; the relative position type (e.g., FRONT, BACK) of the vehicle that triggers
34       *            the sensor.
35       * @param name the name of the sensor.
36       * @param simulator the simulator to enable animation.
37       */
38      public SimpleReportingSensor(final Lane lane, final Length.Rel position,
39          final RelativePosition.TYPE triggerPosition, final String name, final OTSDEVSSimulatorInterface simulator)
40      {
41          super(lane, position, triggerPosition, name, simulator);
42          try
43          {
44              new SensorAnimation(this, simulator, Color.YELLOW);
45          }
46          catch (RemoteException | NamingException exception)
47          {
48              exception.printStackTrace();
49          }
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public void trigger(final LaneBasedGTU gtu)
55      {
56          System.out.println(this + " triggered by FRONT of " + gtu);
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public String toString()
62      {
63          return "Sensor [Lane=" + this.getLane() + "]";
64      }
65  }