summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/top_cb.c
blob: ff45c2907b7f96f4e5d001cd6a8ae1170b0e6752 (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
/*
 * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT!
 *
 * Skeleton for top callbacks implementation.
 *
 * 
 */
#include "common.h"
#include "fsm.h"
#include "top_cb.h"
#include "top.h"
#include "getsamples.h"
#include "asserv.h"
#include "gutter.h"

/*
 * BACKWARD =collector_full=>
 *  => GO_TO_GOAL
 *   Go the goal to depose the samples.
 */
fsm_branch_t
top__BACKWARD__collector_full (void)
{
    gutter_start ();
    top_data.sequence_to_do = (~top_data.sequence_to_do) & 0x1f;
    return top_next (BACKWARD, collector_full);
}

/*
 * BACKWARD =ended=>
 *  => GET_ICE
 *   Get ICE to end the sequence.
 */
fsm_branch_t
top__BACKWARD__ended (void)
{
    /* Generic get sample data */
    struct getsamples_data_t get_sample_data;
    get_sample_data.event = TOP_EVENT_ice_took;
    get_sample_data.sample_bitfield = ~top_data.boxes_used; // XXX
    get_sample_data.distributor_y = ICE_DISTRIBUTOR_Y;
    if (top_data.team_color)
      {
	get_sample_data.distributor_x = ICE_DISTRIBUTOR_LEFT;
	getsamples_start (get_sample_data);
      }
    else
      {
	get_sample_data.distributor_x = ICE_DISTRIBUTOR_RIGHT;
	getsamples_start (get_sample_data);
      }
    return top_next (BACKWARD, ended);
}

/*
 * BACKWARD =ice_dist_empty=>
 *  => GET_ADV_ICE
 *   Go to take the ice in the adversary distributor because our is empty.
 */
fsm_branch_t
top__BACKWARD__ice_dist_empty (void)
{
    /* Generic get sample data */
    struct getsamples_data_t get_sample_data;
    get_sample_data.event = TOP_EVENT_ice_took;
    get_sample_data.sample_bitfield = ~top_data.boxes_used; // XXX
    get_sample_data.distributor_y = ICE_DISTRIBUTOR_Y;
    if (top_data.team_color)
      {
	get_sample_data.distributor_x = ICE_DISTRIBUTOR_LEFT;
	getsamples_start (get_sample_data);
      }
    else
      {
	get_sample_data.distributor_x = ICE_DISTRIBUTOR_RIGHT;
	getsamples_start (get_sample_data);
      }
    return top_next (BACKWARD, ice_dist_empty);
}

/*
 * GET_ICE =ice_took=>
 *  => BACKWARD
 *   Go backward to end the take balls.
 */
fsm_branch_t
top__GET_ICE__ice_took (void)
{
    asserv_position_t pos;

    asserv_get_position (&pos);

    asserv_goto (pos.x - 200, pos.y - 200);
    return top_next (GET_ICE, ice_took);
}

/*
 * START =ok=>
 *  => GET_SAMPLES
 *   Go to take some samples. The sequence shall be adapt to take the correct number of samples.
 */
fsm_branch_t
top__START__ok (void)
{
    /* Generic get sample data */
    struct getsamples_data_t get_sample_data;
    get_sample_data.event = TOP_EVENT_samples_took;
    get_sample_data.sample_bitfield = ~top_data.boxes_used; // XXX
    if (top_data.team_color == BLUE_TEAM)
      {
	get_sample_data.distributor_x = BLUE_DISTRIBUTOR_X;
	get_sample_data.distributor_y = BLUE_DISTRIBUTOR_Y;
	getsamples_start (get_sample_data);
      }
    else
      {
	get_sample_data.distributor_x = RED_DISTRIBUTOR_X;
	get_sample_data.distributor_y = RED_DISTRIBUTOR_Y;
	getsamples_start (get_sample_data);
      }
    return top_next (START, ok);
}

/*
 * GO_TO_GOAL =samples_deposed=>
 *  => GET_SAMPLES
 *   The samples had been deposed, it shall try to get more samples. This state will call the getsamples FSM and the moveFSM.
 */
fsm_branch_t
top__GO_TO_GOAL__samples_deposed (void)
{
    /* Generic get sample data */
    struct getsamples_data_t get_sample_data;
    get_sample_data.event = TOP_EVENT_samples_took;
    get_sample_data.sample_bitfield = ~top_data.boxes_used; // XXX
    if (top_data.team_color == BLUE_TEAM)
      {
	get_sample_data.distributor_x = BLUE_DISTRIBUTOR_X;
	get_sample_data.distributor_y = BLUE_DISTRIBUTOR_Y;
	getsamples_start (get_sample_data);
      }
    else
      {
	get_sample_data.distributor_x = RED_DISTRIBUTOR_X;
	get_sample_data.distributor_y = RED_DISTRIBUTOR_Y;
	getsamples_start (get_sample_data);
      }
    return top_next (GO_TO_GOAL, samples_deposed);
}

/*
 * GET_ADV_ICE =ice_took=>
 *  => BACKWARD
 *   The ice has been taken.
 */
fsm_branch_t
top__GET_ADV_ICE__ice_took (void)
{
    asserv_position_t pos;

    asserv_get_position (&pos);

    asserv_goto (pos.x - 200, pos.y - 200);
    return top_next (GET_ADV_ICE, ice_took);
}

/*
 * GET_SAMPLES =samples_took=>
 *  => BACKWARD
 *   The samples had been took and now the ice is missing.
 */
fsm_branch_t
top__GET_SAMPLES__samples_took (void)
{
    // Call the get samples state machine.

    // Blue color.
    /* Generic get sample data */
    struct getsamples_data_t get_sample_data;
    get_sample_data.event = TOP_EVENT_samples_took;
    get_sample_data.sample_bitfield = top_data.sequence; // XXX
    if (top_data.team_color == BLUE_TEAM)
      {
	get_sample_data.distributor_x = BLUE_DISTRIBUTOR_X;
	get_sample_data.distributor_y = BLUE_DISTRIBUTOR_Y;
	getsamples_start (get_sample_data);
      }
    else
      {
	get_sample_data.distributor_x = RED_DISTRIBUTOR_X;
	get_sample_data.distributor_y = RED_DISTRIBUTOR_Y;
	getsamples_start (get_sample_data);
      }
    return top_next (START, ok);
}