2 Motores + Joystick
Dependencies: X_NUCLEO_IHM01A1 TextLCD
Fork of HelloWorld_IHM01A1_2Motors_mbedOS by
Revision 35:a05bef8dd995, committed 2018-04-24
- Comitter:
- leogrotti
- Date:
- Tue Apr 24 15:09:16 2018 +0000
- Parent:
- 34:098efd69c86d
- Child:
- 36:0cd4fdbb40af
- Commit message:
- 2 motores + joystick com get_speed
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 24 14:26:11 2018 +0000
+++ b/main.cpp Tue Apr 24 15:09:16 2018 +0000
@@ -63,7 +63,7 @@
In Full Step mode: 1 pps = 1 step/s).
In 1/N Step Mode: N pps = 1 step/s). */
#define SPEED_1 1300
-#define SPEED_2 1200
+#define SPEED_2 1300
@@ -107,12 +107,14 @@
float w;
float u;
+
+
unsigned int minspeed = 1300;
//int step = 0x08;
-int speed1;
-int speed2;
+unsigned int speed1;
+unsigned int speed2;
/* Motor Control Component. */
@@ -139,35 +141,12 @@
exit(EXIT_FAILURE);
}
- /* Printing to the console. */
- // 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);
-
- /* Moving N steps in the forward direction. */
- //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();
-
- /* Getting current 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);
-
- /* Waiting 2 seconds. */
- // wait_ms(DELAY_1);
-
-
- /*----- Moving. -----*/
+ /*motor1->set_acceleration(160);
+ motor2->set_acceleration(160);
+ motor1->set_max_speed(speed1);
+ motor2->set_max_speed(speed2);*/
while(true) {
@@ -178,11 +157,15 @@
// pc.printf ("X: %f \r\n",u);
// pc.printf ("Y: %f \r\n",w);
+
+
+
if (u>0.740) {
motor1->run(StepperMotor::FWD);
speed1 = motor1->get_speed();
+ printf("speed1 =%d \r\n\n", speed1);
printf("U =%f \r\n\n", u);
}
@@ -191,11 +174,15 @@
motor1->run(StepperMotor::BWD);
speed1 = motor1->get_speed();
+ printf("speed1 =%d \r\n\n", speed1);
+
printf("U =%f \r\n\n", u);
}
else
motor1->hard_stop();
+ speed1 = 0;
+ printf("speed1 =%d \r\n\n", speed1);
printf("U =%f \r\n\n", u);
@@ -205,6 +192,8 @@
motor2->run(StepperMotor::BWD);
speed2 = motor2->get_speed();
+
+ printf("speed2 =%d \r\n\n", speed2);
printf("W =%f \r\n\n", w);
}
@@ -212,13 +201,17 @@
motor2->run(StepperMotor::FWD);
- speed2 = motor1->get_speed();
- printf("W =%f \r\n\n", w);
+ speed2 = motor2->get_speed();
+
+ printf("speed2 =%d \r\n\n", speed2);
+ printf("W =%f \r\n\n", w);
}
else
motor2->hard_stop();
- printf("W =%f \r\n\n", w);
+ speed2 = 0;
+ printf("speed2 =%d \r\n\n", speed2);
+ printf("W =%f \r\n\n", w);
}
}
