target.py 33 KB

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