View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djunits.value.vdouble.scalar.Time;
5   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
6   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterTypes;
7   import org.opentrafficsim.core.gtu.perception.AbstractPerception;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   
10  /**
11   * The perception module of a GTU based on lanes. It is responsible for perceiving (sensing) the environment of the GTU, which
12   * includes the locations of other GTUs. Perception is done at a certain time, and the perceived information might have a
13   * limited validity. In that sense, Perception is stateful. Information can be requested as often as needed, but will only be
14   * recalculated when asked explicitly. This abstract class provides the building blocks for lane-based perception. <br>
15   * Perception for lane-based GTUs involves information about GTUs in front of the owner GTU on the same lane (the 'leader' GTU),
16   * parallel vehicles (important if we want to change lanes), distance to other vehicles on parallel lanes, as well in front as
17   * to the back (important if we want to change lanes), and information about obstacles, traffic lights, speed signs, and ending
18   * lanes.
19   * <p>
20   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22   * </p>
23   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
24   * initial version Nov 15, 2015 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
28   */
29  public abstract class AbstractLanePerception extends AbstractPerception implements LanePerception
30  {
31  
32      /** */
33      private static final long serialVersionUID = 20151128L;
34  
35      /** Lane structure to perform the perception with. */
36      private LaneStructure laneStructure = null;
37  
38      /** Most recent update time of lane structure. */
39      private Time updateTime = null;
40  
41      /**
42       * Create a new LanePerception module. Because the constructor is often called inside the constructor of a GTU, this
43       * constructor does not ask for the pointer to the GTU, as it is often impossible to provide at the time of construction.
44       * Use the setter of the GTU instead.
45       * @param gtu GTU
46       */
47      public AbstractLanePerception(final LaneBasedGTU gtu)
48      {
49          super(gtu);
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public final LaneBasedGTU getGtu()
55      {
56          return (LaneBasedGTU) super.getGtu();
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public final LaneStructure getLaneStructure() throws ParameterException
62      {
63          if (this.laneStructure == null || this.updateTime.lt(getGtu().getSimulator().getSimulatorTime().getTime()))
64          {
65              // downstream structure length
66              Length down = getGtu().getBehavioralCharacteristics().getParameter(ParameterTypes.PERCEPTION);
67              // upstream structure length
68              Length up = getGtu().getBehavioralCharacteristics().getParameter(ParameterTypes.LOOKBACK);
69              // structure length downstream of split on link not on route
70              Length downSplit = getGtu().getBehavioralCharacteristics().getParameter(ParameterTypes.LOOKAHEAD);
71              // structure length upstream of merge on link not on route
72              Length upMerge = Length.max(up, downSplit);
73              if (this.laneStructure != null)
74              {
75                  // TODO update lane structure
76                  
77              }
78              else
79              {
80                  // TODO create lane structure
81                  
82              }
83              // TODO possibly optimize by using a 'singleton' lane structure source
84              this.updateTime = getGtu().getSimulator().getSimulatorTime().getTime();
85          }
86          return this.laneStructure;
87      }
88  
89  }