-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_ax12.c
216 lines (178 loc) · 6.51 KB
/
actions_ax12.c
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
#include <p33Fxxxx.h> /* Includes device header file */
#include <stdint.h> /* Includes uint16_t definition */
#include <stdbool.h> /* Includes true/false definition */
#include <stdio.h>
#include <uart.h>
#include <delay.h>
#include "main.h"
#define maxtork_ax 850
#define maxspeed_ax 400
#define delay_min_ax 30
/******************************************************************************/
/*************************** Arm Specification ********************************/
/******************************************************************************/
// PIN TEAM = COTE D'EQUIPE VIOLET !!
/******************************************************************************/
/****************************** Init Position *********************************/
/******************************************************************************/
volatile int Num_Action_Done = 0;
volatile int Num_Action_ToDo = 0;
volatile char Tab_Actions_ToDo [NUM_ACTIONS_BUFFER] = {0};
void Add_Action_AX12(char Action_ToDo)
{
int num = Num_Action_ToDo;
num++;
if (num == NUM_ACTIONS_BUFFER) {
num = 0;
}
Tab_Actions_ToDo[num] = Action_ToDo;
Num_Action_ToDo = num;
}
void Faire_Actions_AX12(void)
{
int num = Num_Action_Done;
char Action_ToDo;
if (num != Num_Action_ToDo && 0/* !Delay_90_Over */) {
num++;
if (num == NUM_ACTIONS_BUFFER) {
num = 0;
}
Action_ToDo = Tab_Actions_ToDo[num];
switch (Action_ToDo)
{
case AX12_INIT_AX12 :
Init_ax12();
break;
case AX12_DEPLOY_WINGS_BAS :
Deploy_wings_B();
break;
case AX12_DEPLOY_WINGS_HAUT :
Deploy_wings_H();
break;
case AX12_DEPLOY_WINGS :
Deploy_wings();
break;
case AX12_IBICF:
I_Can_Fly();
break;
case POMPE_ACTIVER:
Activer_Pompes();
break;
case POMPE_ACTIVER_BAS:
Activer_Pompe_basse();
break;
case POMPE_ETEINDRE:
Eteindre_Pompes();
break;
case AX12_CLOSE_WINGS_BAS :
Close_wings_B();
break;
case AX12_CLOSE_WINGS_HAUT :
Close_wings_H();
break;
case AX12_CLOSE_WINGS :
Close_wings();
break;
}
Num_Action_Done = num;
}
}
void Init_ax12() {
PutAX(Wing_1, AX_TORQUE_LIMIT, maxtork_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_TORQUE_LIMIT, maxtork_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_3, AX_TORQUE_LIMIT, maxtork_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_TORQUE_LIMIT, maxtork_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_1, AX_MOVING_SPEED, maxspeed_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_MOVING_SPEED, maxspeed_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_3, AX_MOVING_SPEED, maxspeed_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_MOVING_SPEED, maxspeed_ax);
__delay_ms(delay_min_ax);
PutAX(Wing_1, AX_GOAL_POSITION, 280);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
PutAX(Wing_3, AX_GOAL_POSITION, 270);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
}
// PIN TEAM = 1 pour violet, 0 pour vert
void Deploy_wings_H(void) // Deploie les ailes du haut.
{
PutAX(Wing_1, AX_GOAL_POSITION, 800);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_GOAL_POSITION, 205);
__delay_ms(delay_min_ax);
}
void Deploy_wings_B(void) // Deploie les ailes du bas.
{
PutAX(Wing_3, AX_GOAL_POSITION, 819);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_GOAL_POSITION, 205);
__delay_ms(delay_min_ax);
}
void Deploy_wings(void) // Deplois toutes les ailes.
{
PutAX(Wing_1, AX_GOAL_POSITION, 800);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_GOAL_POSITION, 220);
__delay_ms(delay_min_ax);
PutAX(Wing_3, AX_GOAL_POSITION, 814);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_GOAL_POSITION, 210);
__delay_ms(delay_min_ax);
SendDone();
}
void Close_wings_B(void) // Range toutes les ailes.
{
PutAX(Wing_3, AX_GOAL_POSITION, 270);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
}
void Close_wings_H(void) // Range toutes les ailes.
{
PutAX(Wing_1, AX_GOAL_POSITION, 280);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
}
void Close_wings(void) // Range toutes les ailes.
{
PutAX(Wing_1, AX_GOAL_POSITION, 280);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
PutAX(Wing_3, AX_GOAL_POSITION, 270);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
SendDone();
}
void I_Can_Fly(void) // A vous de jouer !!! ;)
{
PutAX(Wing_1, AX_GOAL_POSITION, 800);
__delay_ms(delay_min_ax);
PutAX(Wing_3, AX_GOAL_POSITION, 819);
__delay_ms(500);
PutAX(Wing_1, AX_GOAL_POSITION, 280);
__delay_ms(delay_min_ax);
PutAX(Wing_3, AX_GOAL_POSITION, 270);
__delay_ms(delay_min_ax);
PutAX(Wing_2, AX_GOAL_POSITION, 205);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_GOAL_POSITION, 210);
__delay_ms(500)
PutAX(Wing_2, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
PutAX(Wing_4, AX_GOAL_POSITION, 740);
__delay_ms(delay_min_ax);
}
/******************************************************************************/