-
Notifications
You must be signed in to change notification settings - Fork 0
/
asserv.ino
86 lines (66 loc) · 1.91 KB
/
asserv.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
#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"
unsigned long index = 0;
unsigned long timeStart = 0;
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();
/* 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 */
/*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);
}