Projet vierge pour lancer les programmes

Dependencies:   Encoder_Nucleo_32_bits PwmIn mbed

Fork of v2bis by Chafik ZERROUKI

Files at this revision

API Documentation at this revision

Comitter:
haarkon
Date:
Mon May 29 16:23:47 2017 +0000
Parent:
0:f00e68bef80c
Child:
2:1d440e938c44
Commit message:
Evo pour utilisation de la pixy

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat May 27 15:15:41 2017 +0000
+++ b/main.cpp	Mon May 29 16:23:47 2017 +0000
@@ -78,9 +78,9 @@
  * PA_7    -> CNY2 (Analog In)
  * PA_8    -> Servomoteur (PWM Out)
  * PA_9    -> US Trigger #3 (Digital Out)
- * PA_10   -> I (Encodeur Droit) (IRQ In)
+ * PA_10   -> US Echo #1 (Pwm In)
  * PA_11   -> US Echo #2 (Pwm In)
- * PA_12   -> US Echo #1 (Pwm In)
+ * PA_12   -> SS (SPI Slave Select) (Digital Out)
  * PA_13
  * PA_14
  * PA_15   -> Boussole (Pwm In)
@@ -123,7 +123,7 @@
  * PD_2    -> Led2 (Digital Out)
  */
 
-Serial      Pixy    (PA_0, PA_1, 115200);
+Serial      Pixy    (PA_0, PA_1, 230400);
 Serial      Pc      (PA_2, PA_3, 460800);
 
 AnalogIn    CNY1    (PC_4);
@@ -143,22 +143,22 @@
 DigitalOut  En      (PC_9);
 DigitalOut  SensG   (PC_8);
 DigitalOut  SensD   (PC_6);
+DigitalOut  SS      (PA_12);
 
-InterruptIn Echo1   (PA_12);
+InterruptIn Echo1   (PA_10);
 InterruptIn Echo2   (PA_11);
 InterruptIn Echo3   (PB_12);
 InterruptIn BP      (PC_13);
 InterruptIn IG      (PC_7);
-InterruptIn ID      (PA_10);
+
+PwmIn       PWMG    (PB_2);
+PwmIn       PWMD    (PB_1);
+PwmIn       PWMB    (PA_15);
 
 PwmOut      Pwm_MG  (PB_10);
 PwmOut      Pwm_MD  (PB_3);
 PwmOut      Servo   (PA_8);
 
-PwmIn       PWMG    (PB_2);
-PwmIn       PWMD    (PB_1);
-PwmIn       PWMB    (PA_15);
-
 I2C         Bus_I2C (PB_9, PB_8);
 
 SPI         MotG    (PC_12, PC_11, PC_10);
@@ -188,7 +188,7 @@
 
 //  Dialogue avec la Pixy
 T_pixyData  Pixy_FIFO[20];
-Byte        Pixy_nbObjet = 0, Pixy_wObjet = 0, pixy_rObjet = 0;
+Byte        Pixy_nbObjet = 0, Pixy_wObjet = 0, Pixy_rObjet = 0;
 
 // Gestion des capteurs Ultrason
 long        Echo1Start, Echo2Start, Echo3Start;
@@ -218,7 +218,6 @@
 void echo2Rise ()
 {
     Echo2Start = temps.read_us();
-    Led2 = !Led2;
 }
 
 void echo3Rise ()
@@ -252,6 +251,7 @@
     static int          Pixy_synced = 0;
     int i;
 
+    Led2 = ! Led2;
     if (!Pixy_synced) {                                                     // On n'a pas trouvé le départ (0x55aa55aa ou 0x55aa56aa)
         tmpBuffer.tab[bytecount] = Pixy.getc();                             // On stocke l'octet reçu dans la première case dispo du tableau temporaire
         if (bytecount < 3) {                                                // Si on n'a pas encore reçu les 4 premier octets
@@ -317,8 +317,8 @@
     Echo2.fall (&echo2Fall);
     Echo3.fall (&echo3Fall);
 
+    BP.enable_irq();
     IG.enable_irq();
-    ID.enable_irq();
     Echo1.enable_irq();
     Echo2.enable_irq();
     Echo3.enable_irq();
@@ -435,18 +435,18 @@
                         FlagTickLed = 0;
                     }
 
-                    if (((Tick%150)==0)&& FlagTick) {
+                    if (((Tick%150)==0) && FlagTick) {
                         FlagTick = 0;
                         if (BOUSSOLE_check==0) {
                             CAP_PWM = ((PWMB.pulsewidth()*1000)-1)*10;
-                            Pc.printf ("\r PWM = %4.1lf\t", CAP_PWM);
+                            Pc.printf ("\r PWM = %4.1lf", CAP_PWM);
                         }
-                        if (I2C_check==0) {
+                        //if (I2C_check==0) {
                             Bus_I2C.write(BOUSSOLE_adress,BOUSSOLE_status, 1, true);
                             Bus_I2C.read (BOUSSOLE_adress,I2C_registerValue,4);
                             CAP_I2C = (double)(((unsigned short)I2C_registerValue[2]<<8)+(unsigned short)I2C_registerValue[3])/10.0;
-                            Pc.printf ("\t I2C = %4.1lf\r", CAP_I2C);
-                        }
+                            Pc.printf ("\r\t\t I2C = %4.1lf", CAP_I2C);
+                        //}
                     }
                 } while(!Pc.readable());
                 MENU_choix = Pc.getc();
@@ -601,82 +601,91 @@
                 Pc.printf ("\n\n\rPixy\n");
                 Pc.printf ("\rAppuyez sur Entree pour quitter\n");
                 do {
-                    if ((Tick%2)==0) {
+                    if (((Tick%50)==0) && FlagTick) {
+                        FlagTick = 0;
                         switch (phase) {
                             case 0 :
                                 PIXY_red += 5;
-                                if (PIXY_red == 255) phase = 1;
+                                if (PIXY_red == 255) {
+                                    phase = 1;
+                                    //Pc.printf ("\rPhase  1");
+                                }
                                 break;
                             case 1 :
                                 PIXY_green += 5;
-                                if (PIXY_green == 255) phase = 2;
+                                if (PIXY_green == 255) {
+                                    phase = 2;
+                                    //Pc.printf ("\rPhase  2");
+                                }
                                 break;
                             case 2 :
                                 PIXY_red -= 5;
-                                if (PIXY_red == 0) phase = 3;
+                                if (PIXY_red == 0)  {
+                                    phase = 3;
+                                    //Pc.printf ("\rPhase  3");
+                                }
                                 break;
                             case 3 :
                                 PIXY_blue += 5;
-                                if (PIXY_blue == 255) phase = 4;
+                                if (PIXY_blue == 255)  {
+                                    phase = 4;
+                                    //Pc.printf ("\rPhase  4");
+                                }
                                 break;
                             case 4 :
                                 PIXY_green -= 5;
-                                if (PIXY_green == 0) phase = 5;
+                                if (PIXY_green == 0)  {
+                                    phase = 5;
+                                    //Pc.printf ("\rPhase  5");
+                                }
                                 break;
                             case 5 :
                                 PIXY_red += 5;
-                                if (PIXY_red == 255) phase = 6;
+                                if (PIXY_red == 255)  {
+                                    phase = 6;
+                                    //Pc.printf ("\rPhase  6");
+                                }
                                 break;
                             case 6 :
                                 PIXY_green += 5;
-                                if (PIXY_green == 255) phase = 7;
+                                if (PIXY_green == 255)  {
+                                    phase = 7;
+                                    //Pc.printf ("\rPhase  7");
+                                }
                                 break;
                             case 7 :
                                 PIXY_red -= 5;
-                                if (PIXY_red == 0) phase = 8;
-                                break;
-                            case 8 :
                                 PIXY_green -= 5;
-                                if (PIXY_green == 0) phase = 9;
-                                break;
-                            case 9 :
-                                PIXY_red += 5;
-                                if (PIXY_red == 255) phase = 10;
-                                break;
-                            case 10 :
-                                PIXY_blue -= 5;
-                                if (PIXY_blue == 0) phase = 11;
-                                break;
-                            case 11 :
-                                PIXY_green += 5;
-                                if (PIXY_green == 255) phase = 12;
-                                break;
-                            case 12 :
-                                PIXY_green += 5;
-                                if (PIXY_green == 255) phase = 13;
-                                break;
-                            case 13 :
-                                PIXY_red -= 5;
-                                if (PIXY_red == 0) phase = 14;
-                                break;
-                            case 14 :
-                                PIXY_green -= 5;
-                                if (PIXY_green == 0) phase = 0;
+                                PIXY_blue -=5;
+                                if (PIXY_red == 0)  {
+                                    phase = 0;
+                                    //Pc.printf ("\rPhase  0");
+                                }
                                 break;
                         }
                         Pixy.putc(0);
-                        Pixy.putc(0xFF);
+                        Pixy.putc(0xFD);
                         Pixy.putc(PIXY_red);
                         Pixy.putc(PIXY_green);
                         Pixy.putc(PIXY_blue);
 
-                        if ((Tick%50)==0) {
-                            Pc.printf ("\r Nombre d'objets detecte = %d",Pixy_nbObjet);
-                            FlagPixy = 0;
-                            Pixy_nbObjet = 0;
-                        }
+                        while (Pixy_nbObjet) {
+                            Pc.printf ("\r%5hd = %5hd,%5hd : %5hdx%5hd", Pixy_FIFO[Pixy_rObjet].CCbloc.signature, Pixy_FIFO[Pixy_rObjet].CCbloc.x, Pixy_FIFO[Pixy_rObjet].CCbloc.y, Pixy_FIFO[Pixy_rObjet].CCbloc.width, Pixy_FIFO[Pixy_rObjet].CCbloc.height);
+                            
+                            if (Pixy_nbObjet>1) Pc.printf("\n");
+                        
+                            if (Pixy_rObjet<19) Pixy_rObjet++;
+                            else Pixy_rObjet = 0;
+
+                            Pixy_nbObjet--;
+                        }                                
+                        FlagPixy = 0;
                     }
-                    if ((Tick%100)==0) Led1 = !Led1;
+
+                    if (FlagTickLed) {
+                        Led1 = !Led1;
+                        FlagTickLed = 0;
+                    }
                 } while(!Pc.readable());
                 MENU_choix = Pc.getc();
                 break;
--- a/mbed.bld	Sat May 27 15:15:41 2017 +0000
+++ b/mbed.bld	Mon May 29 16:23:47 2017 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/4eea097334d6
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/86740a56073b
\ No newline at end of file