Codice per pilotare il motore IHM01A1
Dependencies: mbed X_NUCLEO_IHM01A1
Diff: main.cpp
- Revision:
- 35:2b44ed4ec7a0
- Parent:
- 34:543d0d1147d9
- Child:
- 38:f3c848cd18cf
diff -r 543d0d1147d9 -r 2b44ed4ec7a0 main.cpp --- a/main.cpp Wed Mar 01 13:31:48 2017 +0000 +++ b/main.cpp Fri Mar 10 11:10:49 2017 +0100 @@ -46,7 +46,7 @@ #include "DevSPI.h" /* Component specific header files. */ -#include "l6474_class.h" +#include "L6474.h" /* Definitions ---------------------------------------------------------------*/ @@ -70,7 +70,7 @@ /* Variables -----------------------------------------------------------------*/ /* Initialization parameters. */ -L6474_Init_t init = { +L6474_init_t init = { 160, /* Acceleration rate in pps^2. Range: (0..+inf). */ 160, /* Deceleration rate in pps^2. Range: (0..+inf). */ 1600, /* Maximum speed in pps. Range: (30..10000]. */ @@ -107,18 +107,18 @@ * @param None * @retval None * @note If needed, implement it, and then attach and enable it: - * + motor->AttachFlagIRQ(&FlagIRQHandler); - * + motor->EnableFlagIRQ(); + * + motor->attach_flag_irq(&flag_irq_handler); + * + motor->enable_flag_irq(); * To disable it: - * + motor->DisbleFlagIRQ(); + * + motor->disble_flag_irq(); */ -void FlagIRQHandler(void) +void flag_irq_handler(void) { /* Set ISR flag. */ motor->isr_flag = TRUE; /* Get the value of the status register. */ - unsigned int status = motor->GetStatus(); + unsigned int status = motor->get_status(); /* Check NOTPERF_CMD flag: if set, the command received by SPI can't be performed. */ /* This often occures when a command is sent to the L6474 while it is not in HiZ state. */ @@ -142,13 +142,13 @@ /* Initializing Motor Control Component. */ motor = new L6474(D2, D8, D7, D9, D10, dev_spi); - if (motor->Init(&init) != COMPONENT_OK) { + if (motor->init(&init) != COMPONENT_OK) { exit(EXIT_FAILURE); } /* Attaching and enabling interrupt handlers. */ - motor->AttachFlagIRQ(&FlagIRQHandler); - motor->EnableFlagIRQ(); + motor->attach_flag_irq(&flag_irq_handler); + motor->enable_flag_irq(); /* Printing to the console. */ printf("Motor Control Application Example for 1 Motor\r\n\n"); @@ -160,13 +160,13 @@ printf("--> Moving forward %d steps.\r\n", STEPS_1); /* Moving N steps in the forward direction. */ - motor->Move(StepperMotor::FWD, STEPS_1); + motor->move(StepperMotor::FWD, STEPS_1); /* Waiting while the motor is active. */ - motor->WaitWhileActive(); + motor->wait_while_active(); /* Getting current position. */ - int position = motor->GetPosition(); + int position = motor->get_position(); /* Printing to the console. */ printf(" Position: %d.\r\n", position); @@ -181,13 +181,13 @@ printf("--> Setting Torque Regulation Current to 500[mA].\r\n"); /* Increasing the torque regulation current to 500[mA]. */ - motor->SetParameter(L6474_TVAL, 500); + motor->set_parameter(L6474_TVAL, 500); /* Printing to the console. */ printf("--> Doubling the microsteps.\r\n"); /* Doubling the microsteps. */ - if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_1_16)) { + if (!motor->set_step_mode((StepperMotor::step_mode_t) STEP_MODE_1_16)) { printf(" Step Mode not allowed.\r\n"); } @@ -198,10 +198,10 @@ printf("--> Setting Home.\r\n"); /* Setting the current position to be the home position. */ - motor->SetHome(); + motor->set_home(); /* Getting current position. */ - position = motor->GetPosition(); + position = motor->get_position(); /* Printing to the console. */ printf(" Position: %d.\r\n", position); @@ -216,13 +216,13 @@ printf("--> Moving backward %d steps.\r\n", STEPS_1); /* Moving N steps in the backward direction. */ - motor->Move(StepperMotor::BWD, STEPS_1); + motor->move(StepperMotor::BWD, STEPS_1); /* Waiting while the motor is active. */ - motor->WaitWhileActive(); + motor->wait_while_active(); /* Getting current position. */ - position = motor->GetPosition(); + position = motor->get_position(); /* Printing to the console. */ printf(" Position: %d.\r\n", position); @@ -237,13 +237,13 @@ printf("--> Going to position %d.\r\n", STEPS_1); /* Requesting to go to a specified position. */ - motor->GoTo(STEPS_1); + motor->go_to(STEPS_1); /* Waiting while the motor is active. */ - motor->WaitWhileActive(); + motor->wait_while_active(); /* Getting current position. */ - position = motor->GetPosition(); + position = motor->get_position(); /* Printing to the console. */ printf(" Position: %d.\r\n", position); @@ -258,13 +258,13 @@ printf("--> Going Home.\r\n"); /* Requesting to go to home. */ - motor->GoHome(); + motor->go_home(); /* Waiting while the motor is active. */ - motor->WaitWhileActive(); + motor->wait_while_active(); /* Getting current position. */ - position = motor->GetPosition(); + position = motor->get_position(); /* Printing to the console. */ printf(" Position: %d.\r\n", position); @@ -279,13 +279,13 @@ printf("--> Running backward for %d seconds.\r\n", DELAY_3 / 1000); /* Requesting to run backward. */ - motor->Run(StepperMotor::BWD); + motor->run(StepperMotor::BWD); /* Waiting. */ wait_ms(DELAY_3); /* Getting current speed. */ - int speed = motor->GetSpeed(); + int speed = motor->get_speed(); /* Printing to the console. */ printf(" Speed: %d.\r\n", speed); @@ -296,13 +296,13 @@ printf("--> Increasing the speed while running again for %d seconds.\r\n", DELAY_3 / 1000); /* Increasing the speed. */ - motor->SetMaxSpeed(SPEED_1); + motor->set_max_speed(SPEED_1); /* Waiting. */ wait_ms(DELAY_3); /* Getting current speed. */ - speed = motor->GetSpeed(); + speed = motor->get_speed(); /* Printing to the console. */ printf(" Speed: %d.\r\n", speed); @@ -314,13 +314,13 @@ printf("--> Decreasing the speed while running again for %d seconds.\r\n", DELAY_4 / 1000); /* Decreasing the speed. */ - motor->SetMaxSpeed(SPEED_2); + motor->set_max_speed(SPEED_2); /* Waiting. */ wait_ms(DELAY_4); /* Getting current speed. */ - speed = motor->GetSpeed(); + speed = motor->get_speed(); /* Printing to the console. */ printf(" Speed: %d.\r\n", speed); @@ -332,10 +332,10 @@ printf("--> Hard Stop.\r\n"); /* Requesting to immediatly stop. */ - motor->HardStop(); + motor->hard_stop(); /* Waiting while the motor is active. */ - motor->WaitWhileActive(); + motor->wait_while_active(); /* Waiting. */ wait_ms(DELAY_2); @@ -347,20 +347,20 @@ printf("--> Infinite Loop...\r\n"); /* Setting the current position to be the home position. */ - motor->SetHome(); + motor->set_home(); /* Infinite Loop. */ while (true) { /* Requesting to go to a specified position. */ - motor->GoTo(STEPS_1 >> 1); + motor->go_to(STEPS_1 >> 1); /* Waiting while the motor is active. */ - motor->WaitWhileActive(); + motor->wait_while_active(); /* Requesting to go to a specified position. */ - motor->GoTo(- (STEPS_1 >> 1)); + motor->go_to(- (STEPS_1 >> 1)); /* Waiting while the motor is active. */ - motor->WaitWhileActive(); + motor->wait_while_active(); } }