Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: BLE-MegaPiSea_Rev2_WIP.cpp
- Revision:
- 3:b1e7eb9d61b7
- Parent:
- 2:fec3ed956ded
--- a/BLE-MegaPiSea_Rev2_WIP.cpp Thu Jun 27 09:08:17 2019 +0000
+++ b/BLE-MegaPiSea_Rev2_WIP.cpp Wed Jul 24 09:34:41 2019 +0000
@@ -32,9 +32,9 @@
// Input/Output
DigitalOut PostOutBI1 (PA_6); // Output 1 per pilotaggio input BI1 del Motore B Posteriore
-PwmOut PostOutPWB (PA_7); // Output per pilotaggio input PWM del motore B Posteriore
+PwmOut PostOutPWB (PB_6); // Output per pilotaggio input PWM del motore B Posteriore
//DigitalOut PostOutPWB (PA_7); // Scopi Diagnostici: Output Digitale per pilotaggio PWM del motore B Posteriore
-DigitalOut PostOutBI2 (PB_6); // Output 2 per pilotaggio input BI2 del Motore B Posteriore
+DigitalOut PostOutBI2 (PA_7); // Output 2 per pilotaggio input BI2 del Motore B Posteriore
DigitalIn PostInNE1 (PC_7); // Input per acquisire i segnali NET1 in output dall'encoder Posteriore
//DigitalInOut OutBlades (PB_9, PIN_OUTPUT, OpenDrain, 0); // Output per il pilotaggio del Relay di azionamento Lame Rotanti
@@ -86,6 +86,7 @@
+
//**********************************************/
// IRQ associata a Rx da BLE
//**********************************************/
@@ -118,6 +119,8 @@
cReadChar = myBLE.getc(); // Read character
if(cReadChar == 0x02)
{
+ pc.printf(">Ricevuto\r\n "); // visualizza comando inviato da BLE tramite pressione dei Button B1-B6
+
//-- command will be 8 bytes for joystick values
//-- command will be 3 bytes for button change event
//-- all valid command packets begin with <STX> (0x02) and end with <ETX> (0x03)
@@ -255,7 +258,7 @@
//++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++ INIZIO Ciclo Principale +++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++
-
+ /*
while(true)
{
//Ottieni X e Y dal Joystick e trasformali in comandi per il motore Right e Left:
@@ -335,7 +338,7 @@
AntOutPWB.write(float(fL/100.0)); // DutyCycle del PWM Sinistro (Anteriore)
}
} //while (true) Ciclo principale
-
+ */
//++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++ FINE Ciclo Principale +++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -346,9 +349,222 @@
//++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++ INIZIO Ciclo test +++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++
+ //++++++++++++ INIZIO Test modalità di funzionamento Motori con PWM ++++++++++++
+
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+
+ fDutyCycle = 0.0;
+
+ // inizializza il pin PWM
+ //+++PostOutPWB.period_us(100); // periodo del PWM Posteriore
+ //+++PostOutPWB.write(fDutyCycle); // duty cycle del PWM Posteriore
+ //+++AntOutPWB.period_us(100); // periodo del PWM Anteriore
+ //+++AntOutPWB.write(fDutyCycle); // duty cycle del PWM Anteriore
+ while(true)
+ {
+ if(cCommandBLE == 'A')
+ {
+ myLed = 0;
+ }
+ else
+ {
+ myLed = 1;
+ }
+ {
+ // Vai avanti Anteriore
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 1;
+ AntOutBI2 = 0;
+ PostOutPWB.write(0.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
+ pc.printf("Avanti Anteriore\r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ // Vai Indietro Anteriore
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 1;
+ PostOutPWB.write(0.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
+ pc.printf("Indietro Anteriore \r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ // Vai avanti Posteriore
+ PostOutBI1 = 1;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(0.0); // duty cycle del PWM Anteriore
+ pc.printf("Avanti Posteriore\r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ // Vai Indietro Posteriore
+ PostOutBI1 = 0;
+ PostOutBI2 = 1;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(0.0); // duty cycle del PWM Anteriore
+ pc.printf("Indietro Posteriore \r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+
+
+ // Vai avanti Anteriore + Posteriore
+ PostOutBI1 = 1;
+ PostOutBI2 = 0;
+ AntOutBI1 = 1;
+ AntOutBI2 = 0;
+ PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
+ pc.printf("Avanti Anteriore + Posteriore\r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ // Vai Indietro Anteriore + Posteriore
+ PostOutBI1 = 0;
+ PostOutBI2 = 1;
+ AntOutBI1 = 0;
+ AntOutBI2 = 1;
+ PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
+ pc.printf("Indietro Anteriore + Posteriore \r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ // Vai avanti Anteriore + Posteriore velocità ridotta
+ PostOutBI1 = 1;
+ PostOutBI2 = 0;
+ AntOutBI1 = 1;
+ AntOutBI2 = 0;
+ PostOutPWB.write(0.5); // duty cycle del PWM Posteriore
+ AntOutPWB.write(0.5); // duty cycle del PWM Anteriore
+ pc.printf("Avanti Anteriore + Posteriore velocita' ridotta\r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ // Vai Indietro Anteriore + Posteriore velocità ridotta
+ PostOutBI1 = 0;
+ PostOutBI2 = 1;
+ AntOutBI1 = 0;
+ AntOutBI2 = 1;
+ PostOutPWB.write(0.5); // duty cycle del PWM Posteriore
+ AntOutPWB.write(0.5); // duty cycle del PWM Anteriore
+ pc.printf("Indietro Anteriore + Posteriore velocita' ridotta\r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+
+
+ // Ruota a destra
+ PostOutBI1 = 0;
+ PostOutBI2 = 1;
+ AntOutBI1 = 1;
+ AntOutBI2 = 0;
+ PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
+ pc.printf("Ruota a Destra\r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ // Ruota a sinistra
+ PostOutBI1 = 1;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 1;
+ PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
+ pc.printf("Ruota a Sinistra\r\n");
+ wait (2);
+
+ // spegni
+ PostOutBI1 = 0;
+ PostOutBI2 = 0;
+ AntOutBI1 = 0;
+ AntOutBI2 = 0;
+ pc.printf("Fermo\r\n\r\n");
+ wait (3);
+
+ }
+ } // while(true) Test motore con PWM
+
+ //++++++++++++ FINE Test Motore con PWM ++++++++++++
//++++++++++++ INIZIO Test PWM tramite BLE ++++++++++++
-
+ /*
// inizializza segnali (BI1,BI2 = '1','0') per movimento CW. Per il movimento CCW (BI1,BI2 = '0','1'
PostOutBI1 = 1;
PostOutBI2 = 0;
@@ -494,14 +710,15 @@
}
}
} // while(true) Test motore con PWM pilotato da BLE
-
+ */
//++++++++++++ FINE Test PWM tramite BLE ++++++++++++
- //++++++++++++ INIZIO Test Motore con PWM ++++++++++++
- /*
+
+ /*
+ //++++++++++++ INIZIO Test Motore Destra o Sinistra con PWM ++++++++++++
PostOutBI1 = 1;
PostOutBI2 = 0;
- AntOutBI1 = 1;
+ AntOutBI1 = 0;
AntOutBI2 = 0;
fDutyCycle = 0.0;
@@ -509,19 +726,19 @@
// inizializza il pin PWM
PostOutPWB.period_us(100); // periodo del PWM Posteriore
PostOutPWB.write(fDutyCycle); // duty cycle del PWM Posteriore
- AntOutPWB.period_us(100); // periodo del PWM Anteriore
- AntOutPWB.write(fDutyCycle); // duty cycle del PWM Anteriore
+ //+++AntOutPWB.period_us(100); // periodo del PWM Anteriore
+ //+++AntOutPWB.write(fDutyCycle); // duty cycle del PWM Anteriore
while(true)
{
- if(cCommandBLE == 'A')
+ //+++if(cCommandBLE == 'A')
{
// Vai avanti
PostOutBI1 = 1;
PostOutBI2 = 0;
- AntOutBI1 = 1;
+ AntOutBI1 = 0;
AntOutBI2 = 0;
- PostOutPWB.write(0.5); // duty cycle del PWM Posteriore
- AntOutPWB.write(0.5); // duty cycle del PWM Anteriore
+ PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
+ AntOutPWB.write(0.0); // duty cycle del PWM Anteriore
pc.printf("Avanti\r\n\r\n");
wait (2);
@@ -531,15 +748,15 @@
AntOutBI1 = 0;
AntOutBI2 = 0;
pc.printf("Fermo\r\n\r\n");
- wait (1);
+ wait (3);
// Vai Indietro
PostOutBI1 = 0;
PostOutBI2 = 1;
AntOutBI1 = 0;
- AntOutBI2 = 1;
+ AntOutBI2 = 0;
PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
- AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
+ AntOutPWB.write(0.0); // duty cycle del PWM Anteriore
pc.printf("Indietro\r\n\r\n");
wait (2);
@@ -549,48 +766,16 @@
AntOutBI1 = 0;
AntOutBI2 = 0;
pc.printf("Fermo\r\n\r\n");
- wait (1);
-
- // Ruota a destra
- PostOutBI1 = 0;
- PostOutBI2 = 1;
- AntOutBI1 = 1;
- AntOutBI2 = 0;
- PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
- AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
- pc.printf("Destra\r\n\r\n");
- wait (2);
+ wait (3);
- // spegni
- PostOutBI1 = 0;
- PostOutBI2 = 0;
- AntOutBI1 = 0;
- AntOutBI2 = 0;
- pc.printf("Fermo\r\n\r\n");
- wait (1);
- // Ruota a sinistra
- PostOutBI1 = 1;
- PostOutBI2 = 0;
- AntOutBI1 = 0;
- AntOutBI2 = 1;
- PostOutPWB.write(1.0); // duty cycle del PWM Posteriore
- AntOutPWB.write(1.0); // duty cycle del PWM Anteriore
- pc.printf("Sinistra\r\n\r\n");
- wait (2);
-
- // spegni
- PostOutBI1 = 0;
- PostOutBI2 = 0;
- AntOutBI1 = 0;
- AntOutBI2 = 0;
- pc.printf("Fermo\r\n\r\n");
- wait (1);
}
- } // while(true) Test motore con PWM
+ } // while(true) Test motore con PWM
*/
- //++++++++++++ FINE Test Motore con PWM ++++++++++++
+ //++++++++++++ FINE Test Motore Destra o Sinistra con PWM ++++++++++++
+
+
//++++++++++++ INIZIO Test Motore ++++++++++++
/*