SpeedLimit.java

  1. package org.opentrafficsim.road.network.sampling.data;

  2. import org.djunits.unit.SpeedUnit;
  3. import org.djunits.value.vfloat.scalar.FloatSpeed;
  4. import org.djutils.exceptions.Throw;
  5. import org.opentrafficsim.core.gtu.GTUException;
  6. import org.opentrafficsim.core.network.NetworkException;
  7. import org.opentrafficsim.kpi.sampling.data.ExtendedDataTypeSpeed;
  8. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  9. import org.opentrafficsim.road.network.sampling.GtuData;

  10. /**
  11.  * Speed limit for trajectories.
  12.  * <p>
  13.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  14.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  15.  * <p>
  16.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 11 okt. 2016 <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.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  20.  */
  21. public class SpeedLimit extends ExtendedDataTypeSpeed<GtuData>
  22. {

  23.     /**
  24.      * Constructor.
  25.      */
  26.     public SpeedLimit()
  27.     {
  28.         super("SpeedLimit");
  29.     }

  30.     /** {@inheritDoc} */
  31.     @Override
  32.     public final FloatSpeed getValue(final GtuData gtu)
  33.     {
  34.         Throw.whenNull(gtu, "GTU may not be null.");
  35.         LaneBasedGTU laneGtu = gtu.getGtu();
  36.         try
  37.         {
  38.             return new FloatSpeed(laneGtu.getReferencePosition().getLane().getSpeedLimit(laneGtu.getGTUType()).si,
  39.                     SpeedUnit.SI);
  40.         }
  41.         catch (NetworkException | GTUException exception)
  42.         {
  43.             throw new RuntimeException("Could not obtain speed limit.", exception);
  44.         }
  45.     }

  46.     /** {@inheritDoc} */
  47.     @Override
  48.     public final String toString()
  49.     {
  50.         return "SpeedLimit";
  51.     }

  52. }