-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmi2012.ino
149 lines (122 loc) · 3.69 KB
/
pmi2012.ino
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
#include "include_arduino.h"
#include "parameters.h"
#include <math.h>
#include "encoder.h"
#include "robotstate.h"
#include "pwm.h"
#include "fifo.h"
#include "message.h"
#include "control.h"
#include "motor.h"
#include "define.h"
unsigned long index = 0;
unsigned long timeStart = 0;
byte etat = E_START;
void setup(){
value_pwm_left = 0;
value_pwm_right = 0;
/*Initialise la file des buts a atteindre*/
initGoals();
/*Active les pwm*/
initPWM();
/*Initialise le regulateur*/
initController();
/*Active les interruptions sur les encodeurs*/
initEncoders();
/*Definit la position initiale du robot*/
initRobotState();
/*Active la liaison serie*/
initSerialLink();
// LED qui n'en est pas une
pinMode(DEL_PIN,OUTPUT);
}
void loop(){
/* on note le temps de debut */
timeStart = micros();
/*Serial.print(value_left_enc);
Serial.print(" : ");
Serial.println(value_right_enc);
Serial.print(robot_get_x() * (ENC_TICKS_TO_MM * .01));
Serial.print(" - ");
Serial.println(robot_get_y() * (ENC_TICKS_TO_MM * .01));*/
/* La del est allumee pendant le traitement */
digitalWrite(DEL_PIN, HIGH);
/* zone programmation libre */
/*lecture des ordres*/
readIncomingData();
/*recuperation du but suivant (vitesse, angle ou position) */
if(current_goal.isReached){
popGoal(); /* va changer la valeur de current_goal */
switch(etat){
case E_START:
pushGoalPosition(NO_ID, (double)520 * (ENC_MM_TO_TICKS), (double)152 * (ENC_MM_TO_TICKS), (double)255);
etat = E_CAD1_OR;
break;
case E_CAD1_OR:
pushGoalOrientation(NO_ID, 0, 100);
etat = E_CAD1;
break;
case E_CAD1:
if(paf()){
pushGoalPosition(NO_ID, (double)1120 * (ENC_MM_TO_TICKS), (double)152 * (ENC_MM_TO_TICKS), (double)255);
etat = E_CAD2_OR;
}
break;
case E_CAD2_OR:
pushGoalOrientation(NO_ID, 0, 100);
etat = E_CAD2;
break;
case E_CAD2:
if(paf()){
pushGoalPosition(NO_ID, (double)1720 * (ENC_MM_TO_TICKS), (double)152 * (ENC_MM_TO_TICKS), (double)255);
etat = E_CAD3_OR;
}
break;
case E_CAD3_OR:
pushGoalOrientation(NO_ID, 0, 100);
etat = E_CAD3;
break;
case E_CAD3:
if(paf()){
pushGoalPosition(NO_ID, (double)2320 * (ENC_MM_TO_TICKS), (double)152 * (ENC_MM_TO_TICKS), (double)255);
etat = E_CAD4_OR;
}
break;
case E_CAD4_OR:
pushGoalOrientation(NO_ID, 0, 100);
etat = E_CAD4;
break;
case E_CAD4:
if(paf()){
//pushGoalPosition(NO_ID, (double)152 * (ENC_MM_TO_TICKS), (double)2320 * (ENC_MM_TO_TICKS), (double)255);
//etat = E_;²
}
break;
}
}
/*traitement des taches*/
if(!current_goal.isReached){
if(current_goal.type == TYPE_SPEED)
speedControl(&value_pwm_left,&value_pwm_right);
else if(current_goal.type == TYPE_ANGLE)
angleControl(&value_pwm_left,&value_pwm_right);
else if(current_goal.type == TYPE_POSITION)
positionControl(&value_pwm_left,&value_pwm_right);
else if(current_goal.type == TYPE_PWM)
pwmControl(&value_pwm_left,&value_pwm_right);
}
/*ecriture de la sortie*/
setLeftPWM(value_pwm_left);
setRightPWM(value_pwm_right);
/*modele d'evolution*/
computeRobotState();
/* fin zone de programmation libre */
/* On eteint la del */
digitalWrite(DEL_PIN, LOW);
/* On attend le temps qu'il faut pour boucler */
long udelay = DUREE_CYCLE*1000-(micros()-timeStart);
if(udelay<0)
Serial.println("ouch : mainloop trop longue");
else
delayMicroseconds(udelay);
}