-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifo.cpp
144 lines (124 loc) · 3.77 KB
/
fifo.cpp
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
/*
* fifo.c
*
* Created on: 16 janv. 2011
* Author: HoHen
*/
#include "fifo.h"
#include <math.h>
#include "include_arduino.h"
Fifo goals;
void initGoals(){
goals.goal = (Goal*)malloc(sizeof(Goal)*SIZE);
goals.in = 0;
goals.out = 0;
/*for(int i=0;i<10;i++){
pushGoalPosition(NO_ID, (double)300 * (ENC_MM_TO_TICKS), (double)0 * (ENC_MM_TO_TICKS), (double)250);
pushGoalPosition(NO_ID, (double)100 * (ENC_MM_TO_TICKS), (double)0 * (ENC_MM_TO_TICKS), (double)250);
pushGoalPosition(NO_ID, (double)200 * (ENC_MM_TO_TICKS), (double)0 * (ENC_MM_TO_TICKS), (double)250);
}*/
/*for(int i=0;i<10;i++){
pushGoalOrientation(NO_ID, 3.14, 100); //angle,vitesse
pushGoalOrientation(NO_ID, 0, 100); //angle,vitesse
}*/
//pushGoalOrientation(NO_ID, 3.14/2, 100); //angle,vitesse
//pushGoalPosition(NO_ID, (double)100 * (ENC_MM_TO_TICKS), (double)100 * (ENC_MM_TO_TICKS), (double)255);
//pushGoalPosition(NO_ID, (double)0 * (ENC_MM_TO_TICKS), (double)100 * (ENC_MM_TO_TICKS), (double)255);
//pushGoalPosition(NO_ID, (double)0 * (ENC_MM_TO_TICKS), (double)0 * (ENC_MM_TO_TICKS), (double)255);
//pushGoalAutoCalibration(0,0);
/*pour tester le robot*/
//pushGoalOrientation(3.14,255); //angle,vitesse
//pushGoalPosition(NO_ID, 10000, 9000, 255); //x,y,vitesse
//pushGoalSpeed(NO_ID, 255, 10000); //vitesse,periode
//pushGoalOrientation(3.14,255);
/*pushGoalDelay(1000);
pushGoalOrientation(3.14,255);
pushGoalDelay(1000);
pushGoalOrientation(3*3.14/2,255);
pushGoalDelay(1000);
pushGoalOrientation(0,255);*/
//pushGoalOrientation(1.414,200);
}
void pushGoalOrientation(int id, double angle, double speed){
if((goals.in+1)%SIZE != goals.out){
Goal* incGoal = goals.goal+goals.in;
incGoal->type = TYPE_ANGLE;
incGoal->id = id;
incGoal->data_1 = angle;
incGoal->data_2 = speed;
goals.in = (goals.in+1)%SIZE;
}
}
void pushGoalPosition(int id, double x, double y, double speed){
if((goals.in+1)%SIZE != goals.out){
Goal* incGoal = goals.goal+goals.in;
incGoal->type = TYPE_POSITION;
incGoal->id = id;
incGoal->data_1 = x;
incGoal->data_2 = y;
incGoal->data_3 = speed;
goals.in = (goals.in+1)%SIZE;
}
}
void pushGoalSpeed(int id, double speed, double period){
if((goals.in+1)%SIZE != goals.out){
Goal* incGoal = goals.goal+goals.in;
incGoal->type = TYPE_SPEED;
incGoal->id = id;
incGoal->data_1 = speed;
incGoal->data_2 = period;
goals.in = (goals.in+1)%SIZE;
}
}
void pushGoalPwm(int id, double left, double right, double period){
if((goals.in+1)%SIZE != goals.out){
Goal* incGoal = goals.goal+goals.in;
incGoal->type = TYPE_PWM;
incGoal->id = id;
incGoal->data_1 = left;
incGoal->data_2 = right;
incGoal->data_3 = period;
goals.in = (goals.in+1)%SIZE;
}
}
void popGoal(){
if(goals.in!=goals.out){
current_goal.isReached = false;
current_goal.isCanceled = false;
current_goal.isMessageSent = false;
current_goal.phase = PHASE_1;
Goal* outGoal = goals.goal+goals.out;
current_goal.type = outGoal->type;
current_goal.id = outGoal->id;
switch (outGoal->type) {
case TYPE_SPEED:
current_goal.speed = outGoal->data_1;
current_goal.period = outGoal->data_2;
break;
case TYPE_ANGLE:
current_goal.angle = outGoal->data_1;
current_goal.speed = outGoal->data_2;
break;
case TYPE_POSITION:
current_goal.x = outGoal->data_1;
current_goal.y = outGoal->data_2;
current_goal.speed = outGoal->data_3;
break;
case TYPE_PWM:
current_goal.x = outGoal->data_1;
current_goal.y = outGoal->data_2;
current_goal.period = outGoal->data_3;
break;
default:
break;
}
goals.out = (goals.out+1)%SIZE;
}
}
void clearGoals(){
goals.in = 0;
goals.out = 0;
}
bool fifoIsEmpty(){
return goals.in==goals.out;
}