From: Andrea Manni Date: Thu, 6 Apr 2017 15:14:17 +0000 (+0200) Subject: Cleanup X-Git-Url: http://git.piffa.net/web?p=rover;a=commitdiff_plain;h=24b5e111ad1899efc45338275e7380536382aced Cleanup --- diff --git a/prototypes/macchina/fsm/base/base.ino b/prototypes/macchina/fsm/base/base.ino index 2ac12cb..4dada11 100644 --- a/prototypes/macchina/fsm/base/base.ino +++ b/prototypes/macchina/fsm/base/base.ino @@ -12,17 +12,12 @@ Codice: http://git.andreamanni.com/web?p=rove #include "rover.h" #include "Servo.h" -#define dEBUG int rotPausa = 500; // Pausa per una rotazione di ~90' void setup() { abilita(); -#ifdef DEBUG - Serial.begin(9600); - Serial.println("Attivazione sketch"); -#endif } @@ -46,9 +41,6 @@ void loop() delay(10); // Movimento minimo, per stabilizzare // l'input del sensore if (distanceCheck()) { -#ifdef DEBUG -Serial.println("\t ###### Ostacolo! ######"); -#endif stato = check ; } @@ -78,27 +70,15 @@ Serial.println("\t ###### Ostacolo! ######"); // Inversione servoMiddle(); stato = inversione ; -#ifdef DEBUG -Serial.print("Stato: "); -Serial.println(stato); -#endif break; case sx: -#ifdef DEBUG -Serial.print("Stato: "); -Serial.println(stato); -#endif giraSX(); delay(giroPausa); stato = forward ; break; case dx: -#ifdef DEBUG -Serial.print("Stato: "); -Serial.println(stato); -#endif giraDX(); delay(giroPausa); stato = forward ; @@ -111,10 +91,6 @@ Serial.println(stato); break; case inversione: -#ifdef DEBUG -Serial.print("Stato: "); -Serial.println(stato); -#endif stop(); indietro(); // Why not? :) delay(giroPausa * 1); @@ -130,10 +106,4 @@ Serial.println(stato); break; } -#ifdef DEBUG -//Serial.print("Stato: "); -//Serial.println(stato); -//Serial.print("Distanza: "); -//Serial.println(distanceMonitor()); -#endif } diff --git a/prototypes/macchina/fsm/base_debug/base_debug.ino b/prototypes/macchina/fsm/base_debug/base_debug.ino new file mode 100644 index 0000000..2ac12cb --- /dev/null +++ b/prototypes/macchina/fsm/base_debug/base_debug.ino @@ -0,0 +1,139 @@ +/* FSM Base + +Prototipo rozzo per il movimento utilizzando le funzioni +di base della libreria Rover e una FSM. + + +Schema: https://lab.piffa.net/schemi/2wd_car_bb.png +Codice: http://git.andreamanni.com/web?p=rove + +*/ + + +#include "rover.h" +#include "Servo.h" +#define dEBUG + +int rotPausa = 500; // Pausa per una rotazione di ~90' + +void setup() +{ + abilita(); +#ifdef DEBUG + Serial.begin(9600); + Serial.println("Attivazione sketch"); +#endif +} + + +// FSM +enum { // Stati della FMS + forward, + check, // Cerca percorso libero + sx, // sx + dx, // dx + ferma, + inversione +} stato = forward; + +const int giroPausa = 630 ; // Tempo necessario per rotazione +void loop() +{ + switch (stato) { + case forward: + servoMiddle(); + avanti(); + delay(10); // Movimento minimo, per stabilizzare + // l'input del sensore + if (distanceCheck()) { +#ifdef DEBUG +Serial.println("\t ###### Ostacolo! ######"); +#endif + stato = check ; + } + + break; + + case check: + if (!distanceCheck()) { + stato = forward ; + break; + } + stop(); +// check dx + servoDX(); + if (!distanceCheck()) { + stato = dx ; + servoMiddle(); + break; + } + +// check sx + servoSX(); + if (!distanceCheck()) { + stato = sx ; + servoMiddle(); + break; + } +// Inversione + servoMiddle(); + stato = inversione ; +#ifdef DEBUG +Serial.print("Stato: "); +Serial.println(stato); +#endif + break; + + case sx: +#ifdef DEBUG +Serial.print("Stato: "); +Serial.println(stato); +#endif + giraSX(); + delay(giroPausa); + stato = forward ; + break; + + case dx: +#ifdef DEBUG +Serial.print("Stato: "); +Serial.println(stato); +#endif + giraDX(); + delay(giroPausa); + stato = forward ; + break; + + case ferma: + stop(); + delay(1000); + stato = check ; + break; + + case inversione: +#ifdef DEBUG +Serial.print("Stato: "); +Serial.println(stato); +#endif + stop(); + indietro(); // Why not? :) + delay(giroPausa * 1); + giraDX(); + delay(giroPausa * 3); + stato = check ; + break; + + default: + stop(); + delay(2000); + stato = check ; + break; + } + +#ifdef DEBUG +//Serial.print("Stato: "); +//Serial.println(stato); +//Serial.print("Distanza: "); +//Serial.println(distanceMonitor()); +#endif +} diff --git a/prototypes/macchina/fsm/simple/simple.ino b/prototypes/macchina/fsm/simple/simple.ino deleted file mode 100644 index ad16c4b..0000000 --- a/prototypes/macchina/fsm/simple/simple.ino +++ /dev/null @@ -1,106 +0,0 @@ -/* FSM Base - -Prototipo rozzo per il movimento utilizzando le funzioni -di base della libreria Rover e una FSM. - - -Schema: https://lab.piffa.net/schemi/2wd_car_bb.png -Codice: http://git.andreamanni.com/web?p=rove - -*/ - - -#include "rover.h" -#include "Servo.h" - -int rotPausa = 500; // Pausa per una rotazione di ~90' - -void setup() -{ - abilita(); - servoMiddle(); -} - - -// FSM -enum { // Stati della FMS - forward, - check, // Cerca percorso libero - sx, // sx - dx, // dx - ferma, - inversione -} stato = forward; - -const int giroPausa = 500 ; // Tempo necessario per rotazione -void loop() -{ - switch (stato) { - case forward: - servoMiddle(); - avanti(); - delay(50); // Movimento minimo, per stabilizzare - // l'input del sensore - if (distanceCheck()) { - stato == check ; - } - - break; - - case check: - if (!distanceCheck()) { - stato == forward ; - break; - } - stop(); -// check dx - servoDX(); - if (!distanceCheck()) { - stato == dx ; - servoMiddle(); - break; - } - -// check sx - servoSX(); - if (!distanceCheck()) { - stato == sx ; - servoMiddle(); - break; - } -// Inversione - servoMiddle(); - stato == inversione ; - break; - - case sx: - giraSX(); - delay(giroPausa); - break; - - case dx: - giraDX(); - delay(giroPausa); - break; - - case ferma: - stop(); - delay(1000); - stato == check ; - break; - - case inversione: - stop(); - indietro(); // Why not? :) - delay(1000); - delay(giroPausa * 2); - stato == check ; - break; - - default: - stop(); - delay(2000); - stato == check ; - break; - } -}