seconda prova motore

Dependencies:   X_NUCLEO_IHM12A1 X_NUCLEO_IKS01A2 mbed

Fork of prova_motore by duckietownhsunina

Files at this revision

API Documentation at this revision

Comitter:
das94
Date:
Fri Feb 17 12:04:56 2017 +0000
Parent:
5:1808ddbbef21
Commit message:
prova motore 2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Feb 16 12:20:59 2017 +0000
+++ b/main.cpp	Fri Feb 17 12:04:56 2017 +0000
@@ -18,13 +18,17 @@
 
 /* Motor Control Component. */
 STSPIN240_250 *motor;
+int s1;
+int s0;
+
+
+
 
 
 /* Main ----------------------------------------------------------------------*/
 
 int main()
 {
-
     uint8_t demoStep = 0;
    // riv
     /* Initializing Motor Control Component. */
@@ -38,36 +42,37 @@
 
     /* Set PWM duty cycle of Ref to 60% */
     motor->SetRefPwmDc(0, 60);
+    motor->SetRefPwmDc(1, 60);
 
     /* Set PWM Frequency of bridge A inputs to 10000 Hz */
-    motor->SetBridgeInputPwmFreq(0,10000);
+    motor->SetBridgeInputPwmFreq(0,70000);
 
     /* Set PWM Frequency of bridge B inputs to 10000 Hz */
-    motor->SetBridgeInputPwmFreq(1,10000);
+    motor->SetBridgeInputPwmFreq(1,70000);
 
     
     
                //INIZIALIZZAZIONI, s1 e s2 conterranno i valori di velocità da dare ai singoli motori
       
-                int s0=50;
-                int s1=50;
+                s0=50;
+                s1=50;
                 
                 //Definisco due oggetti della classe AnalogIn che chiamo ten1 e ten2, chiamo il costruttore per inizializzarli 
                 AnalogIn ten0(A1);  //indico che vorrò leggere la tensione analogica su questi due pin, 
                 AnalogIn ten1(A2);  //è la stessa di quella che ho sulle due ruote
                     
                 /**** SETTO I DUE MOTORI ALLA STESSA VELOCITA, 50%, E ALLA STESSA DIREZIONE ****/
-                
-                motor->SetSpeed(0,s0);                          //SETTO LA VELOCITà DEL MOTORE 0 AL 50%
-                motor->SetSpeed(1,s1);                          //RIDUCO LA VELOCITA DEL MOTORE 0
-                motor->Run(1, BDCMotor::FWD);                   //FACCIO ANDARE AVANTI IL MOTORE 1, per farlo andare indietro basta mettere BWD invece di FWD
-                motor->Run(0, BDCMotor::FWD);                   //MOTORE 0 IN AVANTI
+                 motor->SetSpeed(0,s0);                          //SETTO LA VELOCITà DEL MOTORE 0 AL 50%
+                 motor->SetSpeed(1,s1);                          //RIDUCO LA VELOCITA DEL MOTORE 0
+                 motor->Run(1, BDCMotor::FWD);                   //FACCIO ANDARE AVANTI IL MOTORE 1, per farlo andare indietro basta mettere BWD invece di FWD
+                 motor->Run(0, BDCMotor::FWD);                   //MOTORE 0 IN AVANTI
+               
                 
                 
                  while (1)
                  {   
-                
-                    if(ten1.read() - ten0.read() >0.1)   //la tensione sul motore 0 è 10 volte quella dell'altro motore
+                    
+                    if(ten1.read()-ten0.read()>0.1)   //la tensione sul motore 0 è 10 volte quella dell'altro motore
                     {
                         s1+=10;
                         motor->SetSpeed(1,s1);      //aumento la velocità del 5%                         
@@ -79,8 +84,8 @@
                     else if (ten0.read() - ten1.read() >0.1)   //la tensione sul motore 0 è 10 volte quella dell'altro motore
                     {
                         
-                        s0 +=10;
-                        motor->SetSpeed(0,s0);      //aumento la velocità del 5%                         
+                        s1-=10;
+                        motor->SetSpeed(1,s1);      //aumento la velocità del 5%                         
                        // motor->Run(0, BDCMotor::FWD);     
                        
                        printf(" Velocita S0 %6ld\n", s0);
@@ -90,7 +95,7 @@
                     
                     }
                     
-                    wait_ms(250);  // 250 ms
+                    wait_ms(150);  // 250 ms
                 }