summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/top_cb.c
blob: 76cdb2b1338bb1e238443e32e82957cc77ff9609 (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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/* top_cb.c */
/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
 *
 * Copyright (C) 2009 Dufour Jérémy
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}}
 * Main FSM calling other FSM.
 */


#include "common.h"
#include "fsm.h"
#include "top_cb.h"
#include "asserv.h"
#include "playground.h"
#include "move.h"	/* move FSM */

/*
 * IDLE =start=>
 *  => WAIT_INIT_TO_FINISH
 *   nothing to do.
 */
fsm_branch_t
top__IDLE__start (void)
{
    return top_next (IDLE, start);
}

/*
 * WAIT_INIT_TO_FINISH =init_match_is_started=>
 *  => GET_PUCK_FROM_THE_GROUND
 *   the match start, try to get some puck from the ground.
 */
fsm_branch_t
top__WAIT_INIT_TO_FINISH__init_match_is_started (void)
{
    return top_next (WAIT_INIT_TO_FINISH, init_match_is_started);
}

/*
 * GET_PUCK_FROM_THE_GROUND =move_fsm_succeed=>
 * already_six_pucks_or_no_next_position => GET_PUCK_FROM_DISTRIBUTOR
 *   get the next distributor position and launch move FSM to go there.
 * next_position_exists => GET_PUCK_FROM_THE_GROUND
 *   go to the next position using move FSM.
 */
fsm_branch_t
top__GET_PUCK_FROM_THE_GROUND__move_fsm_succeed (void)
{
    return top_next_branch (GET_PUCK_FROM_THE_GROUND, move_fsm_succeed, already_six_pucks_or_no_next_position);
    return top_next_branch (GET_PUCK_FROM_THE_GROUND, move_fsm_succeed, next_position_exists);
}

/*
 * GET_PUCK_FROM_THE_GROUND =move_fsm_failed=>
 *  => GET_PUCK_FROM_DISTRIBUTOR
 *   we have failed to do a move, go the distributor (get next distributor and go
 *   there with move FSM).
 */
fsm_branch_t
top__GET_PUCK_FROM_THE_GROUND__move_fsm_failed (void)
{
    return top_next (GET_PUCK_FROM_THE_GROUND, move_fsm_failed);
}

/*
 * GET_PUCK_FROM_THE_GROUND =bot_is_full_of_pucks=>
 *  => STOP_TO_GO_TO_UNLOAD_AREA
 *   stop move FSM.
 */
fsm_branch_t
top__GET_PUCK_FROM_THE_GROUND__bot_is_full_of_pucks (void)
{
    return top_next (GET_PUCK_FROM_THE_GROUND, bot_is_full_of_pucks);
}

/*
 * GET_PUCK_FROM_THE_GROUND =state_timeout=>
 *  => STOP_TO_GET_PUCK_FROM_DISTRIBUTOR
 *   too much time lost to get puck from the ground, stop move FSM.
 */
fsm_branch_t
top__GET_PUCK_FROM_THE_GROUND__state_timeout (void)
{
    return top_next (GET_PUCK_FROM_THE_GROUND, state_timeout);
}

/*
 * GET_PUCK_FROM_DISTRIBUTOR =move_fsm_succeed=>
 *  => CLEAN_FRONT_OF_DISTRIBUTOR
 *   really go to the front of the distributor (it clean front area).
 */
fsm_branch_t
top__GET_PUCK_FROM_DISTRIBUTOR__move_fsm_succeed (void)
{
    return top_next (GET_PUCK_FROM_DISTRIBUTOR, move_fsm_succeed);
}

/*
 * GET_PUCK_FROM_DISTRIBUTOR =move_fsm_failed=>
 * no_puck_or_still_time => GET_PUCK_FROM_DISTRIBUTOR
 *   get the next distributor position and launch move FSM to go there.
 * some_pucks_and_no_more_time => GO_TO_UNLOAD_AREA
 *   compute an unload area.
 *   ask move FSM to go there.
 */
fsm_branch_t
top__GET_PUCK_FROM_DISTRIBUTOR__move_fsm_failed (void)
{
    return top_next_branch (GET_PUCK_FROM_DISTRIBUTOR, move_fsm_failed, no_puck_or_still_time);
    return top_next_branch (GET_PUCK_FROM_DISTRIBUTOR, move_fsm_failed, some_pucks_and_no_more_time);
}

/*
 * 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.
 */
fsm_branch_t
top__STOP_TO_GO_TO_UNLOAD_AREA__move_fsm_stopped (void)
{
    return top_next (STOP_TO_GO_TO_UNLOAD_AREA, move_fsm_stopped);
}

/*
 * STOP_TO_GO_TO_UNLOAD_AREA =move_fsm_succeed=>
 *  => GO_TO_UNLOAD_AREA
 *   do the same as bot_move_stopped.
 */
fsm_branch_t
top__STOP_TO_GO_TO_UNLOAD_AREA__move_fsm_succeed (void)
{
    return top_next (STOP_TO_GO_TO_UNLOAD_AREA, move_fsm_succeed);
}

/*
 * STOP_TO_GO_TO_UNLOAD_AREA =bot_move_failed=>
 *  => GO_TO_UNLOAD_AREA
 *   do the same as bot_move_stopped.
 */
fsm_branch_t
top__STOP_TO_GO_TO_UNLOAD_AREA__bot_move_failed (void)
{
    return top_next (STOP_TO_GO_TO_UNLOAD_AREA, bot_move_failed);
}

/*
 * STOP_TO_GET_PUCK_FROM_DISTRIBUTOR =move_fsm_stopped=>
 *  => GET_PUCK_FROM_DISTRIBUTOR
 *   get next distributor and go there.
 */
fsm_branch_t
top__STOP_TO_GET_PUCK_FROM_DISTRIBUTOR__move_fsm_stopped (void)
{
    return top_next (STOP_TO_GET_PUCK_FROM_DISTRIBUTOR, move_fsm_stopped);
}

/*
 * GO_TO_UNLOAD_AREA =move_fsm_succeed=>
 *  => FUCK_UNLOAD_AREA
 *   make the bot do a fuck the wall in backward until blocked.
 */
fsm_branch_t
top__GO_TO_UNLOAD_AREA__move_fsm_succeed (void)
{
    return top_next (GO_TO_UNLOAD_AREA, move_fsm_succeed);
}

/*
 * GO_TO_UNLOAD_AREA =move_fsm_failed=>
 *  => GO_TO_UNLOAD_AREA
 *   compute a new unload area.
 *   ask move FSM to go to the position using backward only.
 */
fsm_branch_t
top__GO_TO_UNLOAD_AREA__move_fsm_failed (void)
{
    return top_next (GO_TO_UNLOAD_AREA, move_fsm_failed);
}

/*
 * FUCK_UNLOAD_AREA =bot_move_succeed=>
 *  => UNLOAD_PUCKS
 *   unload all the pucks from the elevator.
 */
fsm_branch_t
top__FUCK_UNLOAD_AREA__bot_move_succeed (void)
{
    return top_next (FUCK_UNLOAD_AREA, bot_move_succeed);
}

/*
 * FUCK_UNLOAD_AREA =bot_move_failed=>
 *  => GO_AWAY_TO_RETRY_UNLOAD
 *   move backward from the unload area using linear move.
 */
fsm_branch_t
top__FUCK_UNLOAD_AREA__bot_move_failed (void)
{
    return top_next (FUCK_UNLOAD_AREA, bot_move_failed);
}

/*
 * UNLOAD_PUCKS =elevator_is_closed=>
 *  => GO_AWAY_FROM_UNLOAD_AREA
 *   linear move.
 */
fsm_branch_t
top__UNLOAD_PUCKS__elevator_is_closed (void)
{
    return top_next (UNLOAD_PUCKS, elevator_is_closed);
}

/*
 * UNLOAD_PUCKS =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.
 */
fsm_branch_t
top__UNLOAD_PUCKS__state_timeout (void)
{
    return top_next (UNLOAD_PUCKS, state_timeout);
}

/*
 * ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD =elevator_is_closed=>
 *  => GO_AWAY_TO_RETRY_UNLOAD
 *   move backward from the unload area using linear move.
 */
fsm_branch_t
top__ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD__elevator_is_closed (void)
{
    return top_next (ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD, elevator_is_closed);
}

/*
 * ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD =state_timeout=>
 *  => GO_AWAY_TO_RETRY_UNLOAD
 *   do the same as elevator_ready.
 */
fsm_branch_t
top__ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD__state_timeout (void)
{
    return top_next (ELEVATOR_READY_TO_GO_AWAY_TO_RETRY_UNLOAD, state_timeout);
}

/*
 * 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.
 */
fsm_branch_t
top__GO_AWAY_TO_RETRY_UNLOAD__bot_move_succeed (void)
{
    return top_next (GO_AWAY_TO_RETRY_UNLOAD, bot_move_succeed);
}

/*
 * GO_AWAY_TO_RETRY_UNLOAD =bot_move_failed=>
 * niceness => TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD
 *   decrement niceness.
 *   move forward using linear move.
 * no_more_niceness => GO_TO_UNLOAD_AREA
 *   do the same as move succeed.
 */
fsm_branch_t
top__GO_AWAY_TO_RETRY_UNLOAD__bot_move_failed (void)
{
    return top_next_branch (GO_AWAY_TO_RETRY_UNLOAD, bot_move_failed, niceness);
    return top_next_branch (GO_AWAY_TO_RETRY_UNLOAD, bot_move_failed, no_more_niceness);
}

/*
 * 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.
 */
fsm_branch_t
top__TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD__bot_move_succeed (void)
{
    return top_next (TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD, bot_move_succeed);
}

/*
 * TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD =bot_move_failed=>
 *  => GO_AWAY_TO_RETRY_UNLOAD
 *   do the same as succeed.
 */
fsm_branch_t
top__TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD__bot_move_failed (void)
{
    return top_next (TRY_AGAIN_TO_GO_AWAY_TO_RETRY_UNLOAD, bot_move_failed);
}

/*
 * FUCK_THE_DISTRIBUTOR =bot_move_succeed=>
 *  => WAIT_FOR_PUCKS
 *   let's cylinder FSM works until finished.
 */
fsm_branch_t
top__FUCK_THE_DISTRIBUTOR__bot_move_succeed (void)
{
    return top_next (FUCK_THE_DISTRIBUTOR, bot_move_succeed);
}

/*
 * FUCK_THE_DISTRIBUTOR =bot_move_failed=>
 * no_puck_or_still_time => GET_PUCK_FROM_DISTRIBUTOR
 *   get a new distributor and go there.
 * some_pucks_and_no_more_time => GO_TO_UNLOAD_AREA
 *   compute an unload area.
 *   ask move FSM to go there.
 */
fsm_branch_t
top__FUCK_THE_DISTRIBUTOR__bot_move_failed (void)
{
    return top_next_branch (FUCK_THE_DISTRIBUTOR, bot_move_failed, no_puck_or_still_time);
    return top_next_branch (FUCK_THE_DISTRIBUTOR, bot_move_failed, some_pucks_and_no_more_time);
}

/*
 * WAIT_FOR_PUCKS =bot_is_full_of_pucks=>
 *  => GO_TO_UNLOAD_AREA
 *   compute an unload area.
 *   ask the move FSM to go there.
 */
fsm_branch_t
top__WAIT_FOR_PUCKS__bot_is_full_of_pucks (void)
{
    return top_next (WAIT_FOR_PUCKS, bot_is_full_of_pucks);
}

/*
 * WAIT_FOR_PUCKS =empty_distributor=>
 * no_puck_or_still_time => GET_PUCK_FROM_DISTRIBUTOR
 *   get a new distributor position and go there.
 * some_pucks_and_no_more_time => GO_TO_UNLOAD_AREA
 *   compute an unload area and go there.
 */
fsm_branch_t
top__WAIT_FOR_PUCKS__empty_distributor (void)
{
    return top_next_branch (WAIT_FOR_PUCKS, empty_distributor, no_puck_or_still_time);
    return top_next_branch (WAIT_FOR_PUCKS, empty_distributor, some_pucks_and_no_more_time);
}

/*
 * 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.
 * next_position_for_pucks_on_ground_exists => GET_PUCK_FROM_THE_GROUND
 *   go to the next position using move FSM.
 */
fsm_branch_t
top__GO_AWAY_FROM_UNLOAD_AREA__bot_move_succeed (void)
{
    return top_next_branch (GO_AWAY_FROM_UNLOAD_AREA, bot_move_succeed, more_than_six_pucks_or_no_next_position);
    return top_next_branch (GO_AWAY_FROM_UNLOAD_AREA, bot_move_succeed, next_position_for_pucks_on_ground_exists);
}

/*
 * GO_AWAY_FROM_UNLOAD_AREA =bot_move_failed=>
 * niceness => TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA
 *   decrement niceness.
 *   move forward using linear move.
 * no_more_niceness_and_more_than_six_pucks_or_no_next_position => GET_PUCK_FROM_DISTRIBUTOR
 *   go to the next position using move FSM.
 * no_more_niceness_and_next_position_for_pucks_on_ground_exists => GET_PUCK_FROM_THE_GROUND
 *   go to the next position using move FSM.
 */
fsm_branch_t
top__GO_AWAY_FROM_UNLOAD_AREA__bot_move_failed (void)
{
    return top_next_branch (GO_AWAY_FROM_UNLOAD_AREA, bot_move_failed, niceness);
    return top_next_branch (GO_AWAY_FROM_UNLOAD_AREA, bot_move_failed, no_more_niceness_and_more_than_six_pucks_or_no_next_position);
    return top_next_branch (GO_AWAY_FROM_UNLOAD_AREA, bot_move_failed, no_more_niceness_and_next_position_for_pucks_on_ground_exists);
}

/*
 * TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA =bot_move_succeed=>
 *  => GO_AWAY_FROM_UNLOAD_AREA
 *   move backward using linear move.
 */
fsm_branch_t
top__TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA__bot_move_succeed (void)
{
    return top_next (TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA, bot_move_succeed);
}

/*
 * TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA =bot_move_failed=>
 *  => GO_AWAY_FROM_UNLOAD_AREA
 *   do the same as succeed.
 */
fsm_branch_t
top__TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA__bot_move_failed (void)
{
    return top_next (TRY_AGAIN_TO_GO_AWAY_FROM_UNLOAD_AREA, bot_move_failed);
}

/*
 * CLEAN_FRONT_OF_DISTRIBUTOR =move_fsm_succeed=>
 *  => FUCK_THE_DISTRIBUTOR
 *   we are in front of the distributor: fuck it.
 */
fsm_branch_t
top__CLEAN_FRONT_OF_DISTRIBUTOR__move_fsm_succeed (void)
{
    return top_next (CLEAN_FRONT_OF_DISTRIBUTOR, move_fsm_succeed);
}

/*
 * CLEAN_FRONT_OF_DISTRIBUTOR =move_fsm_failed=>
 *  => GET_PUCK_FROM_DISTRIBUTOR
 *   get a new distributor and go there.
 */
fsm_branch_t
top__CLEAN_FRONT_OF_DISTRIBUTOR__move_fsm_failed (void)
{
    return top_next (CLEAN_FRONT_OF_DISTRIBUTOR, move_fsm_failed);
}