|
| 1 | +package trafficcontrolsystem; |
| 2 | + |
| 3 | +import sysmlinjava.annotations.Operation; |
| 4 | +import sysmlinjava.annotations.Value; |
| 5 | +import sysmlinjava.annotations.statemachines.StateMachine; |
| 6 | +import sysmlinjava.blocks.SysMLBlock; |
| 7 | +import sysmlinjava.valuetypes.BBoolean; |
| 8 | +import sysmlinjava.valuetypes.DirectionDegrees; |
| 9 | +import sysmlinjava.valuetypes.DurationSeconds; |
| 10 | + |
| 11 | +/** |
| 12 | + * SysMLinJava executable model of an individual intersection's traffic signal |
| 13 | + * system that controls signal phases for four approaches to the intersection. |
| 14 | + * The signal phases correspond to the system states. The modeled system |
| 15 | + * consists of values for the signal colors for each of the four approaches for |
| 16 | + * each of the signal phases/states, and a state machine that determines the |
| 17 | + * timing of and transitioning between each of the phases/states. The |
| 18 | + * intersection signal system operates as a sub-state machine to two of the |
| 19 | + * states of the {@code TrafficControlSystem}, i.e. one sub-state machine for |
| 20 | + * normal operations and another sub-state machine for emergency operations. |
| 21 | + * Normal operations provide each approach with a standard red-green-yellow-red |
| 22 | + * cycle, while emergency operations find the intersection providing green to |
| 23 | + * the approaching emergency vehicle and red to all other approaches. |
| 24 | + * <p> |
| 25 | + * The {@code IntersectionSignalSystem} model demonstrates how SysMLinJava can |
| 26 | + * be used to model systems that operate in accordance with more complex state |
| 27 | + * machines, i.e. state machines with pseudo-states for transition "choices" and |
| 28 | + * "junctions" and state machines that operate within states as sub-state |
| 29 | + * machines. |
| 30 | + * |
| 31 | + * @author ModelerOne |
| 32 | + * |
| 33 | + * @see trafficcontrolsystem.TrafficControlSystem |
| 34 | + * @see trafficcontrolsystem.IntersectionSignalSystemNormalStateMachine |
| 35 | + * @see trafficcontrolsystem.IntersectionSignalSystemEmergencyStateMachine |
| 36 | + */ |
| 37 | +public class IntersectionSignalSystem extends SysMLBlock |
| 38 | +{ |
| 39 | + /** |
| 40 | + * Value for signal state (red, green, yellow) of the east-bound approach |
| 41 | + */ |
| 42 | + @Value |
| 43 | + public SignalStatesEnum eastBound; |
| 44 | + /** |
| 45 | + * Value for signal state (red, green, yellow) of the west-bound approach |
| 46 | + */ |
| 47 | + @Value |
| 48 | + public SignalStatesEnum westBound; |
| 49 | + /** |
| 50 | + * Value for signal state (red, green, yellow) of the north-bound approach |
| 51 | + */ |
| 52 | + @Value |
| 53 | + public SignalStatesEnum northBound; |
| 54 | + /** |
| 55 | + * Value for signal state (red, green, yellow) of the south-bound approach |
| 56 | + */ |
| 57 | + @Value |
| 58 | + public SignalStatesEnum southBound; |
| 59 | + |
| 60 | + /** |
| 61 | + * Value for the duration of the signal phase east/west red, north-south green |
| 62 | + */ |
| 63 | + @Value |
| 64 | + public DurationSeconds EWRedNSGrnDuration; |
| 65 | + /** |
| 66 | + * Value for the duration of the signal phase east/west yellow or north/south |
| 67 | + * yellow |
| 68 | + */ |
| 69 | + @Value |
| 70 | + public DurationSeconds YellowDuration; |
| 71 | + /** |
| 72 | + * Value for the duration of the signal phase east/west green, north-south red |
| 73 | + */ |
| 74 | + @Value |
| 75 | + public DurationSeconds EWGrnNSRedDuration; |
| 76 | + |
| 77 | + /** |
| 78 | + * Value that indicates the presence of an emergency vehicle on an approach |
| 79 | + */ |
| 80 | + @Value |
| 81 | + public BBoolean emergencyVehiclePresent; |
| 82 | + /** |
| 83 | + * Value for the approach direction of the emergency vehicle, if present |
| 84 | + */ |
| 85 | + @Value |
| 86 | + public DirectionDegrees emergencyVehicleDirection; |
| 87 | + |
| 88 | + /** |
| 89 | + * State machine for the signal system during normal operations |
| 90 | + */ |
| 91 | + @StateMachine |
| 92 | + public IntersectionSignalSystemNormalStateMachine stateMachineNormalOps; |
| 93 | + /** |
| 94 | + * State machine for the signal system during emergency operations |
| 95 | + */ |
| 96 | + @StateMachine |
| 97 | + public IntersectionSignalSystemEmergencyStateMachine stateMachineEmergencyOps; |
| 98 | + |
| 99 | + /** |
| 100 | + * Constructor |
| 101 | + * |
| 102 | + * @param contextBlock block in whose context the system resides |
| 103 | + * @param name unique name |
| 104 | + * @param id unique ID |
| 105 | + */ |
| 106 | + public IntersectionSignalSystem(SysMLBlock contextBlock, String name, Long id) |
| 107 | + { |
| 108 | + super(contextBlock, name, id); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Sets the east-west signals to green, north-south to red |
| 113 | + */ |
| 114 | + @Operation |
| 115 | + public void setEWGrnNSRed() |
| 116 | + { |
| 117 | + eastBound.setValue(SignalStatesEnum.Green); |
| 118 | + westBound.setValue(SignalStatesEnum.Green); |
| 119 | + northBound.setValue(SignalStatesEnum.Red); |
| 120 | + southBound.setValue(SignalStatesEnum.Red); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Sets the east-west signals to yellow, north-south to red |
| 125 | + */ |
| 126 | + @Operation |
| 127 | + public void setEWYelNSRed() |
| 128 | + { |
| 129 | + eastBound.setValue(SignalStatesEnum.Yellow); |
| 130 | + westBound.setValue(SignalStatesEnum.Yellow); |
| 131 | + northBound.setValue(SignalStatesEnum.Red); |
| 132 | + southBound.setValue(SignalStatesEnum.Red); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Sets the east signal yellow, west signal to green, north-south to red |
| 137 | + */ |
| 138 | + @Operation |
| 139 | + public void setEYelWGrnNSRed() |
| 140 | + { |
| 141 | + eastBound.setValue(SignalStatesEnum.Yellow); |
| 142 | + westBound.setValue(SignalStatesEnum.Green); |
| 143 | + northBound.setValue(SignalStatesEnum.Red); |
| 144 | + southBound.setValue(SignalStatesEnum.Red); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Sets the east signal to green, west signal to yellow, north-south to red |
| 149 | + */ |
| 150 | + @Operation |
| 151 | + public void setEGrnWYelNSRed() |
| 152 | + { |
| 153 | + eastBound.setValue(SignalStatesEnum.Green); |
| 154 | + westBound.setValue(SignalStatesEnum.Yellow); |
| 155 | + northBound.setValue(SignalStatesEnum.Red); |
| 156 | + southBound.setValue(SignalStatesEnum.Red); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Sets the east-west signals to red, north-south to green |
| 161 | + */ |
| 162 | + @Operation |
| 163 | + public void setEWRedNSGreen() |
| 164 | + { |
| 165 | + eastBound.setValue(SignalStatesEnum.Red); |
| 166 | + westBound.setValue(SignalStatesEnum.Red); |
| 167 | + northBound.setValue(SignalStatesEnum.Green); |
| 168 | + southBound.setValue(SignalStatesEnum.Green); |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Sets the east-west signals to red, north-south to yellow |
| 173 | + */ |
| 174 | + @Operation |
| 175 | + public void setEWRedNSYel() |
| 176 | + { |
| 177 | + eastBound.setValue(SignalStatesEnum.Red); |
| 178 | + westBound.setValue(SignalStatesEnum.Red); |
| 179 | + northBound.setValue(SignalStatesEnum.Yellow); |
| 180 | + southBound.setValue(SignalStatesEnum.Yellow); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Sets the east signal to green, west signal to red, north-south to red |
| 185 | + */ |
| 186 | + @Operation |
| 187 | + public void setEGrnWRedNSRed() |
| 188 | + { |
| 189 | + eastBound.setValue(SignalStatesEnum.Green); |
| 190 | + westBound.setValue(SignalStatesEnum.Red); |
| 191 | + northBound.setValue(SignalStatesEnum.Red); |
| 192 | + southBound.setValue(SignalStatesEnum.Red); |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * Sets the east signal to red, west signals to green, north-south to red |
| 197 | + */ |
| 198 | + @Operation |
| 199 | + public void setERedWGrnNSRed() |
| 200 | + { |
| 201 | + eastBound.setValue(SignalStatesEnum.Red); |
| 202 | + westBound.setValue(SignalStatesEnum.Green); |
| 203 | + northBound.setValue(SignalStatesEnum.Red); |
| 204 | + southBound.setValue(SignalStatesEnum.Red); |
| 205 | + } |
| 206 | + |
| 207 | + @Override |
| 208 | + protected void createValues() |
| 209 | + { |
| 210 | + super.createValues(); |
| 211 | + eastBound = new SignalStatesEnum(SignalStatesEnum.Green); |
| 212 | + westBound = new SignalStatesEnum(SignalStatesEnum.Green); |
| 213 | + northBound = new SignalStatesEnum(SignalStatesEnum.Red); |
| 214 | + southBound = new SignalStatesEnum(SignalStatesEnum.Red); |
| 215 | + EWGrnNSRedDuration = new DurationSeconds(20); |
| 216 | + EWRedNSGrnDuration = new DurationSeconds(10); |
| 217 | + YellowDuration = new DurationSeconds(5); |
| 218 | + emergencyVehiclePresent = new BBoolean(false); |
| 219 | + emergencyVehicleDirection = new DirectionDegrees(DirectionDegrees.east); |
| 220 | + } |
| 221 | +} |
0 commit comments