Grand Tour

[code language=”Java”]
# Title: Grand Tour
# Purpose: Checking out the completed track
# Author: Chris Morgan
# Date: 4th November 2014
import jarray
import jmri

class GrandTour(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")
self.quayheadSensor = sensors.provideSensor("quayhead")
self.headshuntSensor = sensors.provideSensor("headshunt")
self.runroundpointsSensor = sensors.provideSensor("runroundpoints")
self.platform1Sensor = sensors.provideSensor("platform1")
self.runroundloopSensor = sensors.provideSensor("runroundloop")
self.bayplatformSensor = sensors.provideSensor("bayplatform")
# set loco throttle
print ">>> Setting up loco throttle"
#self.throttle = self.getThrottle(3, False) # new decoder
self.throttle = self.getThrottle(5362, True) # Class 25 D5362
print ">>> Setup complete"
return

def handle(self):

print ">>> Starting tour…"
# set loco sound on
#self.throttle.setF1(True)
# turn the inertia off (it may have been on for positioning)
self.throttle.setF12(False)
# engine is on the bay points and is to reversed onto the main line
print ">>> Setting points…"
turnouts.provideTurnout("baypointsop").setState(THROWN)
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)
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 ">>> Set points for platform 1"
turnouts.provideTurnout("baypointsop").setState(CLOSED)
turnouts.provideTurnout("runroundpointsop").setState(CLOSED)
print ">>> Setting loco to forward"
self.throttle.setIsForward(True)
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)
print ">>> waiting for engine to reach the run round points"
self.waitSensorActive(self.runroundpointsSensor)
print ">>> at the run round points – allow the loco to run on for a few seconds"
self.waitMsec(7000)
print ">>> stopping the loco"
self.throttle.setSpeedSetting(0)
print ">>> allow the loco to come to a halt"
self.waitMsec(4000)
print ">>> now to go back via the run round loop"
print ">> set the points"
turnouts.provideTurnout("runroundpointsop").setState(THROWN)
print ">>> run round points thrown"
turnouts.provideTurnout("quaypointsop").setState(CLOSED)
print ">>> quay points closed"
turnouts.provideTurnout("approachpointsop").setState(THROWN)
print ">>> approach points thrown"
print ">>> send the loco back to the main line"
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)
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 ">>> now to set off down the quay"
turnouts.provideTurnout("quaypointsop").setState(THROWN)
print ">>> Setting loco to forward"
self.throttle.setIsForward(True)
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)
print ">>> wait for the loco to get to the quay head"
self.waitSensorActive(self.quayheadSensor)
print ">>> at the quay head so stop the loco"
self.waitMsec(3000)
self.throttle.setSpeedSetting(0)
print ">>> allow the loco to come to a halt"
self.waitMsec(5000)
# now go back to the main line
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)
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)
# and now run back to the bay platform
print "Setting the points"
#set the points
turnouts.provideTurnout("approachpointsop").setState(CLOSED)
turnouts.provideTurnout("baypointsop").setState(THROWN)
self.throttle.setIsForward(True)
print ">>> Sound whistle"
#self.throttle.setF3(True)
self.waitMsec(1000)
self.throttle.setF3(False)
print ">>> move loco"
self.throttle.setSpeedSetting(0.2)
print ">>> waiting for the loco to get to the bay platform"
self.waitSensorActive(self.bayplatformSensor)
print ">>> at the bay platform but let the loco run on a bit"
self.waitMsec(10000)
print ">> stopping the loco"
self.throttle.setSpeedSetting(0)
print ">>> wait for the loco to come to a stop"
self.waitMsec(5000)
# set loco sound off
#self.throttle.setF1(False)
self.waitMsec(5000)
return 1
# (requires JMRI to be terminated to stop – caution
# doing so could leave loco running if not careful)

# end of class definition

# start one of these up
GrandTour().start()
[/code]