1 package org.opentrafficsim.road.gtu.lane.perception; 2 3 import org.opentrafficsim.base.parameters.ParameterException; 4 import org.opentrafficsim.base.parameters.ParameterTypeLength; 5 import org.opentrafficsim.base.parameters.ParameterTypes; 6 import org.opentrafficsim.core.gtu.GtuException; 7 import org.opentrafficsim.core.gtu.perception.AbstractPerception; 8 import org.opentrafficsim.core.network.NetworkException; 9 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu; 10 import org.opentrafficsim.road.gtu.lane.perception.mental.Mental; 11 import org.opentrafficsim.road.gtu.lane.perception.structure.LaneStructure; 12 13 /** 14 * The perception module of a GTU based on lanes. It is responsible for perceiving (sensing) the environment of the GTU, which 15 * includes the locations of other GTUs. Perception is done at a certain time, and the perceived information might have a 16 * limited validity. In that sense, Perception is stateful. Information can be requested as often as needed, but will only be 17 * recalculated when asked explicitly. This abstract class provides the building blocks for lane-based perception. <br> 18 * Perception for lane-based GTUs involves information about GTUs in front of the owner GTU on the same lane (the 'leader' GTU), 19 * parallel vehicles (important if we want to change lanes), distance to other vehicles on parallel lanes, as well in front as 20 * to the back (important if we want to change lanes), and information about obstacles, traffic lights, speed signs, and ending 21 * lanes. 22 * <p> 23 * This class allows {@code PerceptionCategory}s that are either eager or lazy. All categories will have the {@code updateAll} 24 * method invoked prior to an operational plan being determined. Categories may ignore this and instead evaluate results only 25 * when the tactical planner requests them. 26 * <p> 27 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 28 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 29 * </p> 30 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a> 31 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a> 32 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a> 33 */ 34 public class CategoricalLanePerception extends AbstractPerception<LaneBasedGtu> implements LanePerception 35 { 36 37 /** */ 38 private static final long serialVersionUID = 20151128L; 39 40 /** Look ahead parameter type. */ 41 protected static final ParameterTypeLength LOOKAHEAD = ParameterTypes.LOOKAHEAD; 42 43 /** Look back parameter type. */ 44 protected static final ParameterTypeLength LOOKBACK = ParameterTypes.LOOKBACK; 45 46 /** Lane structure. */ 47 private LaneStructure laneStructure = null; 48 49 /** Mental module. */ 50 private Mental mental; 51 52 /** 53 * Create a new LanePerception module without mental module. 54 * @param gtu LaneBasedGtu; GTU 55 */ 56 public CategoricalLanePerception(final LaneBasedGtu gtu) 57 { 58 super(gtu); 59 this.mental = null; 60 } 61 62 /** 63 * Create a new LanePerception module with mental module. 64 * @param gtu LaneBasedGtu; GTU 65 * @param mental Mental; mental module 66 */ 67 public CategoricalLanePerception(final LaneBasedGtu gtu, final Mental mental) 68 { 69 super(gtu); 70 this.mental = mental; 71 } 72 73 /** {@inheritDoc} */ 74 @Override 75 public final LaneStructure getLaneStructure() throws ParameterException 76 { 77 if (this.laneStructure == null) 78 { 79 this.laneStructure = new LaneStructure(getGtu(), getGtu().getParameters().getParameter(LOOKBACK), 80 getGtu().getParameters().getParameter(LOOKAHEAD)); 81 } 82 return this.laneStructure; 83 } 84 85 /** {@inheritDoc} */ 86 @Override 87 public Mental getMental() 88 { 89 return this.mental; 90 } 91 92 /** {@inheritDoc} */ 93 @Override 94 public void perceive() throws GtuException, NetworkException, ParameterException 95 { 96 if (this.mental != null) 97 { 98 this.mental.apply(this); 99 } 100 } 101 102 }