Robo l minuscolo
Dependencies: X_NUCLEO_IHM04A1 mbed
Fork of HelloWorld_IHM04A1 by
Revision 6:d5d776281222, committed 2018-02-10
- Comitter:
- carlotara
- Date:
- Sat Feb 10 18:25:08 2018 +0000
- Parent:
- 5:4c1e581bbb8b
- Commit message:
- RoboCaMot
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Jun 15 12:51:03 2016 +0000
+++ b/main.cpp Sat Feb 10 18:25:08 2018 +0000
@@ -81,7 +81,7 @@
L6206 *motor;
/* User button on Nucleo board */
-InterruptIn mybutton_irq(USER_BUTTON);
+//InterruptIn mybutton_irq(USER_BUTTON);
@@ -149,7 +149,7 @@
* @retval None
*/
-void button_pressed(void)
+/*void button_pressed(void)
{
mybutton_irq.disable_irq();
gStep++;
@@ -161,7 +161,7 @@
mybutton_irq.enable_irq();
}
-
+*/
/**
* @brief Main program
@@ -170,6 +170,40 @@
*/
int main(void)
{
+
+ printf("ESTRONCIO\n");
+/*Con il codice
+
+motor->run(0, BDCMotor::FWD); // Forward
+
+fai andare avanti.
+
+
+
+Se vuoi cambiare il verso devi usare questo codice
+
+motor->run(0, BDCMotor::BWD); // Backword
+
+
+
+Lo 0 indica il motore 0, per il secondo motore puoi usare 1 collegandolo opportunamente.
+
+
+
+Quindi ad esempio se devi fare andare tutti e due avanti, usi questo codice
+
+motor->run(0, BDCMotor::FWD); // Forward
+
+motor->run(1, BDCMotor::FWD); // Forward
+
+
+
+Per farli andare indietro
+
+motor->run(0, BDCMotor::BWD); // Forward
+
+motor->run(1, BDCMotor::BWD); // Forward
+*/
/*----- Initialization. -----*/
/* Initializing Motor Control Component. */
@@ -178,14 +212,14 @@
/* When Init method is called with NULL pointer, the L6206 parameters are set */
/* with the predefined values from file l6206_target_config.h, otherwise the */
/* parameters are set using the initDeviceParameters structure values. */
- if (motor->Init(&init) != COMPONENT_OK)
- exit(EXIT_FAILURE);
+ // if (motor->Init(&init) != COMPONENT_OK)
+ // exit(EXIT_FAILURE);
/* Attach the function MyFlagInterruptHandler (defined below) to the flag interrupt */
- motor->AttachFlagInterrupt(MyFlagInterruptHandler);
+ // motor->AttachFlagInterrupt(MyFlagInterruptHandler);
/* Attach the function Error_Handler (defined below) to the error Handler*/
- motor->AttachErrorHandler(Error_Handler);
+ // motor->AttachErrorHandler(Error_Handler);
/* Printing to the console. */
printf("Motor Control Application Example for 4 Motor\r\n\n");
@@ -193,68 +227,88 @@
/* Select the configuration with no bridge paralleling, two unidirectionnal motors on bridge A
and two unidirectionnal motors on bridge B */
- motor->SetDualFullBridgeConfig(PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B);
+
+ // motor->SetDualFullBridgeConfig(PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B);
+ motor->SetDualFullBridgeConfig(PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B);
/* Set PWM Frequency of bridge A inputs to 1000 Hz */
- motor->SetBridgeInputPwmFreq(0,1000);
+ motor->SetBridgeInputPwmFreq(0,2000);
/* Set PWM Frequency of bridge B inputs to 2000 Hz */
motor->SetBridgeInputPwmFreq(1,2000);
- // Attach button_pressed function to Irq
- mybutton_irq.fall(&button_pressed);
+ // // Attach button_pressed function to Irq
+ // mybutton_irq.fall(&button_pressed);
/* Infinite loop */
while(1)
{
- if (gStep > 0)
- {
- printf("Run motor 0 at 20%% of the maximum speed\n");
- /* Set speed of motor 0 to 20% */
- motor->SetSpeed(0,20);
+ // if (gStep > 0)
+ // {
+ printf("ESTRONCIOLETTO\n");
+ // printf("Run motor 0 at 20%% of the maximum speed\n");
+ // /* Set speed of motor 0 to 20% */
+ // motor->SetSpeed(0,40);
/* start motor 0 */
- motor->Run(0, BDCMotor::FWD);
- }
+ // motor->Run(0, BDCMotor::FWD);
+ // }
- if (gStep > 1)
- {
- printf("Run motor 1 at 30%% of the maximum speed\n");
+ // if (gStep > 1)
+ // {
+ printf("Run motor 1 e 2 at 50% avanti\n");
/* Set speed of motor 1 to 30 % */
- motor->SetSpeed(1,30);
+ motor->SetSpeed(0,100);
+ motor->SetSpeed(1,100);
/* start motor 1 */
motor->Run(1, BDCMotor::FWD);
- }
-
- if (gStep > 2)
- {
- printf("Run motor 2 at 40%% of the maximum speed\n");
- /* Set speed of motor 2 to 40 % */
- motor->SetSpeed(2,40);
- /* start motor 2 */
- motor->Run(2, BDCMotor::FWD);
- }
+ motor->Run(0, BDCMotor::FWD); // Avanti
+ printf("Motori 1 e 2 FERMI\n");
+ wait_ms(5000);
+ motor->HardHiZ(0);
+ motor->HardHiZ(1);
+ // printf("Motori 1 e 2 FERMI\n");
+ wait_ms(1000);
+ printf("Run motor 1 e 2 at 50% indietro\n");
+ motor->Run(1, BDCMotor::BWD);
+ motor->Run(0, BDCMotor::BWD); // Indietro
+ wait_ms(5000);
+ motor->HardHiZ(0);
+ motor->HardHiZ(1);
+ printf("Motori 1 e 2 FERMI\n");
+ wait_ms(1000);
+ // }
- if (gStep > 3)
- {
- printf("Run motor 3 at 50%% of the maximum speed\n");
- /* Set speed of motor 3 to 50 % */
- motor->SetSpeed(3,50);
- /* start motor 3 */
- motor->Run(3, BDCMotor::FWD);
- }
+ // if (gStep > 2)
+ // {
+ // printf("Run motor 2 at 40%% of the maximum speed\n");
+ // /* Set speed of motor 2 to 40 % */
+ // motor->SetSpeed(2,100);
+ // /* start motor 2 */
+ // motor->Run(2, BDCMotor::FWD);
+ // }
- if (gStep > 0)
- {
- wait_ms(1000);
+ // if (gStep > 3)
+ // {
+ // printf("Run motor 3 at 50%% of the maximum speed\n");
+ // /* Set speed of motor 3 to 50 % */
+ // motor->SetSpeed(3,100);
+ // /* start motor 3 */
+ // motor->Run(3, BDCMotor::FWD);
+ // }
+
+ // if (gStep > 0)
+ // {
+ // wait_ms(1000);
- motor->HardHiZ(0);
- motor->HardHiZ(1);
- motor->HardHiZ(2);
- motor->HardHiZ(3);
+ // motor->HardHiZ(0);
+ // motor->HardHiZ(1);
+ // motor->HardHiZ(2);
+ // motor->HardHiZ(3);
- wait_ms(1000);
- }
+ // wait_ms(1000);
+ // }
+
}
}
