D. Pseudocode

(1-5)     Deleting Timers/Variables/User Inputs and Clearing the Command Window

 

(6)        Starting the timer for use in toc commands

 

(8-10)   To stop train: 1. CTRL + C 2. Use command “a.motorRun(1,’release’)”

 

(12-16) Connecting to Arduino (Comment out sim code when using simulator)

 

(18-20) Activating the Crossing LEDs (Activating their pins in Arduino)

 

(22-28) LED Flags (Activating the pins for the right and left LEDs, respectively, and setting them to ‘off by default.’

 

(30-42) Flags, set as their defaults

In order:

Setting Arduino pins for Approach/Departure Gates

Setting Flags for “Whether or not the train has yet hit the Approach/Departure Gate” (By default it is 0, or False)

Setting Flag for “Time since hitting the Approach Gate” (By default it is -1, which works functionally as 0)

Setting a Timer Interval for toc, BlinkStart (This is a flag used later in order to ensure the lights repeat a blinking pattern when needed and to stop when not needed)

Setting a Flag for “Whether or not the gate is up” (By default is 1, or True)

Setting Flags for the right and left LEDs respectively, both for “Whether or not the LED is currently active” (By default is 0, or False)

Setting a Timer for toc, ledInterval (This is a flag used later to ensure the blinks stay at a constant rate and do not overload the system)

Setting a timer for “Safe Start,” which is code that ensures that the train starts as safely as possible for traffic conditions. This flag is key to much of the code. (By default is 1 or True)

(46-52) Input Prompt asking if the train is in an urban or rural environment. No input = system assumes ‘worst case’ and defaults itself to the safer, slower, urban setting.

If RuralSet = 0 or is False, then Safestart assumes it is in an urban setting.

If RuralSet = 1 or is True, then Safestart assumes it is in a rural setting.

end

(54) Start Train Motor

 

(56-183)Start a master while-end loop for the code (while 1 so it is always true)

 

(57-63) If Train is in Urban Setting and has not hit either Gate and it is in SafeStart,

Then lower speed to “Urban Safe (170,)” lower gate, set GateUp as False

end

(69)      Flush Arduino out so the code does not overload it using “a.flush();”

 

(71-77) If the Approach Gate detects the train within it and it is SafeStart and it has not yet hit the Departure Gate,

Then decrease speed to “Urban Safe (170,)” set HitApp as True, set HitDep as False, and take the current times for the flags TimeHitApp, BlinkStart, and ledInterval

end

(81-87) If the Departure Gate detects the train within it and it is Safestart and it has not yet set HitDep as True,

Then increase speed to “Maximum (255,)” set HitApp as false, set HitDep as True, raise the gate, set GateUp as True, set SafeStart as False

end

(90-114)If SafeStart is True and HitDep is False, [This is a master If-End Statement that disables the following if-ends (until 114) when any of the req’s are not met]

 

(94-99) If the interval between blink cycles has been .5 seconds or longer and the Right LED is not on and it has been .22 seconds or longer between the last ‘blink,’

Then turn the Right LED on, turn the Left LED off, set rLEDon to True, set lLEDon to False, take the time since the last ‘blink’ (ledInterval)

end

(102-107)If the interval between blink cycles has been .5 seconds or longer and the Left LED is not on and it has been .22 seconds or longer between the last ‘blink,’

Then turn the Left LED on, turn the Right LED off, set lLEDon to True, set rLEDon to False, take the time since the last ‘blink’ (ledInterval)

end

(111-113)If it has been .longer than .5 seconds since the last ‘Blink Cycle,’

Then take the current time for BlinkStart (toc)

end

(117)    End of SafeStart code

 

(122-128)If the Approach Gate detects the train within it and it is not SafeStart and it has not yet hit the Departure Gate,

Then decrease speed to “Urban Safe (170,)” set HitApp as True, set HitDep as False, and take the current times for the flags TimeHitApp, BlinkStart, and ledInterval (toc)

end

(132-134)If it has been 1.10 seconds or longer since hitting the Approach Gate and the gate is up and it has hit the approach gate and it is an urban setting and it has not hit the Departure Gate and it is not SafeStart,

Then lower the gate, set GateUp as False.

end

(138-140)If it has been .5 seconds or longer since hitting the Approach Gate and the gate is up and it has hit the approach gate and it is a rural setting and it has not hit the Departure Gate and it is not SafeStart,

Then lower the gate, set GateUp as False.

end

(144-149)If the Departure Gate detects the train within it and it is not Safestart,

Then increase speed to “Maximum (255,)” set HitApp as false, set HitDep as True, raise the gate, set GateUp as True

end

(155-160) If it has been .5 seconds or longer since the last “Blink Cycle” and the Right LED is not on and HitApp is true and it has been longer than .22 seconds since the last ‘blink’ and it is not SafeStart and HitDep is false,

Then turn on Right LED, turn off Left LED, set rLEDon to True, set lLEDon to False, start a timer for the ledInterval (toc)

end

 

(163-168)If it has been .5 seconds or longer since the last “Blink Cycle” and the Left LED is not on and HitApp is true and it has been longer than .22 seconds since the last ‘blink’ and it is not SafeStart and HitDep is false,

Then turn on Left LED, turn off Right LED, set lLEDon to True, set rLEDon to False, start a timer for the ledInterval (toc)

end

(172-173)If it has been more than .5 seconds since the last “Blink Cycle” and it is not SafeStart,

Then start a timer for a new “Blink Cycle” (Using BlinkStart flag and toc)

end

(177-179)If HitDep is True and HitApp is false,

Then turn off the Right LED, turn off the Left LED

end

end (Master while loop)