Contest IOT GSE5
/
Nucleo_Robotik
En travaux...
main.cpp@0:c085b14ea8df, 2016-01-05 (annotated)
- Committer:
- Mickado
- Date:
- Tue Jan 05 15:18:53 2016 +0000
- Revision:
- 0:c085b14ea8df
- Child:
- 1:47b9204516a0
en travaux
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mickado | 0:c085b14ea8df | 1 | #include "mbed.h" |
Mickado | 0:c085b14ea8df | 2 | #include "HCSR04.h" |
Mickado | 0:c085b14ea8df | 3 | |
Mickado | 0:c085b14ea8df | 4 | #define ECHO_1 PA_9 |
Mickado | 0:c085b14ea8df | 5 | #define TRIG_1 PC_7 |
Mickado | 0:c085b14ea8df | 6 | #define MAXSIZE 10 |
Mickado | 0:c085b14ea8df | 7 | |
Mickado | 0:c085b14ea8df | 8 | DigitalIn bp(PUSH); |
Mickado | 0:c085b14ea8df | 9 | Serial pc(USBTX, USBRX); //UART |
Mickado | 0:c085b14ea8df | 10 | HCSR04 sensor1(TRIG_1, ECHO_1); |
Mickado | 0:c085b14ea8df | 11 | |
Mickado | 0:c085b14ea8df | 12 | |
Mickado | 0:c085b14ea8df | 13 | int i; |
Mickado | 0:c085b14ea8df | 14 | int distance[10] |
Mickado | 0:c085b14ea8df | 15 | |
Mickado | 0:c085b14ea8df | 16 | |
Mickado | 0:c085b14ea8df | 17 | /* |
Mickado | 0:c085b14ea8df | 18 | * fifo de taille size_ contenant des distances de type double, et accessible par les méthodes suivantes : |
Mickado | 0:c085b14ea8df | 19 | * -push : ajoute une donnée en entrée de la fifo |
Mickado | 0:c085b14ea8df | 20 | * -getn : retourne la distance de profondeur n. |
Mickado | 0:c085b14ea8df | 21 | */ |
Mickado | 0:c085b14ea8df | 22 | class fifo { |
Mickado | 0:c085b14ea8df | 23 | public: |
Mickado | 0:c085b14ea8df | 24 | void fifo(int n){ |
Mickado | 0:c085b14ea8df | 25 | size_=n; |
Mickado | 0:c085b14ea8df | 26 | } |
Mickado | 0:c085b14ea8df | 27 | void push(int value){ |
Mickado | 0:c085b14ea8df | 28 | for(i=size_-1;i>0;i--){ |
Mickado | 0:c085b14ea8df | 29 | distance_[i]=distance_[i-1]; |
Mickado | 0:c085b14ea8df | 30 | } |
Mickado | 0:c085b14ea8df | 31 | distance_[0]=value; |
Mickado | 0:c085b14ea8df | 32 | } |
Mickado | 0:c085b14ea8df | 33 | double getn(int n){ |
Mickado | 0:c085b14ea8df | 34 | return distance_[n]; |
Mickado | 0:c085b14ea8df | 35 | } |
Mickado | 0:c085b14ea8df | 36 | private : |
Mickado | 0:c085b14ea8df | 37 | double distance_[MAXSIZE]; |
Mickado | 0:c085b14ea8df | 38 | int size_; |
Mickado | 0:c085b14ea8df | 39 | } |
Mickado | 0:c085b14ea8df | 40 | |
Mickado | 0:c085b14ea8df | 41 | class PIDController{ |
Mickado | 0:c085b14ea8df | 42 | public: |
Mickado | 0:c085b14ea8df | 43 | PIDController(double Kp, double Ki, double Kd){ |
Mickado | 0:c085b14ea8df | 44 | |
Mickado | 0:c085b14ea8df | 45 | } |
Mickado | 0:c085b14ea8df | 46 | private: |
Mickado | 0:c085b14ea8df | 47 | |
Mickado | 0:c085b14ea8df | 48 | } |
Mickado | 0:c085b14ea8df | 49 | |
Mickado | 0:c085b14ea8df | 50 | int main() { |
Mickado | 0:c085b14ea8df | 51 | fifo fifoDist; |
Mickado | 0:c085b14ea8df | 52 | while(1) { |
Mickado | 0:c085b14ea8df | 53 | //On mesure la distance et on l'ajoute à la fifo |
Mickado | 0:c085b14ea8df | 54 | fifoDist.push(sensor1.distance(1)); |
Mickado | 0:c085b14ea8df | 55 | wait(0.2); |
Mickado | 0:c085b14ea8df | 56 | } |
Mickado | 0:c085b14ea8df | 57 | } |