target.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Thu Aug 04 13:29:24 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.trigger = 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.trigger = 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.trigger = 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.trigger = 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.setGuard(self._normal_operation_for_history_train_train_approaching_station_0_guard)
  158. self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_0)
  159. _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"]])
  160. _normal_operation_for_history_train_train_approaching_station_1.setAction(self._normal_operation_for_history_train_train_approaching_station_1_exec)
  161. _normal_operation_for_history_train_train_approaching_station_1.trigger = Event("accel", "tkinter_input")
  162. self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_1)
  163. _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"]])
  164. _normal_operation_for_history_train_train_approaching_station_2.setAction(self._normal_operation_for_history_train_train_approaching_station_2_exec)
  165. _normal_operation_for_history_train_train_approaching_station_2.trigger = Event("leave", "tkinter_input")
  166. self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_2)
  167. # transition /normal_operation/for_history/train/train/driving
  168. _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"]])
  169. _normal_operation_for_history_train_train_driving_0.setGuard(self._normal_operation_for_history_train_train_driving_0_guard)
  170. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_0)
  171. _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"]])
  172. _normal_operation_for_history_train_train_driving_1.setGuard(self._normal_operation_for_history_train_train_driving_1_guard)
  173. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_1)
  174. _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"]])
  175. _normal_operation_for_history_train_train_driving_2.trigger = Event("enter", "tkinter_input")
  176. _normal_operation_for_history_train_train_driving_2.setGuard(self._normal_operation_for_history_train_train_driving_2_guard)
  177. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_2)
  178. _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"]])
  179. _normal_operation_for_history_train_train_driving_3.setAction(self._normal_operation_for_history_train_train_driving_3_exec)
  180. _normal_operation_for_history_train_train_driving_3.trigger = Event("accel", "tkinter_input")
  181. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_3)
  182. _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"]])
  183. _normal_operation_for_history_train_train_driving_4.setAction(self._normal_operation_for_history_train_train_driving_4_exec)
  184. _normal_operation_for_history_train_train_driving_4.trigger = Event("enter", None)
  185. _normal_operation_for_history_train_train_driving_4.setGuard(self._normal_operation_for_history_train_train_driving_4_guard)
  186. self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_4)
  187. # transition /normal_operation/for_history/train/train/max_speed
  188. _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"]])
  189. _normal_operation_for_history_train_train_max_speed_0.setAction(self._normal_operation_for_history_train_train_max_speed_0_exec)
  190. _normal_operation_for_history_train_train_max_speed_0.trigger = Event("accel", "tkinter_input")
  191. _normal_operation_for_history_train_train_max_speed_0.setGuard(self._normal_operation_for_history_train_train_max_speed_0_guard)
  192. self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_0)
  193. _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"]])
  194. _normal_operation_for_history_train_train_max_speed_1.setAction(self._normal_operation_for_history_train_train_max_speed_1_exec)
  195. _normal_operation_for_history_train_train_max_speed_1.trigger = Event("enter", "tkinter_input")
  196. self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_1)
  197. # transition /normal_operation/for_history/GUI_update/S_/updating
  198. _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"]])
  199. _normal_operation_for_history_GUI_update_S__updating_0.setAction(self._normal_operation_for_history_GUI_update_S__updating_0_exec)
  200. _normal_operation_for_history_GUI_update_S__updating_0.trigger = Event("_1after")
  201. self.states["/normal_operation/for_history/GUI_update/S_/updating"].addTransition(_normal_operation_for_history_GUI_update_S__updating_0)
  202. # transition /normal_operation/for_history/polling/S_/okay
  203. _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"]])
  204. _normal_operation_for_history_polling_S__okay_0.setAction(self._normal_operation_for_history_polling_S__okay_0_exec)
  205. _normal_operation_for_history_polling_S__okay_0.trigger = Event("_2after")
  206. self.states["/normal_operation/for_history/polling/S_/okay"].addTransition(_normal_operation_for_history_polling_S__okay_0)
  207. # transition /normal_operation/for_history/polling/S_/warn
  208. _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"]])
  209. _normal_operation_for_history_polling_S__warn_0.setAction(self._normal_operation_for_history_polling_S__warn_0_exec)
  210. _normal_operation_for_history_polling_S__warn_0.trigger = Event("awake", "tkinter_input")
  211. self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_0)
  212. _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"]])
  213. _normal_operation_for_history_polling_S__warn_1.setAction(self._normal_operation_for_history_polling_S__warn_1_exec)
  214. _normal_operation_for_history_polling_S__warn_1.trigger = Event("_3after")
  215. self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_1)
  216. # transition /emergency_stop
  217. _emergency_stop_0 = Transition(self, self.states["/emergency_stop"], [self.states["/finished"]])
  218. _emergency_stop_0.setGuard(self._emergency_stop_0_guard)
  219. self.states["/emergency_stop"].addTransition(_emergency_stop_0)
  220. _emergency_stop_1 = Transition(self, self.states["/emergency_stop"], [self.states["/emergency_stop"]])
  221. _emergency_stop_1.setAction(self._emergency_stop_1_exec)
  222. _emergency_stop_1.trigger = Event("_4after")
  223. self.states["/emergency_stop"].addTransition(_emergency_stop_1)
  224. # transition /paused
  225. _paused_0 = Transition(self, self.states["/paused"], [self.states["/normal_operation/H"]])
  226. _paused_0.setAction(self._paused_0_exec)
  227. _paused_0.trigger = Event("continue", "tkinter_input")
  228. self.states["/paused"].addTransition(_paused_0)
  229. # transition /normal_operation
  230. _normal_operation_0 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
  231. _normal_operation_0.setAction(self._normal_operation_0_exec)
  232. _normal_operation_0.trigger = Event("red_light", "tkinter_input")
  233. self.states["/normal_operation"].addTransition(_normal_operation_0)
  234. _normal_operation_1 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
  235. _normal_operation_1.setAction(self._normal_operation_1_exec)
  236. _normal_operation_1.trigger = Event("yellow_light", "tkinter_input")
  237. _normal_operation_1.setGuard(self._normal_operation_1_guard)
  238. self.states["/normal_operation"].addTransition(_normal_operation_1)
  239. _normal_operation_2 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
  240. _normal_operation_2.trigger = Event("error", None)
  241. self.states["/normal_operation"].addTransition(_normal_operation_2)
  242. _normal_operation_3 = Transition(self, self.states["/normal_operation"], [self.states["/paused"]])
  243. _normal_operation_3.setAction(self._normal_operation_3_exec)
  244. _normal_operation_3.trigger = Event("pause", "tkinter_input")
  245. self.states["/normal_operation"].addTransition(_normal_operation_3)
  246. def _normal_operation_for_history_train_train_stopped_enter(self):
  247. self.speed = 0.0
  248. self.acceleration = 0.0
  249. def _normal_operation_for_history_train_train_stopped_opened_doors_enter(self):
  250. self.addTimer(0, 5)
  251. self.notify("Please wait before closing doors", "white")
  252. def _normal_operation_for_history_train_train_stopped_opened_doors_exit(self):
  253. self.removeTimer(0)
  254. def _normal_operation_for_history_train_train_stopped_allow_closing_enter(self):
  255. self.notify("You can now close the doors!", "white")
  256. def _normal_operation_for_history_train_train_max_speed_enter(self):
  257. self.speed = 120.0
  258. self.acceleration = 0.0
  259. print("MAX")
  260. def _normal_operation_for_history_train_train_max_speed_exit(self):
  261. print("LEAVE MAX")
  262. def _normal_operation_for_history_GUI_update_S__updating_enter(self):
  263. self.addTimer(1, 0.02)
  264. def _normal_operation_for_history_GUI_update_S__updating_exit(self):
  265. self.removeTimer(1)
  266. def _normal_operation_for_history_polling_S__okay_enter(self):
  267. self.addTimer(2, 20.0)
  268. def _normal_operation_for_history_polling_S__okay_exit(self):
  269. self.removeTimer(2)
  270. def _normal_operation_for_history_polling_S__warn_enter(self):
  271. self.addTimer(3, 10.0)
  272. def _normal_operation_for_history_polling_S__warn_exit(self):
  273. self.removeTimer(3)
  274. def _emergency_stop_enter(self):
  275. self.addTimer(4, 0.02)
  276. self.acceleration = -1
  277. def _emergency_stop_exit(self):
  278. self.removeTimer(4)
  279. def _finished_enter(self):
  280. self.acceleration = 0.0
  281. self.speed = 0.0
  282. def _normal_operation_0_exec(self, parameters):
  283. self.notify("Passed red light", "red")
  284. def _normal_operation_1_exec(self, parameters):
  285. self.notify("Passed yellow light while driving too fast", "red")
  286. def _normal_operation_1_guard(self, parameters):
  287. return self.speed > 50
  288. def _normal_operation_3_exec(self, parameters):
  289. self.notify("Paused", "white")
  290. def _normal_operation_for_history_train_train_stopped_in_station_0_exec(self, parameters):
  291. self.openDoors()
  292. def _normal_operation_for_history_train_train_stopped_allow_closing_0_exec(self, parameters):
  293. self.closeDoors()
  294. def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_exec(self, parameters):
  295. value = parameters[0]
  296. self.acceleration = value
  297. def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_guard(self, parameters):
  298. value = parameters[0]
  299. return value > 0
  300. def _normal_operation_for_history_train_train_approaching_station_0_guard(self, parameters):
  301. return self.speed <= 0
  302. def _normal_operation_for_history_train_train_approaching_station_1_exec(self, parameters):
  303. value = parameters[0]
  304. self.acceleration = value
  305. def _normal_operation_for_history_train_train_approaching_station_2_exec(self, parameters):
  306. self.notify("Left station without stopping", "red")
  307. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  308. def _normal_operation_for_history_train_train_driving_0_guard(self, parameters):
  309. return self.speed >= 100 and self.acceleration > 0
  310. def _normal_operation_for_history_train_train_driving_1_guard(self, parameters):
  311. return self.speed <= 0 and self.acceleration < 0
  312. def _normal_operation_for_history_train_train_driving_2_guard(self, parameters):
  313. return self.speed <= 50
  314. def _normal_operation_for_history_train_train_driving_3_exec(self, parameters):
  315. value = parameters[0]
  316. self.acceleration = value
  317. def _normal_operation_for_history_train_train_driving_4_exec(self, parameters):
  318. self.notify("Entered station too fast", "red")
  319. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  320. def _normal_operation_for_history_train_train_driving_4_guard(self, parameters):
  321. return self.speed > 50
  322. def _normal_operation_for_history_train_train_max_speed_0_exec(self, parameters):
  323. value = parameters[0]
  324. self.acceleration = value
  325. def _normal_operation_for_history_train_train_max_speed_0_guard(self, parameters):
  326. value = parameters[0]
  327. return value < 0
  328. def _normal_operation_for_history_train_train_max_speed_1_exec(self, parameters):
  329. self.notify("Entered station at maximum speed!", "red")
  330. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  331. def _normal_operation_for_history_GUI_update_S__updating_0_exec(self, parameters):
  332. self.updateState()
  333. def _normal_operation_for_history_polling_S__okay_0_exec(self, parameters):
  334. self.notify("Please press button!", "yellow")
  335. def _normal_operation_for_history_polling_S__warn_0_exec(self, parameters):
  336. self.notify("", "gray")
  337. def _normal_operation_for_history_polling_S__warn_1_exec(self, parameters):
  338. self.notify("Did not press the button in time", "red")
  339. self.big_step.outputEventOM(Event("broad_cast", None, [Event("error", None, [])]))
  340. def _emergency_stop_0_guard(self, parameters):
  341. return self.speed <= 0
  342. def _emergency_stop_1_exec(self, parameters):
  343. self.updateState()
  344. def _paused_0_exec(self, parameters):
  345. self.notify("", "gray")
  346. def initializeStatechart(self):
  347. # enter default state
  348. states = self.states["/paused"].getEffectiveTargetStates()
  349. self.updateConfiguration(states)
  350. for state in states:
  351. if state.enter:
  352. state.enter()
  353. class ObjectManager(ObjectManagerBase):
  354. def __init__(self, controller):
  355. ObjectManagerBase.__init__(self, controller)
  356. def instantiate(self, class_name, construct_params):
  357. if class_name == "Train":
  358. instance = Train(self.controller, construct_params[0])
  359. instance.associations = {}
  360. else:
  361. raise Exception("Cannot instantiate class " + class_name)
  362. return instance
  363. class Controller(EventLoopControllerBase):
  364. def __init__(self, root, event_loop_callbacks, finished_callback = None):
  365. if finished_callback == None: finished_callback = None
  366. EventLoopControllerBase.__init__(self, ObjectManager(self), event_loop_callbacks, finished_callback)
  367. self.addInputPort("tkinter_input")
  368. self.object_manager.createInstance("Train", [root])