Scheda motori funzionante (demostep)

Dependencies:   X_NUCLEO_IHM12A1 mbed

Fork of SchedamotoriIHM12A1 by Duckiebot

Files at this revision

API Documentation at this revision

Comitter:
gandhi1
Date:
Fri Feb 24 16:13:24 2017 +0000
Parent:
5:21a4085d2057
Commit message:
Scheda motori funzionante (demostep)

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
diff -r 21a4085d2057 -r b5d006c1eb59 main.cpp
--- a/main.cpp	Wed Feb 15 11:09:44 2017 +0000
+++ b/main.cpp	Fri Feb 24 16:13:24 2017 +0000
@@ -1,24 +1,19 @@
 #include "mbed.h"
 #include "stspin240_250_class.h"
-
-/* Initialization parameters of the motor connected to the expansion board. */
+Serial pc(USBTX, USBRX);
  Stspin240_250_Init_t initDeviceParameters =
  {
-  20000, /* Frequency of PWM of Input Bridge A in Hz up to 100000Hz             */
-  20000, /* Frequency of PWM of Input Bridge B in Hz up to 100000Hz             */
-  20000, /* Frequency of PWM used for Ref pin in Hz up to 100000Hz              */
-  50,    /* Duty cycle of PWM used for Ref pin (from 0 to 100)                  */
-  TRUE   /* Dual Bridge configuration  (FALSE for mono, TRUE for dual brush dc) */
+  20000, 
+  20000, 
+  20000, 
+  50,    
+  TRUE   
  };
-
-/* Motor Control Component. */
 STSPIN240_250 *motor;
 
 int main()
 {
   uint8_t demoStep = 0;
-
-  /* Initializing Motor Control Component. */
   #if (defined TARGET_NUCLEO_F030R8)||(defined TARGET_NUCLEO_F334R8)
   motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A2);
   #elif (defined TARGET_NUCLEO_L152RE)
@@ -27,21 +22,10 @@
   motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A0);
   #endif
   if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE);
-
-  /* Set dual bridge enabled as two motors are used*/
   motor->SetDualFullBridgeConfig(1);
-
-
-  /* Set PWM Frequency of Ref to 15000 Hz */ 
-  motor->SetRefPwmFreq(0, 15000); 
-
-  /* Set PWM duty cycle of Ref to 60% */ 
-  motor->SetRefPwmDc(0, 60); 
-  
-  /* Set PWM Frequency of bridge A inputs to 10000 Hz */ 
+  motor->SetRefPwmFreq(0, 15000);
+  motor->SetRefPwmDc(0, 60);  
   motor->SetBridgeInputPwmFreq(0,10000); 
-  
-  /* Set PWM Frequency of bridge B inputs to 10000 Hz */ 
   motor->SetBridgeInputPwmFreq(1,10000); 
   
   while (1)
@@ -49,57 +33,38 @@
     switch (demoStep)
     {  
         case 0:
-          /* Set speed of motor 0 to 100 % */
-          motor->SetSpeed(0,50);
-          motor->SetSpeed(1,50); 
-          /* start motor 0 to run forward*/
-          /* if chip is in standby mode */
-          /* it is automatically awakened */
-          motor->Run(0, BDCMotor::FWD);
-          motor->Run(1, BDCMotor::FWD);
-          break;
-                  case 1:
-                  /* Set speed of motor 0 to 100 % */
-                motor->SetSpeed(0,50);
-                motor->SetSpeed(1,50); 
-                /* start motor 0 to run forward*/
-                /* if chip is in standby mode */
-                /* it is automatically awakened */
-                motor->Run(0, BDCMotor::BWD);
-                motor->Run(1, BDCMotor::BWD);
-                break;
-                   case 2:
-                  /* Set speed of motor 0 to 100 % */
-                motor->SetSpeed(0,32);
-                motor->SetSpeed(1,25); 
-                /* start motor 0 to run forward*/
-                /* if chip is in standby mode */
-                /* it is automatically awakened */
-                motor->Run(0, BDCMotor::BWD);
-                motor->Run(1, BDCMotor::BWD);
-                break;
-                    case 3:
-                  /* Set speed of motor 0 to 100 % */
-                motor->SetSpeed(0,25);
-                motor->SetSpeed(1,40); 
-                /* start motor 0 to run forward*/
-                /* if chip is in standby mode */
-                /* it is automatically awakened */
-                motor->Run(0, BDCMotor::BWD);
-                motor->Run(1, BDCMotor::BWD);
-                break;
-          
-          
-            
-                 
-    }
-  
-    /* Wait for 5 seconds */  
-    wait_ms(5000);
-    
-    /* Increment demostep*/  
+            /* Va avanti */
+            motor->SetSpeed(0,50);
+            motor->SetSpeed(1,50); 
+            motor->Run(0, BDCMotor::FWD);
+            motor->Run(1, BDCMotor::FWD);
+            break;
+        case 1:
+            /* Va a destra */
+            motor->SetSpeed(0,47);
+            motor->SetSpeed(1,23); 
+            motor->Run(0, BDCMotor::FWD);
+            motor->Run(1, BDCMotor::FWD);
+
+            break;
+         case 2:
+            /* Va indietro */
+            motor->SetSpeed(0,50);
+            motor->SetSpeed(1,50); 
+            motor->Run(0, BDCMotor::BWD);
+            motor->Run(1, BDCMotor::BWD);
+            break;
+        case 3:
+            /* Va a sinistra */
+            motor->SetSpeed(0,25);
+            motor->SetSpeed(1,30); 
+            motor->Run(0, BDCMotor::FWD);
+            motor->Run(1, BDCMotor::FWD);
+            break;  
+    } 
+    wait_ms(4500);
     demoStep++;
-    if (demoStep > 12)
+    if (demoStep > 3)
     {
       demoStep = 0;
     }
diff -r 21a4085d2057 -r b5d006c1eb59 mbed.bld
--- a/mbed.bld	Wed Feb 15 11:09:44 2017 +0000
+++ b/mbed.bld	Fri Feb 24 16:13:24 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f
\ No newline at end of file