summaryrefslogtreecommitdiff
path: root/n/asserv/src/taz.c
blob: 61187b84f060ec1133d3e9fc4ea6261ffa79cc22 (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
/* taz.c - Automate pour Taz, robot 2005. */
/* asserv - Position & speed motor control on a ATmega128. {{{
 *
 * Copyright (C) 2005 Nicolas Schodet
 *
 * 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.
 *
 * Contact :
 *        Web: http://perso.efrei.fr/~schodet/
 *      Email: <contact@ni.fr.eu.org>
 * }}} */

/** FSM state. */
uint8_t taz_state;
uint8_t taz_substate;
/** Positions. */
#define taz_scale 0.05026548245743669181
static const uint16_t taz_rear_16 = taz_scale * 270 / 2;
static const uint32_t taz_rear_32 = taz_rear_16 * 256;
static const uint16_t taz_front_16 = taz_scale * 270 / 2;
static const uint32_t taz_front_32 = taz_front_16 * 256;
static const uint16_t taz_side_16 = taz_scale * 340 / 2;
static const uint32_t taz_side_32 = taz_side_16 * 256;

static const uint16_t taz_start_y_16 = taz_scale * 450 / 2;

static const uint16_t taz_before_bridge_16 = taz_scale * 1050;
static const uint16_t taz_after_bridge_16 = taz_scale * (1500 + 22 + 600 + 22
							 + 300);

/* +AutoDec */
/* -AutoDec */

/* TODO:
 *  - timer de match.
 */

/** Initialise behavior. */
static inline void
taz_init (void)
{
    taz_state = 0;
    taz_substate = 0;
}

/** Mise en place avant le d�part. */
static inline void
taz_state_0 (void)
{
    switch (taz_substate)
      {
      case 0:
	/* Attend que l'on enfonce le jack. */
	if (PINA & _BV (6))
	    taz_substate = 1;
	break;
      case 1:
	/* Attend que l'on enl�ve le jack. */
	if (!(PINA & _BV (6)))
	  {
	    taz_substate = 2;
	    /* FTW. */
	    motor_mode = 2;
	    goto_mode = 10;
	    goto_s = -0x10;
	    goto_finish = 0;
	  }
	break;
      case 2:
	if (goto_finish)
	  {
	    taz_substate = 3;
	    /* Recalage. */
	    goto_y = taz_rear_32;
	    goto_a = 0x00400000;
	    /* On avance juste qu'� l'y de d�part. */
	    motor_mode = 2;
	    goto_mode = 0;
	    goto_sign = 0;
	    goto_d = taz_start_y - taz_rear;
	    goto_x = postrack_x;
	    goto_y = postrack_y;
	    goto_finish = 0;
	  }
	break;
      case 3:
	if (goto_finish)
	  {
	    taz_substate = 4;
	    /* Direction l'axe des x. */
	    motor_mode = 2;
	    goto_mode = 1;
	    goto_a = 0;
	    goto_finish = 0;
	  }
	break;
      case 4:
	if (goto_finish)
	  {
	    taz_substate = 5;
	    /* FTW. */
	    motor_mode = 2;
	    goto_mode = 10;
	    goto_s = -0x10;
	    goto_finish = 0;
	  }
	break;
      case 5:
	if (goto_finish && (PINA & _BV (6)))
	  {
	    taz_substate = 6;
	    /* Recalage. */
	    goto_x = taz_rear_32;
	    goto_a = 0;
	  }
      case 6:
	if (!(PINA & _BV (6)))
	  {
	    taz_state = 1;
	    taz_substate = 0;
	  }
      }
}

/** Avanc�e vers le pont. */
static inline void
taz_state_1 (void)
{
    switch (taz_substate)
      {
      case 0:
	break;
      }
}

/** Travers�e du pont. */
static inline void
taz_state_2 (void)
{
    switch (taz_substate)
      {
      case 0:
	break;
      }
}

/** . */
static inline void
taz_state_3 (void)
{
    switch (taz_substate)
      {
      case 0:
	break;
      }
}

/** . */
static inline void
taz_state_4 (void)
{
    switch (taz_substate)
      {
      case 0:
	break;
      }
}

/** . */
static inline void
taz_state_5 (void)
{
    switch (taz_substate)
      {
      case 0:
	break;
      }
}

/** FSM. */
static inline void
taz_update (void)
{
    switch (taz_state)
      {
      case 0:
	taz_state_0 ();
	break;
      case 1:
	taz_state_1 ();
	break;
      case 2:
	taz_state_2 ();
	break;
      case 3:
	taz_state_3 ();
	break;
      case 4:
	taz_state_4 ();
	break;
      case 5:
	taz_state_5 ();
	break;
      }
}