123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- """
- Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
- Date: Fri Aug 05 16:08:37 2016
- """
- from sccd.runtime.statecharts_core import *
- # package ""
- class Train(RuntimeClassBase):
- def __init__(self, controller, root):
- RuntimeClassBase.__init__(self, controller)
-
- self.semantics.big_step_maximality = StatechartSemantics.TakeMany
- self.semantics.internal_event_lifeline = StatechartSemantics.Queue
- self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
- self.semantics.priority = StatechartSemantics.SourceChild
- self.semantics.concurrency = StatechartSemantics.Single
-
- # build Statechart structure
- self.build_statechart_structure()
-
- # call user defined constructor
- Train.user_defined_constructor(self, root)
-
- def user_defined_constructor(self, root):
- self.root, self.acceleration, self.velocity = root, 0.0, 0.0
- self.root.trainIs(self)
-
- def user_defined_destructor(self):
- pass
-
-
- # user defined method
- def updateState(self):
- self.root.updateState()
-
-
- # user defined method
- def openDoors(self):
- self.root.openDoors()
-
-
- # user defined method
- def closeDoors(self):
- self.root.closeDoors()
-
-
- # user defined method
- def notify(self, message, color):
- self.root.notify(message, color)
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, self)
-
- # state /normal_operation
- self.states["/normal_operation"] = State(1, self)
-
- # state /normal_operation/for_history
- self.states["/normal_operation/for_history"] = ParallelState(2, self)
-
- # state /normal_operation/for_history/train
- self.states["/normal_operation/for_history/train"] = State(3, self)
-
- # state /normal_operation/for_history/train/train
- self.states["/normal_operation/for_history/train/train"] = State(4, self)
-
- # state /normal_operation/for_history/train/train/stopped
- self.states["/normal_operation/for_history/train/train/stopped"] = State(5, self)
- self.states["/normal_operation/for_history/train/train/stopped"].setEnter(self._normal_operation_for_history_train_train_stopped_enter)
-
- # state /normal_operation/for_history/train/train/stopped/opened_doors
- self.states["/normal_operation/for_history/train/train/stopped/opened_doors"] = State(6, self)
- self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].setEnter(self._normal_operation_for_history_train_train_stopped_opened_doors_enter)
- self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].setExit(self._normal_operation_for_history_train_train_stopped_opened_doors_exit)
-
- # state /normal_operation/for_history/train/train/stopped/in_station
- self.states["/normal_operation/for_history/train/train/stopped/in_station"] = State(7, self)
-
- # state /normal_operation/for_history/train/train/stopped/allow_closing
- self.states["/normal_operation/for_history/train/train/stopped/allow_closing"] = State(8, self)
- self.states["/normal_operation/for_history/train/train/stopped/allow_closing"].setEnter(self._normal_operation_for_history_train_train_stopped_allow_closing_enter)
-
- # state /normal_operation/for_history/train/train/stopped/ready_to_leave
- self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"] = State(9, self)
-
- # state /normal_operation/for_history/train/train/approaching_station
- self.states["/normal_operation/for_history/train/train/approaching_station"] = State(10, self)
-
- # state /normal_operation/for_history/train/train/driving
- self.states["/normal_operation/for_history/train/train/driving"] = State(11, self)
-
- # state /normal_operation/for_history/train/train/max_speed
- self.states["/normal_operation/for_history/train/train/max_speed"] = State(12, self)
- self.states["/normal_operation/for_history/train/train/max_speed"].setEnter(self._normal_operation_for_history_train_train_max_speed_enter)
- self.states["/normal_operation/for_history/train/train/max_speed"].setExit(self._normal_operation_for_history_train_train_max_speed_exit)
-
- # state /normal_operation/for_history/GUI_update
- self.states["/normal_operation/for_history/GUI_update"] = State(13, self)
-
- # state /normal_operation/for_history/GUI_update/S_
- self.states["/normal_operation/for_history/GUI_update/S_"] = State(14, self)
-
- # state /normal_operation/for_history/GUI_update/S_/updating
- self.states["/normal_operation/for_history/GUI_update/S_/updating"] = State(15, self)
- self.states["/normal_operation/for_history/GUI_update/S_/updating"].setEnter(self._normal_operation_for_history_GUI_update_S__updating_enter)
- self.states["/normal_operation/for_history/GUI_update/S_/updating"].setExit(self._normal_operation_for_history_GUI_update_S__updating_exit)
-
- # state /normal_operation/for_history/polling
- self.states["/normal_operation/for_history/polling"] = State(16, self)
-
- # state /normal_operation/for_history/polling/S_
- self.states["/normal_operation/for_history/polling/S_"] = State(17, self)
-
- # state /normal_operation/for_history/polling/S_/okay
- self.states["/normal_operation/for_history/polling/S_/okay"] = State(18, self)
- self.states["/normal_operation/for_history/polling/S_/okay"].setEnter(self._normal_operation_for_history_polling_S__okay_enter)
- self.states["/normal_operation/for_history/polling/S_/okay"].setExit(self._normal_operation_for_history_polling_S__okay_exit)
-
- # state /normal_operation/for_history/polling/S_/warn
- self.states["/normal_operation/for_history/polling/S_/warn"] = State(19, self)
- self.states["/normal_operation/for_history/polling/S_/warn"].setEnter(self._normal_operation_for_history_polling_S__warn_enter)
- self.states["/normal_operation/for_history/polling/S_/warn"].setExit(self._normal_operation_for_history_polling_S__warn_exit)
-
- # state /normal_operation/H
- self.states["/normal_operation/H"] = DeepHistoryState(20, self)
-
- # state /emergency_stop
- self.states["/emergency_stop"] = State(21, self)
- self.states["/emergency_stop"].setEnter(self._emergency_stop_enter)
- self.states["/emergency_stop"].setExit(self._emergency_stop_exit)
-
- # state /finished
- self.states["/finished"] = State(22, self)
- self.states["/finished"].setEnter(self._finished_enter)
-
- # state /paused
- self.states["/paused"] = State(23, self)
-
- # add children
- self.states[""].addChild(self.states["/normal_operation"])
- self.states[""].addChild(self.states["/emergency_stop"])
- self.states[""].addChild(self.states["/finished"])
- self.states[""].addChild(self.states["/paused"])
- self.states["/normal_operation"].addChild(self.states["/normal_operation/for_history"])
- self.states["/normal_operation"].addChild(self.states["/normal_operation/H"])
- self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/train"])
- self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/GUI_update"])
- self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/polling"])
- self.states["/normal_operation/for_history/train"].addChild(self.states["/normal_operation/for_history/train/train"])
- self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/stopped"])
- self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/approaching_station"])
- self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/driving"])
- self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/max_speed"])
- self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/opened_doors"])
- self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/in_station"])
- self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/allow_closing"])
- self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"])
- self.states["/normal_operation/for_history/GUI_update"].addChild(self.states["/normal_operation/for_history/GUI_update/S_"])
- self.states["/normal_operation/for_history/GUI_update/S_"].addChild(self.states["/normal_operation/for_history/GUI_update/S_/updating"])
- self.states["/normal_operation/for_history/polling"].addChild(self.states["/normal_operation/for_history/polling/S_"])
- self.states["/normal_operation/for_history/polling/S_"].addChild(self.states["/normal_operation/for_history/polling/S_/okay"])
- self.states["/normal_operation/for_history/polling/S_"].addChild(self.states["/normal_operation/for_history/polling/S_/warn"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/paused"]
- self.states["/normal_operation"].default_state = self.states["/normal_operation/for_history"]
- self.states["/normal_operation/for_history/train"].default_state = self.states["/normal_operation/for_history/train/train"]
- self.states["/normal_operation/for_history/train/train"].default_state = self.states["/normal_operation/for_history/train/train/stopped"]
- self.states["/normal_operation/for_history/train/train/stopped"].default_state = self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"]
- self.states["/normal_operation/for_history/GUI_update"].default_state = self.states["/normal_operation/for_history/GUI_update/S_"]
- self.states["/normal_operation/for_history/GUI_update/S_"].default_state = self.states["/normal_operation/for_history/GUI_update/S_/updating"]
- self.states["/normal_operation/for_history/polling"].default_state = self.states["/normal_operation/for_history/polling/S_"]
- self.states["/normal_operation/for_history/polling/S_"].default_state = self.states["/normal_operation/for_history/polling/S_/okay"]
-
- # transition /normal_operation/for_history/train/train/stopped/opened_doors
- _normal_operation_for_history_train_train_stopped_opened_doors_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/opened_doors"], [self.states["/normal_operation/for_history/train/train/stopped/allow_closing"]])
- _normal_operation_for_history_train_train_stopped_opened_doors_0.setTrigger(Event("_0after"))
- self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].addTransition(_normal_operation_for_history_train_train_stopped_opened_doors_0)
-
- # transition /normal_operation/for_history/train/train/stopped/in_station
- _normal_operation_for_history_train_train_stopped_in_station_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/in_station"], [self.states["/normal_operation/for_history/train/train/stopped/opened_doors"]])
- _normal_operation_for_history_train_train_stopped_in_station_0.setAction(self._normal_operation_for_history_train_train_stopped_in_station_0_exec)
- _normal_operation_for_history_train_train_stopped_in_station_0.setTrigger(Event("open", "tkinter_input"))
- self.states["/normal_operation/for_history/train/train/stopped/in_station"].addTransition(_normal_operation_for_history_train_train_stopped_in_station_0)
-
- # transition /normal_operation/for_history/train/train/stopped/allow_closing
- _normal_operation_for_history_train_train_stopped_allow_closing_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/allow_closing"], [self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"]])
- _normal_operation_for_history_train_train_stopped_allow_closing_0.setAction(self._normal_operation_for_history_train_train_stopped_allow_closing_0_exec)
- _normal_operation_for_history_train_train_stopped_allow_closing_0.setTrigger(Event("close", "tkinter_input"))
- self.states["/normal_operation/for_history/train/train/stopped/allow_closing"].addTransition(_normal_operation_for_history_train_train_stopped_allow_closing_0)
-
- # transition /normal_operation/for_history/train/train/stopped/ready_to_leave
- _normal_operation_for_history_train_train_stopped_ready_to_leave_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"], [self.states["/normal_operation/for_history/train/train/driving"]])
- _normal_operation_for_history_train_train_stopped_ready_to_leave_0.setAction(self._normal_operation_for_history_train_train_stopped_ready_to_leave_0_exec)
- _normal_operation_for_history_train_train_stopped_ready_to_leave_0.setTrigger(Event("accel", "tkinter_input"))
- _normal_operation_for_history_train_train_stopped_ready_to_leave_0.setGuard(self._normal_operation_for_history_train_train_stopped_ready_to_leave_0_guard)
- self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"].addTransition(_normal_operation_for_history_train_train_stopped_ready_to_leave_0)
-
- # transition /normal_operation/for_history/train/train/approaching_station
- _normal_operation_for_history_train_train_approaching_station_0 = Transition(self, self.states["/normal_operation/for_history/train/train/approaching_station"], [self.states["/normal_operation/for_history/train/train/stopped/in_station"]])
- _normal_operation_for_history_train_train_approaching_station_0.setTrigger(None)
- _normal_operation_for_history_train_train_approaching_station_0.setGuard(self._normal_operation_for_history_train_train_approaching_station_0_guard)
- self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_0)
- _normal_operation_for_history_train_train_approaching_station_1 = Transition(self, self.states["/normal_operation/for_history/train/train/approaching_station"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
- _normal_operation_for_history_train_train_approaching_station_1.setAction(self._normal_operation_for_history_train_train_approaching_station_1_exec)
- _normal_operation_for_history_train_train_approaching_station_1.setTrigger(Event("accel", "tkinter_input"))
- self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_1)
- _normal_operation_for_history_train_train_approaching_station_2 = Transition(self, self.states["/normal_operation/for_history/train/train/approaching_station"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
- _normal_operation_for_history_train_train_approaching_station_2.setAction(self._normal_operation_for_history_train_train_approaching_station_2_exec)
- _normal_operation_for_history_train_train_approaching_station_2.setTrigger(Event("leave", "tkinter_input"))
- self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_2)
-
- # transition /normal_operation/for_history/train/train/driving
- _normal_operation_for_history_train_train_driving_0 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/max_speed"]])
- _normal_operation_for_history_train_train_driving_0.setTrigger(None)
- _normal_operation_for_history_train_train_driving_0.setGuard(self._normal_operation_for_history_train_train_driving_0_guard)
- self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_0)
- _normal_operation_for_history_train_train_driving_1 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"]])
- _normal_operation_for_history_train_train_driving_1.setTrigger(None)
- _normal_operation_for_history_train_train_driving_1.setGuard(self._normal_operation_for_history_train_train_driving_1_guard)
- self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_1)
- _normal_operation_for_history_train_train_driving_2 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
- _normal_operation_for_history_train_train_driving_2.setTrigger(Event("enter", "tkinter_input"))
- _normal_operation_for_history_train_train_driving_2.setGuard(self._normal_operation_for_history_train_train_driving_2_guard)
- self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_2)
- _normal_operation_for_history_train_train_driving_3 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/driving"]])
- _normal_operation_for_history_train_train_driving_3.setAction(self._normal_operation_for_history_train_train_driving_3_exec)
- _normal_operation_for_history_train_train_driving_3.setTrigger(Event("accel", "tkinter_input"))
- self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_3)
- _normal_operation_for_history_train_train_driving_4 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
- _normal_operation_for_history_train_train_driving_4.setAction(self._normal_operation_for_history_train_train_driving_4_exec)
- _normal_operation_for_history_train_train_driving_4.setTrigger(Event("enter", None))
- _normal_operation_for_history_train_train_driving_4.setGuard(self._normal_operation_for_history_train_train_driving_4_guard)
- self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_4)
-
- # transition /normal_operation/for_history/train/train/max_speed
- _normal_operation_for_history_train_train_max_speed_0 = Transition(self, self.states["/normal_operation/for_history/train/train/max_speed"], [self.states["/normal_operation/for_history/train/train/driving"]])
- _normal_operation_for_history_train_train_max_speed_0.setAction(self._normal_operation_for_history_train_train_max_speed_0_exec)
- _normal_operation_for_history_train_train_max_speed_0.setTrigger(Event("accel", "tkinter_input"))
- _normal_operation_for_history_train_train_max_speed_0.setGuard(self._normal_operation_for_history_train_train_max_speed_0_guard)
- self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_0)
- _normal_operation_for_history_train_train_max_speed_1 = Transition(self, self.states["/normal_operation/for_history/train/train/max_speed"], [self.states["/normal_operation/for_history/train/train/max_speed"]])
- _normal_operation_for_history_train_train_max_speed_1.setAction(self._normal_operation_for_history_train_train_max_speed_1_exec)
- _normal_operation_for_history_train_train_max_speed_1.setTrigger(Event("enter", "tkinter_input"))
- self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_1)
-
- # transition /normal_operation/for_history/GUI_update/S_/updating
- _normal_operation_for_history_GUI_update_S__updating_0 = Transition(self, self.states["/normal_operation/for_history/GUI_update/S_/updating"], [self.states["/normal_operation/for_history/GUI_update/S_/updating"]])
- _normal_operation_for_history_GUI_update_S__updating_0.setAction(self._normal_operation_for_history_GUI_update_S__updating_0_exec)
- _normal_operation_for_history_GUI_update_S__updating_0.setTrigger(Event("_1after"))
- self.states["/normal_operation/for_history/GUI_update/S_/updating"].addTransition(_normal_operation_for_history_GUI_update_S__updating_0)
-
- # transition /normal_operation/for_history/polling/S_/okay
- _normal_operation_for_history_polling_S__okay_0 = Transition(self, self.states["/normal_operation/for_history/polling/S_/okay"], [self.states["/normal_operation/for_history/polling/S_/warn"]])
- _normal_operation_for_history_polling_S__okay_0.setAction(self._normal_operation_for_history_polling_S__okay_0_exec)
- _normal_operation_for_history_polling_S__okay_0.setTrigger(Event("_2after"))
- self.states["/normal_operation/for_history/polling/S_/okay"].addTransition(_normal_operation_for_history_polling_S__okay_0)
-
- # transition /normal_operation/for_history/polling/S_/warn
- _normal_operation_for_history_polling_S__warn_0 = Transition(self, self.states["/normal_operation/for_history/polling/S_/warn"], [self.states["/normal_operation/for_history/polling/S_/okay"]])
- _normal_operation_for_history_polling_S__warn_0.setAction(self._normal_operation_for_history_polling_S__warn_0_exec)
- _normal_operation_for_history_polling_S__warn_0.setTrigger(Event("awake", "tkinter_input"))
- self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_0)
- _normal_operation_for_history_polling_S__warn_1 = Transition(self, self.states["/normal_operation/for_history/polling/S_/warn"], [self.states["/normal_operation/for_history/polling/S_/warn"]])
- _normal_operation_for_history_polling_S__warn_1.setAction(self._normal_operation_for_history_polling_S__warn_1_exec)
- _normal_operation_for_history_polling_S__warn_1.setTrigger(Event("_3after"))
- self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_1)
-
- # transition /emergency_stop
- _emergency_stop_0 = Transition(self, self.states["/emergency_stop"], [self.states["/finished"]])
- _emergency_stop_0.setTrigger(None)
- _emergency_stop_0.setGuard(self._emergency_stop_0_guard)
- self.states["/emergency_stop"].addTransition(_emergency_stop_0)
- _emergency_stop_1 = Transition(self, self.states["/emergency_stop"], [self.states["/emergency_stop"]])
- _emergency_stop_1.setAction(self._emergency_stop_1_exec)
- _emergency_stop_1.setTrigger(Event("_4after"))
- self.states["/emergency_stop"].addTransition(_emergency_stop_1)
-
- # transition /paused
- _paused_0 = Transition(self, self.states["/paused"], [self.states["/normal_operation/H"]])
- _paused_0.setAction(self._paused_0_exec)
- _paused_0.setTrigger(Event("continue", "tkinter_input"))
- self.states["/paused"].addTransition(_paused_0)
-
- # transition /normal_operation
- _normal_operation_0 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
- _normal_operation_0.setAction(self._normal_operation_0_exec)
- _normal_operation_0.setTrigger(Event("red_light", "tkinter_input"))
- self.states["/normal_operation"].addTransition(_normal_operation_0)
- _normal_operation_1 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
- _normal_operation_1.setAction(self._normal_operation_1_exec)
- _normal_operation_1.setTrigger(Event("yellow_light", "tkinter_input"))
- _normal_operation_1.setGuard(self._normal_operation_1_guard)
- self.states["/normal_operation"].addTransition(_normal_operation_1)
- _normal_operation_2 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
- _normal_operation_2.setTrigger(Event("error", None))
- self.states["/normal_operation"].addTransition(_normal_operation_2)
- _normal_operation_3 = Transition(self, self.states["/normal_operation"], [self.states["/paused"]])
- _normal_operation_3.setAction(self._normal_operation_3_exec)
- _normal_operation_3.setTrigger(Event("pause", "tkinter_input"))
- self.states["/normal_operation"].addTransition(_normal_operation_3)
-
- def _normal_operation_for_history_train_train_stopped_enter(self):
- self.speed = 0.0
- self.acceleration = 0.0
-
- def _normal_operation_for_history_train_train_stopped_opened_doors_enter(self):
- self.addTimer(0, 5)
- self.notify("Please wait before closing doors", "white")
-
- def _normal_operation_for_history_train_train_stopped_opened_doors_exit(self):
- self.removeTimer(0)
-
- def _normal_operation_for_history_train_train_stopped_allow_closing_enter(self):
- self.notify("You can now close the doors!", "white")
-
- def _normal_operation_for_history_train_train_max_speed_enter(self):
- self.speed = 120.0
- self.acceleration = 0.0
- print("MAX")
-
- def _normal_operation_for_history_train_train_max_speed_exit(self):
- print("LEAVE MAX")
-
- def _normal_operation_for_history_GUI_update_S__updating_enter(self):
- self.addTimer(1, 0.02)
-
- def _normal_operation_for_history_GUI_update_S__updating_exit(self):
- self.removeTimer(1)
-
- def _normal_operation_for_history_polling_S__okay_enter(self):
- self.addTimer(2, 20.0)
-
- def _normal_operation_for_history_polling_S__okay_exit(self):
- self.removeTimer(2)
-
- def _normal_operation_for_history_polling_S__warn_enter(self):
- self.addTimer(3, 10.0)
-
- def _normal_operation_for_history_polling_S__warn_exit(self):
- self.removeTimer(3)
-
- def _emergency_stop_enter(self):
- self.addTimer(4, 0.02)
- self.acceleration = -1
-
- def _emergency_stop_exit(self):
- self.removeTimer(4)
-
- def _finished_enter(self):
- self.acceleration = 0.0
- self.speed = 0.0
-
- def _normal_operation_0_exec(self, parameters):
- self.notify("Passed red light", "red")
-
- def _normal_operation_1_exec(self, parameters):
- self.notify("Passed yellow light while driving too fast", "red")
-
- def _normal_operation_1_guard(self, parameters):
- return self.speed > 50
-
- def _normal_operation_3_exec(self, parameters):
- self.notify("Paused", "white")
-
- def _normal_operation_for_history_train_train_stopped_in_station_0_exec(self, parameters):
- self.openDoors()
-
- def _normal_operation_for_history_train_train_stopped_allow_closing_0_exec(self, parameters):
- self.closeDoors()
-
- def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_exec(self, parameters):
- value = parameters[0]
- self.acceleration = value
-
- def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_guard(self, parameters):
- value = parameters[0]
- return value > 0
-
- def _normal_operation_for_history_train_train_approaching_station_0_guard(self, parameters):
- return self.speed <= 0
-
- def _normal_operation_for_history_train_train_approaching_station_1_exec(self, parameters):
- value = parameters[0]
- self.acceleration = value
-
- def _normal_operation_for_history_train_train_approaching_station_2_exec(self, parameters):
- self.notify("Left station without stopping", "red")
- self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
-
- def _normal_operation_for_history_train_train_driving_0_guard(self, parameters):
- return self.speed >= 100 and self.acceleration > 0
-
- def _normal_operation_for_history_train_train_driving_1_guard(self, parameters):
- return self.speed <= 0 and self.acceleration < 0
-
- def _normal_operation_for_history_train_train_driving_2_guard(self, parameters):
- return self.speed <= 50
-
- def _normal_operation_for_history_train_train_driving_3_exec(self, parameters):
- value = parameters[0]
- self.acceleration = value
-
- def _normal_operation_for_history_train_train_driving_4_exec(self, parameters):
- self.notify("Entered station too fast", "red")
- self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
-
- def _normal_operation_for_history_train_train_driving_4_guard(self, parameters):
- return self.speed > 50
-
- def _normal_operation_for_history_train_train_max_speed_0_exec(self, parameters):
- value = parameters[0]
- self.acceleration = value
-
- def _normal_operation_for_history_train_train_max_speed_0_guard(self, parameters):
- value = parameters[0]
- return value < 0
-
- def _normal_operation_for_history_train_train_max_speed_1_exec(self, parameters):
- self.notify("Entered station at maximum speed!", "red")
- self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
-
- def _normal_operation_for_history_GUI_update_S__updating_0_exec(self, parameters):
- self.updateState()
-
- def _normal_operation_for_history_polling_S__okay_0_exec(self, parameters):
- self.notify("Please press button!", "yellow")
-
- def _normal_operation_for_history_polling_S__warn_0_exec(self, parameters):
- self.notify("", "gray")
-
- def _normal_operation_for_history_polling_S__warn_1_exec(self, parameters):
- self.notify("Did not press the button in time", "red")
- self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
-
- def _emergency_stop_0_guard(self, parameters):
- return self.speed <= 0
-
- def _emergency_stop_1_exec(self, parameters):
- self.updateState()
-
- def _paused_0_exec(self, parameters):
- self.notify("", "gray")
-
- def initializeStatechart(self):
- # enter default state
- states = self.states["/paused"].getEffectiveTargetStates()
- self.updateConfiguration(states)
- for state in states:
- if state.enter:
- state.enter()
- class ObjectManager(ObjectManagerBase):
- def __init__(self, controller):
- ObjectManagerBase.__init__(self, controller)
-
- def instantiate(self, class_name, construct_params):
- if class_name == "Train":
- instance = Train(self.controller, construct_params[0])
- instance.associations = {}
- else:
- raise Exception("Cannot instantiate class " + class_name)
- return instance
- class Controller(EventLoopControllerBase):
- def __init__(self, root, event_loop_callbacks, finished_callback = None, behind_schedule_callback = None):
- if finished_callback == None: finished_callback = None
- if behind_schedule_callback == None: behind_schedule_callback = None
- EventLoopControllerBase.__init__(self, ObjectManager(self), event_loop_callbacks, finished_callback, behind_schedule_callback)
- self.addInputPort("tkinter_input")
- self.object_manager.createInstance("Train", [root])
|