summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/init_cb.c
blob: 70a964c152681bee8d32cdb904fc713c7c95bfb7 (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
/* init_cb.c - init FSM callbacks. */
/*  {{{
 *
 * Copyright (C) 2009 Nicolas Haller
 *
 * 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.
 *
 * }}} */
#include "common.h"
#include "fsm.h"
#include "init_cb.h"
#include "asserv.h"
#include "init.h"
#include "playground.h"
#include "main.h"
#include "aquajim.h"

/*
 * GOTO_THE_WALL_AGAIN =move_done=>
 *  => GO_BACKWARD_AGAIN
 *   go backward for INIT_DIST millimeters again
 */
fsm_branch_t
init__GOTO_THE_WALL_AGAIN__move_done (void)
{
    asserv_move_linearly(-INIT_DIST);
    return init_next (GOTO_THE_WALL_AGAIN, move_done);
}

/*
 * TURN_180_DEGREES_CCW =move_done=>
 *  => SET_POSITION
 *   set real position to asserv
 */
fsm_branch_t
init__TURN_180_DEGREES_CCW__move_done (void)
{
    /* FIXME Value from spa^W marcel */
    asserv_set_position(300, PG_HEIGHT - 305, 0);
    return init_next (TURN_180_DEGREES_CCW, move_done);
}

/*
 * IDLE =start=>
 *  => WAIT_JACK_IN
 *   wait for the jack to be inserted into the bot
 */
fsm_branch_t
init__IDLE__start (void)
{
    return init_next (IDLE, start);
}

/*
 * TURN_90_DEGREES_CCW =move_done=>
 *  => GOTO_THE_WALL_AGAIN
 *   go to the wall for the second time
 */
fsm_branch_t
init__TURN_90_DEGREES_CCW__move_done (void)
{
    asserv_go_to_the_wall(0);
    return init_next (TURN_90_DEGREES_CCW, move_done);
}

/*
 * GO_BACKWARD =move_done=>
 *  => TURN_90_DEGREES_CCW
 *   turn bot for 90 degrees counterclockwise
 */
fsm_branch_t
init__GO_BACKWARD__move_done (void)
{
    asserv_move_angularly(90*BOT_ANGLE_DEGREE);
    return init_next (GO_BACKWARD, move_done);
}

/*
 * GOTO_THE_WALL =move_done=>
 *  => GO_BACKWARD
 *   go backward for INIT_DIST millimeters
 */
fsm_branch_t
init__GOTO_THE_WALL__move_done (void)
{
    asserv_move_linearly(-INIT_DIST);
    return init_next (GOTO_THE_WALL, move_done);
}

/*
 * WAIT_JACK_IN =jack_inserted_into_bot=>
 *  => WAIT_2_SEC
 *   wait for the operator hand disappears
 */
fsm_branch_t
init__WAIT_JACK_IN__jack_inserted_into_bot (void)
{
    /* launch the timer (2 sec)*/
    main_init_wait_cycle = 450;
    return init_next (WAIT_JACK_IN, jack_inserted_into_bot);
}

/*
 * WAIT_2_SEC =init_tempo_ended=>
 *  => GOTO_THE_WALL
 *   go to the first wall
 */
fsm_branch_t
init__WAIT_2_SEC__init_tempo_ended (void)
{
    /* tell asserv to go FORWARD to the wall */
    asserv_go_to_the_wall(0);
    return init_next (WAIT_2_SEC, init_tempo_ended);
}

/*
 * GO_BACKWARD_AGAIN =move_done=>
 *  => TURN_180_DEGREES_CCW
 *   turn bot for 180 degrees counterclockwise
 */
fsm_branch_t
init__GO_BACKWARD_AGAIN__move_done (void)
{
    asserv_move_angularly(180*BOT_ANGLE_DEGREE);
    return init_next (GO_BACKWARD_AGAIN, move_done);
}