target.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Fri Aug 05 16:08:37 2016
  4. """
  5. from sccd.runtime.statecharts_core import *
  6. # package ""
  7. class Train(RuntimeClassBase):
  8. def __init__(self, controller, root):
  9. RuntimeClassBase.__init__(self, controller)
  10. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  11. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  12. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  13. self.semantics.priority = StatechartSemantics.SourceChild
  14. self.semantics.concurrency = StatechartSemantics.Single
  15. # build Statechart structure
  16. self.build_statechart_structure()
  17. # call user defined constructor
  18. Train.user_defined_constructor(self, root)
  19. def user_defined_constructor(self, root):
  20. self.root, self.acceleration, self.velocity = root, 0.0, 0.0
  21. self.root.trainIs(self)
  22. def user_defined_destructor(self):
  23. pass
  24. # user defined method
  25. def updateState(self):
  26. self.root.updateState()
  27. # user defined method
  28. def openDoors(self):
  29. self.root.openDoors()
  30. # user defined method
  31. def closeDoors(self):
  32. self.root.closeDoors()
  33. # user defined method
  34. def notify(self, message, color):
  35. self.root.notify(message, color)
  36. # builds Statechart structure
  37. def build_statechart_structure(self):
  38. # state <root>
  39. self.states[""] = State(0, self)
  40. # state /normal_operation
  41. self.states["/normal_operation"] = State(1, self)
  42. # state /normal_operation/for_history
  43. self.states["/normal_operation/for_history"] = ParallelState(2, self)
  44. # state /normal_operation/for_history/train
  45. self.states["/normal_operation/for_history/train"] = State(3, self)
  46. # state /normal_operation/for_history/train/train
  47. self.states["/normal_operation/for_history/train/train"] = State(4, self)
  48. # state /normal_operation/for_history/train/train/stopped
  49. self.states["/normal_operation/for_history/train/train/stopped"] = State(5, self)
  50. self.states["/normal_operation/for_history/train/train/stopped"].setEnter(self._normal_operation_for_history_train_train_stopped_enter)
  51. # state /normal_operation/for_history/train/train/stopped/opened_doors
  52. self.states["/normal_operation/for_history/train/train/stopped/opened_doors"] = State(6, self)
  53. self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].setEnter(self._normal_operation_for_history_train_train_stopped_opened_doors_enter)
  54. self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].setExit(self._normal_operation_for_history_train_train_stopped_opened_doors_exit)
  55. # state /normal_operation/for_history/train/train/stopped/in_station
  56. self.states["/normal_operation/for_history/train/train/stopped/in_station"] = State(7, self)
  57. # state /normal_operation/for_history/train/train/stopped/allow_closing
  58. self.states["/normal_operation/for_history/train/train/stopped/allow_closing"] = State(8, self)
  59. self.states["/normal_operation/for_history/train/train/stopped/allow_closing"].setEnter(self._normal_operation_for_history_train_train_stopped_allow_closing_enter)
  60. # state /normal_operation/for_history/train/train/stopped/ready_to_leave
  61. self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"] = State(9, self)
  62. # state /normal_operation/for_history/train/train/approaching_station
  63. self.states["/normal_operation/for_history/train/train/approaching_station"] = State(10, self)
  64. # state /normal_operation/for_history/train/train/driving
  65. self.states["/normal_operation/for_history/train/train/driving"] = State(11, self)
  66. # state /normal_operation/for_history/train/train/max_speed
  67. self.states["/normal_operation/for_history/train/train/max_speed"] = State(12, self)
  68. self.states["/normal_operation/for_history/train/train/max_speed"].setEnter(self._normal_operation_for_history_train_train_max_speed_enter)
  69. self.states["/normal_operation/for_history/train/train/max_speed"].setExit(self._normal_operation_for_history_train_train_max_speed_exit)
  70. # state /normal_operation/for_history/GUI_update
  71. self.states["/normal_operation/for_history/GUI_update"] = State(13, self)
  72. # state /normal_operation/for_history/GUI_update/S_
  73. self.states["/normal_operation/for_history/GUI_update/S_"] = State(14, self)
  74. # state /normal_operation/for_history/GUI_update/S_/updating
  75. self.states["/normal_operation/for_history/GUI_update/S_/updating"] = State(15, self)
  76. self.states["/normal_operation/for_history/GUI_update/S_/updating"].setEnter(self._normal_operation_for_history_GUI_update_S__updating_enter)
  77. self.states["/normal_operation/for_history/GUI_update/S_/updating"].setExit(self._normal_operation_for_history_GUI_update_S__updating_exit)
  78. # state /normal_operation/for_history/polling
  79. self.states["/normal_operation/for_history/polling"] = State(16, self)
  80. # state /normal_operation/for_history/polling/S_
  81. self.states["/normal_operation/for_history/polling/S_"] = State(17, self)
  82. # state /normal_operation/for_history/polling/S_/okay
  83. self.states["/normal_operation/for_history/polling/S_/okay"] = State(18, self)
  84. self.states["/normal_operation/for_history/polling/S_/okay"].setEnter(self._normal_operation_for_history_polling_S__okay_enter)
  85. self.states["/normal_operation/for_history/polling/S_/okay"].setExit(self._normal_operation_for_history_polling_S__okay_exit)
  86. # state /normal_operation/for_history/polling/S_/warn
  87. self.states["/normal_operation/for_history/polling/S_/warn"] = State(19, self)
  88. self.states["/normal_operation/for_history/polling/S_/warn"].setEnter(self._normal_operation_for_history_polling_S__warn_enter)
  89. self.states["/normal_operation/for_history/polling/S_/warn"].setExit(self._normal_operation_for_history_polling_S__warn_exit)
  90. # state /normal_operation/H
  91. self.states["/normal_operation/H"] = DeepHistoryState(20, self)
  92. # state /emergency_stop
  93. self.states["/emergency_stop"] = State(21, self)
  94. self.states["/emergency_stop"].setEnter(self._emergency_stop_enter)
  95. self.states["/emergency_stop"].setExit(self._emergency_stop_exit)
  96. # state /finished
  97. self.states["/finished"] = State(22, self)
  98. self.states["/finished"].setEnter(self._finished_enter)
  99. # state /paused
  100. self.states["/paused"] = State(23, self)
  101. # add children
  102. self.states[""].addChild(self.states["/normal_operation"])
  103. self.states[""].addChild(self.states["/emergency_stop"])
  104. self.states[""].addChild(self.states["/finished"])
  105. self.states[""].addChild(self.states["/paused"])
  106. self.states["/normal_operation"].addChild(self.states["/normal_operation/for_history"])
  107. self.states["/normal_operation"].addChild(self.states["/normal_operation/H"])
  108. self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/train"])
  109. self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/GUI_update"])
  110. self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/polling"])
  111. self.states["/normal_operation/for_history/train"].addChild(self.states["/normal_operation/for_history/train/train"])
  112. self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/stopped"])
  113. self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/approaching_station"])
  114. self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/driving"])
  115. self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/max_speed"])
  116. self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/opened_doors"])
  117. self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/in_station"])
  118. self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/allow_closing"])
  119. self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"])
  120. self.states["/normal_operation/for_history/GUI_update"].addChild(self.states["/normal_operation/for_history/GUI_update/S_"])
  121. self.states["/normal_operation/for_history/GUI_update/S_"].addChild(self.states["/normal_operation/for_history/GUI_update/S_/updating"])
  122. self.states["/normal_operation/for_history/polling"].addChild(self.states["/normal_operation/for_history/polling/S_"])
  123. self.states["/normal_operation/for_history/polling/S_"].addChild(self.states["/normal_operation/for_history/polling/S_/okay"])
  124. self.states["/normal_operation/for_history/polling/S_"].addChild(self.states["/normal_operation/for_history/polling/S_/warn"])
  125. self.states[""].fixTree()
  126. self.states[""].default_state = self.states["/paused"]
  127. self.states["/normal_operation"].default_state = self.states["/normal_operation/for_history"]
  128. self.states["/normal_operation/for_history/train"].default_state = self.states["/normal_operation/for_history/train/train"]
  129. self.states["/normal_operation/for_history/train/train"].default_state = self.states["/normal_operation/for_history/train/train/stopped"]
  130. self.states["/normal_operation/for_history/train/train/stopped"].default_state = self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"]
  131. self.states["/normal_operation/for_history/GUI_update"].default_state = self.states["/normal_operation/for_history/GUI_update/S_"]
  132. self.states["/normal_operation/for_history/GUI_update/S_"].default_state = self.states["/normal_operation/for_history/GUI_update/S_/updating"]
  133. self.states["/normal_operation/for_history/polling"].default_state = self.states["/normal_operation/for_history/polling/S_"]
  134. self.states["/normal_operation/for_history/polling/S_"].default_state = self.states["/normal_operation/for_history/polling/S_/okay"]
  135. # transition /normal_operation/for_history/train/train/stopped/opened_doors
  136. _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"]])
  137. _normal_operation_for_history_train_train_stopped_opened_doors_0.setTrigger(Event("_0after"))
  138. self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].addTransition(_normal_operation_for_history_train_train_stopped_opened_doors_0)
  139. # transition /normal_operation/for_history/train/train/stopped/in_station
  140. _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"]])
  141. _normal_operation_for_history_train_train_stopped_in_station_0.setAction(self._normal_operation_for_history_train_train_stopped_in_station_0_exec)
  142. _normal_operation_for_history_train_train_stopped_in_station_0.setTrigger(Event("open", "tkinter_input"))
  143. self.states["/normal_operation/for_history/train/train/stopped/in_station"].addTransition(_normal_operation_for_history_train_train_stopped_in_station_0)
  144. # transition /normal_operation/for_history/train/train/stopped/allow_closing
  145. _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"]])
  146. _normal_operation_for_history_train_train_stopped_allow_closing_0.setAction(self._normal_operation_for_history_train_train_stopped_allow_closing_0_exec)
  147. _normal_operation_for_history_train_train_stopped_allow_closing_0.setTrigger(Event("close", "tkinter_input"))
  148. self.states["/normal_operation/for_history/train/train/stopped/allow_closing"].addTransition(_normal_operation_for_history_train_train_stopped_allow_closing_0)
  149. # transition /normal_operation/for_history/train/train/stopped/ready_to_leave
  150. _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"]])
  151. _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)
  152. _normal_operation_for_history_train_train_stopped_ready_to_leave_0.setTrigger(Event("accel", "tkinter_input"))
  153. _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)
  154. self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"].addTransition(_normal_operation_for_history_train_train_stopped_ready_to_leave_0)
  155. # transition /normal_operation/for_history/train/train/approaching_station
  156. _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"]])
  157. _normal_operation_for_history_train_train_approaching_station_0.setTrigger(None)
  158. _normal_operation_for_history_train_train_approaching_station_0.setGuard(self._normal_operation_for_history_train_train_approaching_station_0_guard)
  159. self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_0)
  160. _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"]])
  161. _normal_operation_for_history_train_train_approaching_station_1.setAction(self._normal_operation_for_history_train_train_approaching_station_1_exec)
  162. _normal_operation_for_history_train_train_approaching_station_1.setTrigger(Event("accel", "tkinter_input"))
  163. self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_1)
  164. _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"]])
  165. _normal_operation_for_history_train_train_approaching_station_2.setAction(self._normal_operation_for_history_train_train_approaching_station_2_exec)
  166. _normal_operation_for_history_train_train_approaching_station_2.setTrigger(Event("leave", "tkinter_input"))
  167. self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_2)
  168. # transition /normal_operation/for_history/train/train/driving
  169. _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"]])
  170. _normal_operation_for_history_train_train_driving_0.setTrigger(None)
  171. _normal_operation_for_history_train_train_driving_0.setGuard(self._normal_operation_for_history_train_train_driving_0_guard)
  172. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_0)
  173. _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"]])
  174. _normal_operation_for_history_train_train_driving_1.setTrigger(None)
  175. _normal_operation_for_history_train_train_driving_1.setGuard(self._normal_operation_for_history_train_train_driving_1_guard)
  176. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_1)
  177. _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"]])
  178. _normal_operation_for_history_train_train_driving_2.setTrigger(Event("enter", "tkinter_input"))
  179. _normal_operation_for_history_train_train_driving_2.setGuard(self._normal_operation_for_history_train_train_driving_2_guard)
  180. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_2)
  181. _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"]])
  182. _normal_operation_for_history_train_train_driving_3.setAction(self._normal_operation_for_history_train_train_driving_3_exec)
  183. _normal_operation_for_history_train_train_driving_3.setTrigger(Event("accel", "tkinter_input"))
  184. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_3)
  185. _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"]])
  186. _normal_operation_for_history_train_train_driving_4.setAction(self._normal_operation_for_history_train_train_driving_4_exec)
  187. _normal_operation_for_history_train_train_driving_4.setTrigger(Event("enter", None))
  188. _normal_operation_for_history_train_train_driving_4.setGuard(self._normal_operation_for_history_train_train_driving_4_guard)
  189. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_4)
  190. # transition /normal_operation/for_history/train/train/max_speed
  191. _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"]])
  192. _normal_operation_for_history_train_train_max_speed_0.setAction(self._normal_operation_for_history_train_train_max_speed_0_exec)
  193. _normal_operation_for_history_train_train_max_speed_0.setTrigger(Event("accel", "tkinter_input"))
  194. _normal_operation_for_history_train_train_max_speed_0.setGuard(self._normal_operation_for_history_train_train_max_speed_0_guard)
  195. self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_0)
  196. _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"]])
  197. _normal_operation_for_history_train_train_max_speed_1.setAction(self._normal_operation_for_history_train_train_max_speed_1_exec)
  198. _normal_operation_for_history_train_train_max_speed_1.setTrigger(Event("enter", "tkinter_input"))
  199. self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_1)
  200. # transition /normal_operation/for_history/GUI_update/S_/updating
  201. _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"]])
  202. _normal_operation_for_history_GUI_update_S__updating_0.setAction(self._normal_operation_for_history_GUI_update_S__updating_0_exec)
  203. _normal_operation_for_history_GUI_update_S__updating_0.setTrigger(Event("_1after"))
  204. self.states["/normal_operation/for_history/GUI_update/S_/updating"].addTransition(_normal_operation_for_history_GUI_update_S__updating_0)
  205. # transition /normal_operation/for_history/polling/S_/okay
  206. _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"]])
  207. _normal_operation_for_history_polling_S__okay_0.setAction(self._normal_operation_for_history_polling_S__okay_0_exec)
  208. _normal_operation_for_history_polling_S__okay_0.setTrigger(Event("_2after"))
  209. self.states["/normal_operation/for_history/polling/S_/okay"].addTransition(_normal_operation_for_history_polling_S__okay_0)
  210. # transition /normal_operation/for_history/polling/S_/warn
  211. _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"]])
  212. _normal_operation_for_history_polling_S__warn_0.setAction(self._normal_operation_for_history_polling_S__warn_0_exec)
  213. _normal_operation_for_history_polling_S__warn_0.setTrigger(Event("awake", "tkinter_input"))
  214. self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_0)
  215. _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"]])
  216. _normal_operation_for_history_polling_S__warn_1.setAction(self._normal_operation_for_history_polling_S__warn_1_exec)
  217. _normal_operation_for_history_polling_S__warn_1.setTrigger(Event("_3after"))
  218. self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_1)
  219. # transition /emergency_stop
  220. _emergency_stop_0 = Transition(self, self.states["/emergency_stop"], [self.states["/finished"]])
  221. _emergency_stop_0.setTrigger(None)
  222. _emergency_stop_0.setGuard(self._emergency_stop_0_guard)
  223. self.states["/emergency_stop"].addTransition(_emergency_stop_0)
  224. _emergency_stop_1 = Transition(self, self.states["/emergency_stop"], [self.states["/emergency_stop"]])
  225. _emergency_stop_1.setAction(self._emergency_stop_1_exec)
  226. _emergency_stop_1.setTrigger(Event("_4after"))
  227. self.states["/emergency_stop"].addTransition(_emergency_stop_1)
  228. # transition /paused
  229. _paused_0 = Transition(self, self.states["/paused"], [self.states["/normal_operation/H"]])
  230. _paused_0.setAction(self._paused_0_exec)
  231. _paused_0.setTrigger(Event("continue", "tkinter_input"))
  232. self.states["/paused"].addTransition(_paused_0)
  233. # transition /normal_operation
  234. _normal_operation_0 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
  235. _normal_operation_0.setAction(self._normal_operation_0_exec)
  236. _normal_operation_0.setTrigger(Event("red_light", "tkinter_input"))
  237. self.states["/normal_operation"].addTransition(_normal_operation_0)
  238. _normal_operation_1 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
  239. _normal_operation_1.setAction(self._normal_operation_1_exec)
  240. _normal_operation_1.setTrigger(Event("yellow_light", "tkinter_input"))
  241. _normal_operation_1.setGuard(self._normal_operation_1_guard)
  242. self.states["/normal_operation"].addTransition(_normal_operation_1)
  243. _normal_operation_2 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
  244. _normal_operation_2.setTrigger(Event("error", None))
  245. self.states["/normal_operation"].addTransition(_normal_operation_2)
  246. _normal_operation_3 = Transition(self, self.states["/normal_operation"], [self.states["/paused"]])
  247. _normal_operation_3.setAction(self._normal_operation_3_exec)
  248. _normal_operation_3.setTrigger(Event("pause", "tkinter_input"))
  249. self.states["/normal_operation"].addTransition(_normal_operation_3)
  250. def _normal_operation_for_history_train_train_stopped_enter(self):
  251. self.speed = 0.0
  252. self.acceleration = 0.0
  253. def _normal_operation_for_history_train_train_stopped_opened_doors_enter(self):
  254. self.addTimer(0, 5)
  255. self.notify("Please wait before closing doors", "white")
  256. def _normal_operation_for_history_train_train_stopped_opened_doors_exit(self):
  257. self.removeTimer(0)
  258. def _normal_operation_for_history_train_train_stopped_allow_closing_enter(self):
  259. self.notify("You can now close the doors!", "white")
  260. def _normal_operation_for_history_train_train_max_speed_enter(self):
  261. self.speed = 120.0
  262. self.acceleration = 0.0
  263. print("MAX")
  264. def _normal_operation_for_history_train_train_max_speed_exit(self):
  265. print("LEAVE MAX")
  266. def _normal_operation_for_history_GUI_update_S__updating_enter(self):
  267. self.addTimer(1, 0.02)
  268. def _normal_operation_for_history_GUI_update_S__updating_exit(self):
  269. self.removeTimer(1)
  270. def _normal_operation_for_history_polling_S__okay_enter(self):
  271. self.addTimer(2, 20.0)
  272. def _normal_operation_for_history_polling_S__okay_exit(self):
  273. self.removeTimer(2)
  274. def _normal_operation_for_history_polling_S__warn_enter(self):
  275. self.addTimer(3, 10.0)
  276. def _normal_operation_for_history_polling_S__warn_exit(self):
  277. self.removeTimer(3)
  278. def _emergency_stop_enter(self):
  279. self.addTimer(4, 0.02)
  280. self.acceleration = -1
  281. def _emergency_stop_exit(self):
  282. self.removeTimer(4)
  283. def _finished_enter(self):
  284. self.acceleration = 0.0
  285. self.speed = 0.0
  286. def _normal_operation_0_exec(self, parameters):
  287. self.notify("Passed red light", "red")
  288. def _normal_operation_1_exec(self, parameters):
  289. self.notify("Passed yellow light while driving too fast", "red")
  290. def _normal_operation_1_guard(self, parameters):
  291. return self.speed > 50
  292. def _normal_operation_3_exec(self, parameters):
  293. self.notify("Paused", "white")
  294. def _normal_operation_for_history_train_train_stopped_in_station_0_exec(self, parameters):
  295. self.openDoors()
  296. def _normal_operation_for_history_train_train_stopped_allow_closing_0_exec(self, parameters):
  297. self.closeDoors()
  298. def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_exec(self, parameters):
  299. value = parameters[0]
  300. self.acceleration = value
  301. def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_guard(self, parameters):
  302. value = parameters[0]
  303. return value > 0
  304. def _normal_operation_for_history_train_train_approaching_station_0_guard(self, parameters):
  305. return self.speed <= 0
  306. def _normal_operation_for_history_train_train_approaching_station_1_exec(self, parameters):
  307. value = parameters[0]
  308. self.acceleration = value
  309. def _normal_operation_for_history_train_train_approaching_station_2_exec(self, parameters):
  310. self.notify("Left station without stopping", "red")
  311. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  312. def _normal_operation_for_history_train_train_driving_0_guard(self, parameters):
  313. return self.speed >= 100 and self.acceleration > 0
  314. def _normal_operation_for_history_train_train_driving_1_guard(self, parameters):
  315. return self.speed <= 0 and self.acceleration < 0
  316. def _normal_operation_for_history_train_train_driving_2_guard(self, parameters):
  317. return self.speed <= 50
  318. def _normal_operation_for_history_train_train_driving_3_exec(self, parameters):
  319. value = parameters[0]
  320. self.acceleration = value
  321. def _normal_operation_for_history_train_train_driving_4_exec(self, parameters):
  322. self.notify("Entered station too fast", "red")
  323. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  324. def _normal_operation_for_history_train_train_driving_4_guard(self, parameters):
  325. return self.speed > 50
  326. def _normal_operation_for_history_train_train_max_speed_0_exec(self, parameters):
  327. value = parameters[0]
  328. self.acceleration = value
  329. def _normal_operation_for_history_train_train_max_speed_0_guard(self, parameters):
  330. value = parameters[0]
  331. return value < 0
  332. def _normal_operation_for_history_train_train_max_speed_1_exec(self, parameters):
  333. self.notify("Entered station at maximum speed!", "red")
  334. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  335. def _normal_operation_for_history_GUI_update_S__updating_0_exec(self, parameters):
  336. self.updateState()
  337. def _normal_operation_for_history_polling_S__okay_0_exec(self, parameters):
  338. self.notify("Please press button!", "yellow")
  339. def _normal_operation_for_history_polling_S__warn_0_exec(self, parameters):
  340. self.notify("", "gray")
  341. def _normal_operation_for_history_polling_S__warn_1_exec(self, parameters):
  342. self.notify("Did not press the button in time", "red")
  343. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  344. def _emergency_stop_0_guard(self, parameters):
  345. return self.speed <= 0
  346. def _emergency_stop_1_exec(self, parameters):
  347. self.updateState()
  348. def _paused_0_exec(self, parameters):
  349. self.notify("", "gray")
  350. def initializeStatechart(self):
  351. # enter default state
  352. states = self.states["/paused"].getEffectiveTargetStates()
  353. self.updateConfiguration(states)
  354. for state in states:
  355. if state.enter:
  356. state.enter()
  357. class ObjectManager(ObjectManagerBase):
  358. def __init__(self, controller):
  359. ObjectManagerBase.__init__(self, controller)
  360. def instantiate(self, class_name, construct_params):
  361. if class_name == "Train":
  362. instance = Train(self.controller, construct_params[0])
  363. instance.associations = {}
  364. else:
  365. raise Exception("Cannot instantiate class " + class_name)
  366. return instance
  367. class Controller(EventLoopControllerBase):
  368. def __init__(self, root, event_loop_callbacks, finished_callback = None, behind_schedule_callback = None):
  369. if finished_callback == None: finished_callback = None
  370. if behind_schedule_callback == None: behind_schedule_callback = None
  371. EventLoopControllerBase.__init__(self, ObjectManager(self), event_loop_callbacks, finished_callback, behind_schedule_callback)
  372. self.addInputPort("tkinter_input")
  373. self.object_manager.createInstance("Train", [root])