2 Motores + Joystick

Dependencies:   X_NUCLEO_IHM01A1 TextLCD

Fork of HelloWorld_IHM01A1_2Motors_mbedOS by ST

Files at this revision

API Documentation at this revision

Comitter:
leogrotti
Date:
Tue Apr 24 14:26:11 2018 +0000
Parent:
33:b276c9c00088
Child:
35:a05bef8dd995
Commit message:
2 motores+ joystick configurado

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Apr 24 13:51:09 2018 +0000
+++ b/main.cpp	Tue Apr 24 14:26:11 2018 +0000
@@ -62,7 +62,7 @@
 /* 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_1 1300
 #define SPEED_2 1200
 
 
@@ -107,9 +107,9 @@
 float w;
 float u;
 
-unsigned int minspeed = 1600;
+unsigned int minspeed = 1300;
 
-int step = 0x08;
+//int step = 0x08;
 
 int speed1;
 int speed2;
@@ -140,31 +140,31 @@
     }
 
     /* Printing to the console. */
-    printf("Motor Control Application Example for 2 Motors\r\n\n");
+   // printf("Motor Control Application Example for 2 Motors\r\n\n");
 
 
     /*----- Moving. -----*/
 
     /* Printing to the console. */
-    printf("--> Moving forward: M1 %d steps, M2 %d steps.\r\n", STEPS >> 1, STEPS);
+    //printf("--> Moving forward: M1 %d steps, M2 %d steps.\r\n", STEPS >> 1, STEPS);
 
     /* Moving N steps in the forward direction. */
-    motor1->move(StepperMotor::FWD, STEPS >> 1);
-    motor2->move(StepperMotor::FWD, STEPS);
+    //motor1->move(StepperMotor::FWD, STEPS >> 1);
+    //motor2->move(StepperMotor::FWD, STEPS);
 
     /* Waiting while the motor is active. */
-    motor1->wait_while_active();
-    motor2->wait_while_active();
+    //motor1->wait_while_active();
+   // motor2->wait_while_active();
 
     /* Getting current position. */
-    int position1 = motor1->get_position();
-    int position2 = motor2->get_position();
+  //  int position1 = motor1->get_position();
+  //  int position2 = motor2->get_position();
     
     /* Printing to the console. */
-    printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
+  //  printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
 
     /* Waiting 2 seconds. */
-    wait_ms(DELAY_1);
+   // wait_ms(DELAY_1);
 
     
     /*----- Moving. -----*/
@@ -178,45 +178,48 @@
   //      pc.printf ("X:   %f \r\n",u);
   //      pc.printf ("Y:    %f  \r\n",w);
   
-        if (u>0.520) {
-           motor1->set_min_speed(minspeed);
-  //         motor1->set_step_mode(step_mode_t_1_2);
+        if (u>0.740) {
+
            motor1->run(StepperMotor::FWD);
            speed1 = motor1->get_speed();
-           printf("velocidade: motor 1: %d \r\n",speed1);
-           printf("movendo motor 1 pra frente\r\n");
+           
+            printf("U =%f \r\n\n", u);
+
            }
-            else{ if(u<0.455) {
-                motor1->set_min_speed(minspeed);
+            else{ if(u<0.65) {
+                
                 motor1->run(StepperMotor::BWD);
                 speed1 = motor1->get_speed();
-                printf("velocidade: motor 1: %d \r\n",speed1);
-                printf("movendo motor 1 pra tras\r\n");
+                
+                printf("U =%f \r\n\n", u);
+
                 }
                else 
                motor1->hard_stop();
-               printf("parado1\r\n");
-               printf("velocidade: motor 1: %d \r\n",speed1);
+               
+                printf("U =%f \r\n\n", u);
+
                }
         
-       if (w>0.535) {
-           motor2->set_min_speed(minspeed);
-           motor2->run(StepperMotor::FWD);
+       if (w>0.76) {
+           
+            motor2->run(StepperMotor::BWD);
            speed2 = motor2->get_speed();
-           printf("velocidade: motor 1: %d \r\n",speed2);
-           printf("movendo motor 2 pra frente\r\n");
+            printf("W =%f \r\n\n", w);
+
            }
-            else{ if(w<0.491) {
-                motor1->set_min_speed(minspeed);
-                motor2->run(StepperMotor::BWD);
+            else{ if(w<0.67) {
+    
+           
+                motor2->run(StepperMotor::FWD);
                 speed2 = motor1->get_speed();
-                printf("velocidade: motor 1: %d \r\n",speed2);
-                printf("movendo motor 2 pra tras\r\n");
+                 printf("W =%f \r\n\n", w);
+ 
                }
                 else
                 motor2->hard_stop();
-                 printf("parado2\r\n");
-                 printf("velocidade: motor 2: %d \r\n",speed2);
+                 printf("W =%f \r\n\n", w);
+
                }
     }
 }
\ No newline at end of file