summaryrefslogtreecommitdiff
path: root/digital/io/src/top.fsm
blob: bf6ad98395b9a3d1e920cae826108fd77e4dcee0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# Top FSM.
top
  Main FSM calling other FSM.

States:
 IDLE
  waiting for the beginning of the top FSM.
 WAIT_INIT_TO_FINISH
  waiting for the end of init.
 GET_PUCK_FROM_THE_GROUND [timeout=1575]
  get some pucks from the ground.
 GET_PUCK_FROM_DISTRIBUTOR
  get some pucks from the distributor.
 STOP_TO_GO_TO_UNLOAD_AREA
  stop the move FSM before starting a new one.
 STOP_TO_GET_PUCK_FROM_DISTRIBUTOR
  stop the move FSM before starting a new one.
 GO_TO_UNLOAD_AREA
  when going to unload area.
 FUCK_UNLOAD_AREA
  when going backward in position for unload.
 UNLOAD_PUCKS [timeout=1125]
  when unloading all pucks from the bot.
 ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD [timeout=1125]
  wait for the elevator to be ready for a bot movement.
 GO_AWAY_TO_RETRY_UNLOAD
  when unload failed, go away from the unload area to try a new one.
 TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD
  try again to go away to retry unloading pucks.
 FUCK_THE_DISTRIBUTOR
  fuck the distributor.
 WAIT_FOR_PUCKS [timeout=1575]
  wait until no more pucks or already full.
 GO_AWAY_FROM_UNLOAD_AREA
  go away from the unload area to turn freely.
 TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA
  try again to go away from the unload area.
 CLEAN_FRONT_OF_DISTRIBUTOR
  clean the front of the distributor to have no problem to fuck it.
 GO_AWAY_FROM_DISTRIBUTOR
  to correctly leave a distributor, we need to do a linear move.
 TRY_AGAIN_TO_GO_AWAY_FROM_DISTRIBUTOR
  try again to go away from the distributor.
 PREPARE_ELEVATOR [timeout=2250]
  prepare the elevator for unload.

Events:
 start
  initialize the FSM.
 move_fsm_succeed
  when the move FSM returns with success.
 move_fsm_failed
  when the move FSM returns with an error.
 move_fsm_stopped
  when the move FSM has stop the bot (as asked).
 bot_move_succeed
  when the bot has succeed its asserv movement.
 bot_move_failed
  when the bot has failed its asserv movement.
 init_match_is_started
  when the init FSM has finished and the match start.
 state_timeout
  timeout in cycle count.
 asserv_last_cmd_ack
  last command sent to the asserv board has been acquitted.
 bot_is_full_of_pucks
  the bot has four pucks inside.
 empty_distributor
  the cylinder has tried to get some pucks but none has been seen.
 elevator_order_done
  the elevator has executed my order (go up, open door, close door).

IDLE:
 start -> WAIT_INIT_TO_FINISH
  nothing to do.

WAIT_INIT_TO_FINISH:
 init_match_is_started -> GET_PUCK_FROM_THE_GROUND
  the match start, try to get some puck from the ground.

GET_PUCK_FROM_THE_GROUND:
 move_fsm_succeed: already_six_pucks_or_no_next_position -> GET_PUCK_FROM_DISTRIBUTOR
  close cylinder.
  get the next distributor position and launch move FSM to go there.
 move_fsm_succeed: next_position_exists -> .
  go to the next position using move FSM.
 move_fsm_failed -> STOP_TO_GO_TO_UNLOAD_AREA
  close cylinder.
  we have failed to do a move, go the distributor (get next distributor and go
  there with move FSM).
 bot_is_full_of_pucks -> STOP_TO_GO_TO_UNLOAD_AREA
  stop move FSM.
 state_timeout -> STOP_TO_GET_PUCK_FROM_DISTRIBUTOR
  close cylinder.
  too much time lost to get puck from the ground, stop move FSM.

STOP_TO_GET_PUCK_FROM_DISTRIBUTOR:
 move_fsm_stopped -> GET_PUCK_FROM_DISTRIBUTOR
  get next distributor and go there.

STOP_TO_GO_TO_UNLOAD_AREA:
 move_fsm_stopped -> GO_TO_UNLOAD_AREA
  compute an unload area.
  ask move FSM to go there using backward move only.
 move_fsm_succeed -> GO_TO_UNLOAD_AREA
  do the same as bot_move_stopped.
 bot_move_failed -> GO_TO_UNLOAD_AREA
  do the same as bot_move_stopped.

GO_TO_UNLOAD_AREA:
 move_fsm_succeed -> PREPARE_ELEVATOR
  prepare the elevator.
# It can be dangerous to loop here with no condition to cancel this loop.
 move_fsm_failed -> .
  compute a new unload area.
  ask move FSM to go to the position using backward only.

PREPARE_ELEVATOR:
 elevator_order_done -> FUCK_UNLOAD_AREA
  make the bot do a fuck the wall in backward until blocked.
 state_timeout -> GO_TO_UNLOAD_AREA
  compute a new unload area and retry.

FUCK_UNLOAD_AREA:
 bot_move_succeed -> UNLOAD_PUCKS
  unload all the pucks from the elevator.
 bot_move_failed -> GO_AWAY_TO_RETRY_UNLOAD
  move backward from the unload area using linear move.

GO_AWAY_TO_RETRY_UNLOAD:
 bot_move_succeed -> GO_TO_UNLOAD_AREA
  compute a new unload area.
  ask move FSM to go there using backward move only.
 bot_move_failed: niceness -> TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD
  decrement niceness.
  move forward using linear move.
 bot_move_failed: no_more_niceness -> GO_TO_UNLOAD_AREA
  do the same as move succeed.

TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD:
 bot_move_succeed -> GO_AWAY_TO_RETRY_UNLOAD
  move backward from the unload area using linear move.
 bot_move_failed -> GO_AWAY_TO_RETRY_UNLOAD
  do the same as succeed.

GET_PUCK_FROM_DISTRIBUTOR:
 move_fsm_succeed -> CLEAN_FRONT_OF_DISTRIBUTOR
  really go to the front of the distributor (it clean front area).
 move_fsm_failed: no_puck_or_still_time -> .
  get the next distributor position and launch move FSM to go there.
 move_fsm_failed: some_pucks_and_no_more_time -> GO_TO_UNLOAD_AREA
  compute an unload area.
  ask move FSM to go there.

CLEAN_FRONT_OF_DISTRIBUTOR:
 move_fsm_succeed -> FUCK_THE_DISTRIBUTOR
  we are in front of the distributor: fuck it.
 move_fsm_failed -> GET_PUCK_FROM_DISTRIBUTOR
  get a new distributor and go there.

FUCK_THE_DISTRIBUTOR:
 bot_move_succeed -> WAIT_FOR_PUCKS
  let's cylinder FSM works until finished.
 bot_move_failed: no_puck_or_still_time -> GET_PUCK_FROM_DISTRIBUTOR
  get a new distributor and go there.
 bot_move_failed: some_pucks_and_no_more_time -> GO_TO_UNLOAD_AREA
  compute an unload area.
  ask move FSM to go there.

WAIT_FOR_PUCKS:
 bot_is_full_of_pucks -> GO_AWAY_FROM_DISTRIBUTOR
  remember unload area.
 empty_distributor: no_puck_or_still_time -> GO_AWAY_FROM_DISTRIBUTOR
  remember distributor.
 empty_distributor: some_pucks_and_no_more_time -> GO_AWAY_FROM_DISTRIBUTOR
  remember unload area.
 state_timeout: no_puck_or_still_time -> GO_AWAY_FROM_DISTRIBUTOR
  remember distributor.
 state_timeout: some_pucks_and_no_more_time -> GO_AWAY_FROM_DISTRIBUTOR
  remember unload area.

GO_AWAY_FROM_DISTRIBUTOR:
 bot_move_succeed: go_to_distributor -> GET_PUCK_FROM_DISTRIBUTOR
  get a new distributor position and go there.
 bot_move_succeed: go_to_unload -> GO_TO_UNLOAD_AREA
  compute an unload area.
  ask the move FSM to go there.
 bot_move_failed: niceness -> TRY_AGAIN_TO_GO_AWAY_FROM_DISTRIBUTOR
  decrement niceness.
  move forward using linear move.
 bot_move_failed: no_more_niceness_and_go_to_distributor -> GET_PUCK_FROM_DISTRIBUTOR
  get a new distributor position and go there.
 bot_move_failed: no_more_niceness_and_go_to_unload -> GO_TO_UNLOAD_AREA
  compute an unload area.
  ask the move FSM to go there.

TRY_AGAIN_TO_GO_AWAY_FROM_DISTRIBUTOR:
 bot_move_succeed -> GO_AWAY_FROM_DISTRIBUTOR
  move backward using linear move.
 bot_move_failed -> GO_AWAY_FROM_DISTRIBUTOR
  do the same as succeed.

UNLOAD_PUCKS:
 elevator_order_done -> GO_AWAY_FROM_UNLOAD_AREA
  linear move.
 state_timeout -> ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD
  we have failed, ask the elevator to put itself in a state where bot movement
  will not damage something.

GO_AWAY_FROM_UNLOAD_AREA:
 bot_move_succeed: more_than_six_pucks_or_no_next_position -> GET_PUCK_FROM_DISTRIBUTOR
  get the next distributor position and launch move FSM to go there.
 bot_move_succeed: next_position_for_pucks_on_ground_exists -> GET_PUCK_FROM_THE_GROUND
  go to the next position using move FSM.
 bot_move_failed: niceness -> TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA
  decrement niceness.
  move forward using linear move.
 bot_move_failed: no_more_niceness_and_more_than_six_pucks_or_no_next_position -> GET_PUCK_FROM_DISTRIBUTOR
  go to the next position using move FSM.
 bot_move_failed: no_more_niceness_and_next_position_for_pucks_on_ground_exists -> GET_PUCK_FROM_THE_GROUND
  go to the next position using move FSM.

TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA:
 bot_move_succeed -> GO_AWAY_FROM_UNLOAD_AREA
  move backward using linear move.
 bot_move_failed -> GO_AWAY_FROM_UNLOAD_AREA
  do the same as succeed.

ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD:
 elevator_order_done -> GO_AWAY_TO_RETRY_UNLOAD
  move backward from the unload area using linear move.
 state_timeout -> GO_AWAY_TO_RETRY_UNLOAD
  do the same as elevator_ready.