# Title: Test 2 # Purpose: learning about scripting, sensors and turnouts # Author: Chris Morgan # Date: 22nd October 2014 import jarray import jmri class Test2(jmri.jmrit.automat.AbstractAutomaton) : def init(self): # define sensors print ">>> Defining sensors" self.mainlineSensor = sensors.provideSensor("mainline") self.approachpointsSensor = sensors.provideSensor("approachpoints") self.baypointsSensor = sensors.provideSensor("baypoints") self.quaypointsSensor = sensors.provideSensor("quaypoints") self.quaysidingSensor = sensors.provideSensor("quaysiding") self.quaysideSensor = sensors.provideSensor("quayside") # set loco throttle print ">>> Setting up loco throttle" self.throttle = self.getThrottle(101, True) # set loco sound on self.throttle.setF1(True) print ">>> Setup complete" return def handle(self): print ">>> Running loop..." # engine is on the bay points and is to be reversed onto the main line # and then run forward down the quay side before returning to the start print ">>> Setting points..." turnouts.provideTurnout("approachpointsop").setState(CLOSED) print ">>> Setting loco to reverse" self.throttle.setIsForward(False) self.waitMsec(1000) print ">>> Sound whistle" self.throttle.setF3(True) self.waitMsec(1000) self.throttle.setF3(False) print ">>> move loco" self.throttle.setSpeedSetting(0.2) # drain cocks self.throttle.setF7(True) self.waitMsec(6000) self.throttle.setF7(False) print ">>> waiting for the loco to to get to the main line" self.waitSensorActive(self.mainlineSensor) print ">>> at the main line, let the loco run on for a while" self.waitMsec(6000) print ">>> stopping the loco" self.throttle.setSpeedSetting(0) print ">>> allow the loco to come to a halt" self.waitMsec(5000) print ">>> throw approach points" turnouts.provideTurnout("approachpointsop").setState(THROWN) print ">>> ensure quay points are thrown correctly" turnouts.provideTurnout("quaypointsop").setState(THROWN) self.waitMsec(4000) print ">>> Guard sounds whistle" self.throttle.setF9(True) self.waitMsec(500) self.throttle.setF9(False) print ">>> loco prepares to move off" self.throttle.setIsForward(True) self.waitMsec(2000) # whistle self.throttle.setF3(True) self.waitMsec(500) self.throttle.setF3(False) print ">>> moving off" self.throttle.setSpeedSetting(0.8) # drain cocks self.throttle.setF7(True) self.waitMsec(6000) self.throttle.setF7(False) print ">>> wait until the loco gets to the quay side" self.waitSensorActive(self.quaysideSensor) print ">>> at the quay side, let it run on a for a while" self.waitMsec(1000) print ">>> bring the loco to a halt" self.throttle.setSpeedSetting(0) print ">>> wait 15 seonds for the loco to come to a halt" self.waitMsec(15000) print ">>> go back again" print ">>> set the loco to reverse" self.throttle.setIsForward(False) print ">>> Sound whistle twice" self.throttle.setF3(True) self.waitMsec(1000) self.throttle.setF3(False) self.waitMsec(500) self.throttle.setF3(True) self.waitMsec(1000) self.throttle.setF3(False) print ">>> move of in reverse" self.throttle.setSpeedSetting(0.8) # drain cocks self.throttle.setF7(True) self.waitMsec(6000) self.throttle.setF7(False) print ">>> waiting for the loco to to get to the quay points" self.waitSensorActive(self.quaypointsSensor) print ">>> at the quay points so begin slowing the loco now" self.throttle.setSpeedSetting(0.4) print ">>> waiting for the loco to to get to the approach points" self.waitSensorActive(self.approachpointsSensor) print ">>> at the approach points so let it run on a 4 seconds" self.waitMsec(4000) print ">>> begin stopping the loco now" self.throttle.setSpeedSetting(0) print ">>> allow 15 seconds for the loco to come to a halt" self.waitMsec(15000) print ">>> now put the loco back on the bay points" turnouts.provideTurnout("approachpointsop").setState(CLOSED) turnouts.provideTurnout("baypointsop").setState(THROWN) self.waitMsec(4000) print ">>> Guard sounds whistle" self.throttle.setF9(True) self.waitMsec(500) self.throttle.setF9(False) print ">>> loco prepares to move off" self.throttle.setIsForward(True) self.waitMsec(2000) # whistle self.throttle.setF3(True) self.waitMsec(500) self.throttle.setF3(False) print ">>> moving off" self.throttle.setSpeedSetting(0.2) # drain cocks self.throttle.setF7(True) self.waitMsec(6000) self.throttle.setF7(False) print ">>> wait for the loco to get to the bay points" self.waitSensorActive(self.baypointsSensor) print ">>> at the bay points, let the loco run on for 3 seconds" self.waitMsec(3000) print ">>> brining the loco to a halt" self.throttle.setSpeedSetting(0) # wait 20 seconds before going found again self.waitMsec(10000) return 1 # end of class definition # start up Test2().start()