ReportingDetector.java

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

  2. import org.djunits.value.vdouble.scalar.Length;
  3. import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
  4. import org.opentrafficsim.core.gtu.RelativePosition;
  5. import org.opentrafficsim.core.network.NetworkException;
  6. import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
  7. import org.opentrafficsim.road.network.lane.Lane;

  8. /**
  9.  * Detector that prints which GTU triggers it.
  10.  * <p>
  11.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
  12.  * All rights reserved. <br>
  13.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  14.  * </p>
  15.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  16.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  17.  */
  18. public class ReportingDetector extends LaneDetector
  19. {
  20.     /** */
  21.     private static final long serialVersionUID = 20150130L;

  22.     /**
  23.      * Construct a new ReportingDetector.
  24.      * @param lane Lane; the lane on which the new ReportingDetector will be located
  25.      * @param position Length; the position of the detector along the lane
  26.      * @param triggerPosition RelativePosition.TYPE; the relative position type (e.g., FRONT, BACK) of the vehicle that triggers
  27.      *            the detector
  28.      * @param id String; the id of the new ReportingDetector
  29.      * @param simulator OtsSimulatorInterface; the simulator to enable animation
  30.      * @param detectorType DetectorType; detector type.
  31.      * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
  32.      */
  33.     public ReportingDetector(final String id, final Lane lane, final Length position,
  34.             final RelativePosition.Type triggerPosition, final OtsSimulatorInterface simulator, final DetectorType detectorType)
  35.             throws NetworkException
  36.     {
  37.         super(id, lane, position, triggerPosition, simulator, detectorType);
  38.     }

  39.     /** {@inheritDoc} */
  40.     @Override
  41.     public final void triggerResponse(final LaneBasedGtu gtu)
  42.     {
  43.         System.out.println(this + " triggered by " + getPositionType().getName() + " of " + gtu);
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public final String toString()
  48.     {
  49.         return "ReportingDetector []";
  50.     }

  51. }