Projet

Général

Profil

Gestionnaire Petit Robot » Historique » Version 1

Anonyme, 08/12/2015 16:48

1 1 Anonyme
h1. Gestionnaire Petit Robot
2
3
<pre>
4
/* Programme gestionnaire du Petit Robot
5
Justin CANO, le 7-12-2015 
6
7
    I - Constantes globales */ 
8
int declenchement = 2;
9
int parasol = 3;
10
int belierFin = 4;
11
int capteurG = A0;
12
int capteurD = A1;
13
int capteurA = A2;
14
15
float vitesseTranslation=0.0;
16
float vitesseRotation=0.0;
17
18
//communication i2c
19
boolean req=false;
20
#include <Wire.h>
21
22
//  II - Méthodes 
23
24
void setup () {
25
  pinMode(parasol,OUTPUT);
26
  Wire.begin(8);                // join i2c bus with address #8
27
  Wire.onReceive(receiveEvent); // register event
28
  Wire.onRequest(requestEvent); //request event
29
}
30
31
void loop () {
32
  principal();
33
}
34
35
void principal () {
36
  boolean depart = digitalRead(declenchement); //déclenchement du programme lorqu'un état haut se présente au robot
37
  boolean a = true;
38
  moteurZero();
39
  long tdepart;
40
  while(depart) {
41
    if(a) {
42
      tdepart = millis(); // l'échelle de temps commence ici (décompte des 90 s) est initialisée UNE fois
43
    }
44
    a=false; //on interdit la réinitialisation
45
    long t=millis(); // mesure du temps absolu
46
    if(t-tdepart<90000) { //durant le match
47
      fermePorte();
48
    }
49
    else { // après le match
50
      moteurZero();
51
      ouvreParasol();
52
    }
53
  delayMicroseconds(20); //petit delay pour la forme
54
  }
55
  delayMicroseconds(20); //petit delay pour la forme
56
}
57
58
void fermePorte() { // fermeture des portes par contour du décor
59
// A DETERMINER
60
}
61
  
62
float distanceIr(int tensionCodee) {
63
  // Distance en mm donnée par l'IR avec pour entrée un digital Read
64
 return 0.0;
65
}
66
67
void moteurZero() { //ordonne l'arrêt de ces derniers
68
}
69
70
void ouvreParasol() {//ouverture du parasol
71
72
}
73
74
void receiveEvent(int howMany) {
75
  float variationMotorG;
76
  float variationMotorD;
77
  while (1 < Wire.available()) { // loop through all but the last
78
    int c = Wire.read(); // receive byte as a character
79
    //Serial.print(c);         // print the character
80
    variationMotorG=((float) c)/10.0;
81
  }
82
   while (Wire.available()) { // loop through all but the last
83
    int c = Wire.read(); // receive byte as a character
84
    //Serial.print(c);         // print the character
85
    variationMotorD=((float) c)/10.0;
86
  }
87
}
88
89
void requestEvent() {
90
  if (req==false) {
91
    int translation=(int)(vitesseTranslation*10.0);
92
    Wire.write(translation);
93
    //Serial.print(i);
94
    //Serial.print(" ");
95
    req=true;
96
  } else if (req==true) {
97
    int rotation= (int)(vitesseRotation*100.0);
98
    req=false;
99
    Wire.write(rotation);
100
    //Serial.println(x);
101
  }
102
}
103
104
105
    
106
107
108
</pre>