]> git.piffa.net Git - aerei/commitdiff
Bugatti problems
authoreaman <eaman@sid>
Thu, 23 Feb 2017 22:38:10 +0000 (23:38 +0100)
committereaman <eaman@sid>
Thu, 23 Feb 2017 22:38:10 +0000 (23:38 +0100)
aerei/antonino/bugatti_fsm/bugatti_fsm.ino
aerei/antonino/bugatti_fsm2/bugatti_fsm2.ino [new file with mode: 0644]
aerei/antonino/bugatti_fsm_mix/bugatti_fsm_mix.ino
aerei/cirso/trigger_transition/trigger_transition.ino
aerei/daniele/fsm/fsm.ino

index 5099f7f0635002a44bbc19e53a97e38a7ce595ca..b977036aaf4e6f30f7ef9db224d2837cb4c78e16 100644 (file)
@@ -10,7 +10,7 @@ Inputs:
    Lettura alettoni con interrupt 0 (PIN2)
 
 TODO:
-* Cambiare il PIN del throttle su A5 da A3
+* Cambiare il PIN del throttle su A2 da A3
 * attaccare il canale degli alettoni al pin2
 * guardare che tipo di RGB e', anodo o cat 
 * a full throttle RGB fa un Rand, vedere che non vada in conflitto con la sec FSM
@@ -18,7 +18,7 @@ TODO:
 */
 
 #include <common.h>
-#define dEBUG
+#define DEBUG
 
 // LED disponibili
 Lampeggiatore left = 7;
@@ -26,7 +26,7 @@ Lampeggiatore right = 8;
 Pwm motore = 3;
 
 // RGB
-RGBLed ailerons(6,5,9);
+RGBLed ailerons(6,5,9,255);
     // Transizione: lampeggiatori sui PIN RGB
     Lampeggiatore sxLamp(5); // Lampeggiatore
     Lampeggiatore dxLamp(9); // Lampeggiatore
@@ -37,7 +37,7 @@ RGBLed ailerons(6,5,9);
 
 // Var thr
 //////////////// !!!! cambiare thrIn
-const byte thrPin = A5; // PIN collegato al CH3
+const byte thrPin = A2; // PIN collegato al CH3
 byte thr ;  // Throttle a 8bit
 int thrIn ; // Valore del th in ingresso dal servo
 
@@ -47,10 +47,9 @@ volatile unsigned int chStart2 = 1500; // Inizio rilevamento
 
 // Variabili per autocalibrazione 0
 const byte chPin2 = 2; // PIN per la calibrazione
-int mid_point2 = 1500;
 
 // Vars Alettoni
-int mid_point = 1560 ; // centro del segnale, trimmato nel setup
+int mid_point = 1452 ; // centro del segnale, trimmato nel setup
 const int deviation = 50 ; // deviazione dal punto medio
         //per entrare nello stato successivo dal centro
 
@@ -91,7 +90,7 @@ void setup() {
   delay(4000);
 
 
-mid_point =  calibraTrim(chPin2) + 8 ; // + LED di servizio per monitor calibrazione
+//mid_point =  calibraTrim(chPin2) + 8 ; // + LED di servizio per monitor calibrazione
 #ifdef DEBUG
    Serial.begin(9600);
 #endif
diff --git a/aerei/antonino/bugatti_fsm2/bugatti_fsm2.ino b/aerei/antonino/bugatti_fsm2/bugatti_fsm2.ino
new file mode 100644 (file)
index 0000000..d743daf
--- /dev/null
@@ -0,0 +1,213 @@
+/* Bugatti di Antonino
+
+Outputs:
+   2 LED / Strisce laterali che lampeggiano alternativamente
+   1 LED in PWM per il motore 
+   1 Striscia RGB sotto per tutta la lunghezza delle ali
+
+Inputs:
+   Lettura del canale Throttle (3) con la funzione Pulsein
+   Lettura alettoni con interrupt 0 (PIN2)
+
+TODO:
+* Cambiare il PIN del throttle su A2 da A3
+* attaccare il canale degli alettoni al pin2
+* guardare che tipo di RGB e', anodo o cat 
+* a full throttle RGB fa un Rand, vedere che non vada in conflitto con la sec FSM
+
+*/
+
+#include <common.h>
+#define DEBUG
+
+// LED disponibili
+Lampeggiatore left = 7;
+Lampeggiatore right = 8;
+Pwm motore = 3;
+
+// RGB
+RGBLed ailerons(6,5,9,255);
+    // Transizione: lampeggiatori sui PIN RGB
+    Lampeggiatore sxLamp(5); // Lampeggiatore
+    Lampeggiatore dxLamp(9); // Lampeggiatore
+//Pwm rsotto = 6;
+//Pwm gsotto = 5;
+//Pwm bsotto = 3;
+
+
+// Var thr
+//////////////// !!!! cambiare thrIn
+const byte thrPin = A2; // PIN collegato al CH3
+byte thr ;  // Throttle a 8bit
+int thrIn ; // Valore del th in ingresso dal servo
+
+// Variabili per interrupt 0 su PIN 2
+volatile unsigned int ail = 1500; // Valore computato
+volatile unsigned int chStart2 = 1500; // Inizio rilevamento
+
+// Variabili per autocalibrazione 0
+const byte chPin2 = 2; // PIN per la calibrazione
+
+// Vars Alettoni
+int mid_point = 1432 ; // centro del segnale, trimmato nel setup
+const int deviation = 50 ; // deviazione dal punto medio
+        //per entrare nello stato successivo dal centro
+
+
+// FSM gestione alettoni
+enum  { // Stati della FMS
+    middle,   // centrale
+    sxin,     // transizione a sx
+    sx,       // sx
+    dxin,     // transizione a dx
+    dx        // dx
+} ailstate  = middle;
+
+// Vars FSM
+unsigned long FSM_lastMillis = 0 ; // Timestamp per la FSM degli alettoni
+unsigned long pausa = 600;  // Pausa per la transizione durante gli stati 2, 4 della FSM
+
+// Variabili comuni:
+unsigned long currentMillis; // timestamp reference per millis per tutto il loop
+byte caso ; // Valore random 
+
+
+void setup() {
+  // I PINs vengono impostati dal constructor al momento
+  // della dichiarazione dell'ogetto.
+  pinMode(thrPin,INPUT);
+  right.Invert() ;  // Opzionale: inverte l'ordine del lampeggio da
+
+  attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
+
+  randomSeed(analogRead(0));
+
+  // Test iniziale dei LED per verifica contatti:
+  left.High();
+  right.High();
+  ailerons.White();
+  motore.Set(255);
+  delay(4000);
+
+
+//mid_point =  calibraTrim(chPin2) + 8 ; // + LED di servizio per monitor calibrazione
+#ifdef DEBUG
+   Serial.begin(9600);
+#endif
+}
+
+void loop() {
+currentMillis = millis(); // Timestamp per tutto il loop
+    
+// Lettura CH3
+  thrIn = pulseIn(thrPin, HIGH, 25000);
+  // Hint: thrIn andrebbe calibrato son un Serial.write
+  if (thrIn != 0) {
+thr = map(thrIn, 870, 2000, 0, 255);
+};
+
+    
+// Gestione throttle
+  if (thr >= 0 && thr < 15) {
+    // IDLE
+
+    right.Blink();
+    left.Blink();
+    motore.UD(2000);
+  } else if (thr < 245) {
+    // Throttle medio
+      
+    right.Blink(1120 - 4 * thr );
+    left.Blink(1120 - 4 * thr );
+    motore.lSet(thr);   // Luminosita' proporzionale al throttle
+  } else {
+    // Throttle al massimo: LED laterali lampeggiano a caso,
+    // Sotto luminosita' a caso
+
+    caso = random(20, 240) ;
+    right.Swap();
+    left.Swap();
+    motore.lSet(caso);
+// TODO: check this
+       ailerons.Rand();
+    delay(caso);
+  }
+
+
+
+  //// Ailerons:
+switch (ailstate) {
+    case middle:
+        ailerons.White();
+        // Alettoni piatti
+        if (ail > mid_point + deviation + deviation /3) {
+            // extra margine per avere un po' di gioco
+            ailstate = sxin;
+            FSM_lastMillis = currentMillis;
+        }
+        else if (ail < mid_point - deviation - deviation / 3) {
+            ailstate = dxin;
+            ailerons.Off();
+            FSM_lastMillis = currentMillis ;
+        } ;
+        break;
+
+    case sxin:
+        // Transizione a sx
+        sxLamp.Blink(150);
+        if (currentMillis - pausa > FSM_lastMillis ) {
+            ailstate = sx;
+        }
+        break;
+case sx:
+        ailerons.Green();
+        if (ail < mid_point + deviation) {
+            ailstate = middle;
+        }
+        else if (ail < mid_point - deviation) {
+            FSM_lastMillis = currentMillis;
+            ailstate = dxin;
+        } ;
+        break;
+
+    case dxin:
+        // Transizione a dx
+        dxLamp.Blink(150);
+        if (currentMillis - pausa > FSM_lastMillis ) {
+            ailstate = dx;
+        }
+        break;
+
+    case dx:
+        ailerons.Blue();
+        if (ail > mid_point - deviation) {
+            ailstate = middle;
+        }
+        else if (ail > mid_point + deviation) {
+            FSM_lastMillis = currentMillis;
+            ailstate = dxin;
+        } ;
+        break;
+    }
+
+
+#ifdef DEBUG
+Serial.print(thrIn);
+    Serial.print("\tthr: ");
+Serial.print(thr);
+    Serial.print("\tail: ");
+    Serial.print(ail);
+    Serial.print("\t ailstate:");
+    Serial.println(ailstate);
+#endif
+}
+// ISRs
+void chRise2() {
+    attachInterrupt(0, chFall2, FALLING);
+    chStart2 = micros();
+}
+
+void chFall2() {
+    attachInterrupt(0, chRise2, RISING);
+    ail = micros() - chStart2;
+}
index 4c03df0b7115eb38503a6a8b2b7d8489d52b6a47..abf6cb72eac5217c44fe1f4b0691ad128ffd75f9 100644 (file)
@@ -18,7 +18,7 @@ TODO:
 */
 
 #include <common.h>
-#define dEBUG
+#define DEBUG
 
 // LED disponibili
 Lampeggiatore left = 7;
@@ -26,7 +26,7 @@ Lampeggiatore right = 8;
 Pwm motore = 3;
 
 // RGB
-RGBLed ailerons(6,5,9);
+RGBLed ailerons(6,5,9,255);
 // Transizione: lampeggiatori sui PIN RGB
 Lampeggiatore sxLamp(5); // Lampeggiatore
 Lampeggiatore dxLamp(9); // Lampeggiatore
@@ -37,7 +37,7 @@ Pwm bsotto = 3;
 
 // Var thr
 //////////////// !!!! cambiare thrIn
-const byte thrPin = A5; // PIN collegato al CH3
+const byte thrPin = A2; // PIN collegato al CH3
 byte thr ;  // Throttle a 8bit
 int thrIn ; // Valore del th in ingresso dal servo
 
@@ -45,13 +45,11 @@ int thrIn ; // Valore del th in ingresso dal servo
 volatile unsigned int ail = 1500; // Valore computato
 volatile unsigned int chStart2 = 1500; // Inizio rilevamento
 
-// Variabili per autocalibrazione 0
-const byte chPin2 = 2; // PIN per la calibrazione
-int mid_point2 = 1500;
 
 // Vars Alettoni
-int mid_point = 1560 ; // centro del segnale, trimmato nel setup
-const int deviation = 50 ; // deviazione dal punto medio
+const byte chPin2 = 2; // PIN per la calibrazione
+int mid_point = 1450 ; // centro del segnale, trimmato nel setup
+const int deviation = 40 ; // deviazione dal punto medio
 //per entrare nello stato successivo dal centro
 
 
@@ -104,7 +102,7 @@ void loop() {
     thrIn = pulseIn(thrPin, HIGH, 25000);
     // Hint: thrIn andrebbe calibrato son un Serial.write
     if (thrIn != 0) {
-        thr = map(thrIn, 960, 2000, 0, 255);
+        thr = map(thrIn, 870, 2000, 0, 255);
     };
 
 
@@ -118,7 +116,7 @@ void loop() {
         // RGB
         rsotto.lDown(3000);
         gsotto.lUp(1000);
-        bsotto.lup(2000);
+        bsotto.lUp(2000);
 
 
     } else if (thr < 245) {
@@ -158,7 +156,7 @@ void loop() {
             break;
 
         case sx:
-            ailerons.Green();
+            ailerons.Red();
             if (ail < mid_point + deviation) {
                 ailstate = middle;
             }
@@ -212,6 +210,8 @@ void loop() {
     Serial.print(ail);
     Serial.print("\t ailstate:");
     Serial.println(ailstate);
+    //Serial.print("\t mid_point:");
+    //Serial.print(mid_point);
 #endif
 }
 // ISRs
index bcb36d5909e4c00bcd1a57425c2851d8e39f6341..73128d43636459a4bcc29b9a6d965a25163fafee 100644 (file)
@@ -1,4 +1,4 @@
-/* Cirso TransStates
+/* Cirso TransStates Focke-Wulf Fw 190
 
 Output:
    2 LED ai lati con lampeggio alternato
index 98ee6c9ab36b66eadaad8edfeb06bb0a58da5bde..60ac8a00989dcbf49cfdcf53f6ae68ec26cb70d5 100644 (file)
@@ -65,11 +65,11 @@ codadx.Invert();
   // HI -> LOW --> LOW -> HI
   // per avere 2 LED che lampeggiano alternativamente
     // Funzione relativa a calibrazione con pulsein:
-    //mid_point2 =  calibraTrim(chPin2) ; // Calibrazione del TRIM attivo sul canale
+    mid_point2 =  calibraTrim(chPin2) ; // Calibrazione del TRIM attivo sul canale
     //mid_point3 =  calibraTrim(chPin3) ; // Calibrazione del TRIM attivo sul canale
     attachInterrupt(0, chRise2, RISING); // PIN 2 su 328p / 168
     attachInterrupt(1, chRise3, RISING); // PIN 3 su 328p / 168
-#ifdef DEBUG
+#ifdef dEBUG
 Serial.begin(9600); 
 #endif
 }
@@ -94,10 +94,10 @@ pright.lDown(1000);
         // Throttle al massimo: LED laterali lampeggiano a caso,
         // Sotto luminosita' a caso
         caso = random(30, 250) ;
-pleft.Set(); 
-pright.Set(); 
-pcodasx.Set();
-pcodadx.Set();
+pleft.Set(caso); 
+pright.Set(caso); 
+pcodasx.Set(caso);
+pcodadx.Set(caso);
         delay(caso);
     }
     else {