SimpleReportingSensor.java

  1. package org.opentrafficsim.road.network.lane;

  2. import java.awt.Color;
  3. import java.rmi.RemoteException;

  4. import javax.naming.NamingException;

  5. import org.djunits.value.vdouble.scalar.Length;
  6. import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
  7. import org.opentrafficsim.core.gtu.RelativePosition;
  8. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;

  9. /**
  10.  * Sensor that prints which GTU triggers it.
  11.  * <p>
  12.  * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
  13.  * All rights reserved. <br>
  14.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  15.  * <p>
  16.  * $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
  17.  * initial version an 30, 2015 <br>
  18.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  19.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  20.  */
  21. public class SimpleReportingSensor extends AbstractSensor
  22. {
  23.     /** */
  24.     private static final long serialVersionUID = 20150130L;

  25.     /**
  26.      * @param lane the lane that triggers the deletion of the GTU.
  27.      * @param position the position of the sensor
  28.      * @param triggerPosition RelativePosition.TYPE; the relative position type (e.g., FRONT, BACK) of the vehicle that triggers
  29.      *            the sensor.
  30.      * @param name the name of the sensor.
  31.      * @param simulator the simulator to enable animation.
  32.      */
  33.     public SimpleReportingSensor(final Lane lane, final Length position,
  34.         final RelativePosition.TYPE triggerPosition, final String name, final OTSDEVSSimulatorInterface simulator)
  35.     {
  36.         super(lane, position, triggerPosition, name, simulator);
  37.         try
  38.         {
  39.             new SensorAnimation(this, simulator, Color.YELLOW);
  40.         }
  41.         catch (RemoteException | NamingException exception)
  42.         {
  43.             exception.printStackTrace();
  44.         }
  45.     }

  46.     /** {@inheritDoc} */
  47.     @Override
  48.     public void trigger(final LaneBasedGTU gtu)
  49.     {
  50.         System.out.println(this + " triggered by FRONT of " + gtu);
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public String toString()
  55.     {
  56.         return "Sensor [Lane=" + this.getLane() + "]";
  57.     }
  58. }