funzionamento un motore

Dependencies:   X_NUCLEO_IHM01A1 mbed Motori_ultrasuoni_prova

Fork of HelloWorld_IHM01A1_2Motors by ST

Revision:
24:8cb3c4ad055f
Parent:
17:aae1446c67f4
Child:
28:3f17a4152bcf
--- a/main.cpp	Fri Apr 08 12:57:07 2016 +0000
+++ b/main.cpp	Thu Sep 08 12:52:04 2016 +0000
@@ -51,9 +51,20 @@
 
 /* Definitions ---------------------------------------------------------------*/
 
-/* Number of steps to move. */
+/* Number of steps. */
 #define STEPS 3200
 
+/* Delay in milliseconds. */
+#define DELAY_1 2000
+#define DELAY_2 6000
+#define DELAY_3 8000
+
+/* Speed in pps (Pulses Per Second).
+   In Full Step mode: 1 pps = 1 step/s).
+   In 1/N Step Mode:  N pps = 1 step/s). */
+#define SPEED_1 2400
+#define SPEED_2 1200
+
 
 /* Variables -----------------------------------------------------------------*/
 
@@ -104,7 +115,7 @@
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
     
     /*----- Moving. -----*/
@@ -134,7 +145,7 @@
     motor2->SetHome();
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
 
     /*----- Going to a specified position. -----*/
@@ -158,7 +169,7 @@
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
     
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
     
     /*----- Going Home. -----*/
@@ -182,7 +193,7 @@
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
 
     /*----- Running. -----*/
@@ -195,7 +206,7 @@
     motor2->Run(StepperMotor::FWD);
 
     /* Waiting until delay has expired. */
-    wait_ms(6000);
+    wait_ms(DELAY_2);
 
     /* Getting current speed. */
     int speed1 = motor1->GetSpeed();
@@ -209,12 +220,12 @@
     /* Printing to the console. */
     printf("--> Increasing the speed while running.\r\n");
 
-    /* Increasing speed to 2400 step/s. */
-    motor1->SetMaxSpeed(2400);
-    motor2->SetMaxSpeed(2400);
+    /* Increasing the speed. */
+    motor1->SetMaxSpeed(SPEED_1);
+    motor2->SetMaxSpeed(SPEED_1);
 
     /* Waiting until delay has expired. */
-    wait_ms(6000);
+    wait_ms(DELAY_2);
 
     /* Getting current speed. */
     speed1 = motor1->GetSpeed();
@@ -229,12 +240,12 @@
     /* Printing to the console. */
     printf("--> Decreasing the speed while running.\r\n");
 
-    /* Decreasing speed to 1200 step/s. */
-    motor1->SetMaxSpeed(1200);
-    motor2->SetMaxSpeed(1200);
+    /* Decreasing the speed. */
+    motor1->SetMaxSpeed(SPEED_2);
+    motor2->SetMaxSpeed(SPEED_2);
 
     /* Waiting until delay has expired. */
-    wait_ms(8000);
+    wait_ms(DELAY_3);
 
     /* Getting current speed. */
     speed1 = motor1->GetSpeed();
@@ -258,7 +269,7 @@
     motor2->WaitWhileActive();
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
 
     /*----- Infinite Loop. -----*/