Test
Dependencies: X_NUCLEO_IHM02A1 mbed
Fork of HelloWorld_IHM02A1 by
Revision 20:64b4bb57c3c6, committed 2018-05-10
- Comitter:
- Robby
- Date:
- Thu May 10 02:12:07 2018 +0000
- Parent:
- 19:eeb4796d6a03
- Commit message:
- Test
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Apr 08 13:02:44 2016 +0000 +++ b/main.cpp Thu May 10 02:12:07 2018 +0000 @@ -48,6 +48,8 @@ /* Expansion Board specific header files. */ #include "x_nucleo_ihm02a1_class.h" +/* String libraries for splitting commands*/ +#include <string.h> /* Definitions ---------------------------------------------------------------*/ @@ -55,7 +57,7 @@ #define MPR_1 4 /* Number of steps. */ -#define STEPS_1 (400 * 128) /* 1 revolution given a 400 steps motor configured at 1/128 microstep mode. */ +#define STEPS_1 (200 * 128) /* 1 revolution given a 400 steps motor configured at 1/128 microstep mode. */ #define STEPS_2 (STEPS_1 * 2) /* Delay in milliseconds. */ @@ -66,6 +68,9 @@ /* Variables -----------------------------------------------------------------*/ +/* Serial port to USB*/ +Serial pc(USBTX,USBRX);//tx, rx + /* Motor Control Expansion Board. */ X_NUCLEO_IHM02A1 *x_nucleo_ihm02a1; @@ -74,16 +79,16 @@ { /* First Motor. */ { - 9.0, /* Motor supply voltage in V. */ - 400, /* Min number of steps per revolution for the motor. */ - 1.7, /* Max motor phase voltage in A. */ - 3.06, /* Max motor phase voltage in V. */ - 300.0, /* Motor initial speed [step/s]. */ - 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ - 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ - 992.0, /* Motor maximum speed [step/s]. */ + 12.0, /* Motor supply voltage in V. */ + 200, /* Min number of steps per revolution for the motor. */ + 0.5, /* Max motor phase voltage in A. */ + 5.06, /* Max motor phase voltage in V. */ + 200.0, /* Motor initial speed [step/s]. */ + 300.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ + 300.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ + 400.0, /* Motor maximum speed [step/s]. */ 0.0, /* Motor minimum speed [step/s]. */ - 602.7, /* Motor full-step speed threshold [step/s]. */ + 800, /* Motor full-step speed threshold [step/s]. */ 3.06, /* Holding kval [V]. */ 3.06, /* Constant speed kval [V]. */ 3.06, /* Acceleration starting kval [V]. */ @@ -102,16 +107,16 @@ /* Second Motor. */ { - 9.0, /* Motor supply voltage in V. */ - 400, /* Min number of steps per revolution for the motor. */ - 1.7, /* Max motor phase voltage in A. */ - 3.06, /* Max motor phase voltage in V. */ - 300.0, /* Motor initial speed [step/s]. */ - 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ - 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ - 992.0, /* Motor maximum speed [step/s]. */ + 12.0, /* Motor supply voltage in V. */ + 200, /* Min number of steps per revolution for the motor. */ + 0.5, /* Max motor phase voltage in A. */ + 5.06, /* Max motor phase voltage in V. */ + 200.0, /* Motor initial speed [step/s]. */ + 300.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ + 300.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ + 400.0, /* Motor maximum speed [step/s]. */ 0.0, /* Motor minimum speed [step/s]. */ - 602.7, /* Motor full-step speed threshold [step/s]. */ + 800, /* Motor full-step speed threshold [step/s]. */ 3.06, /* Holding kval [V]. */ 3.06, /* Constant speed kval [V]. */ 3.06, /* Acceleration starting kval [V]. */ @@ -128,297 +133,501 @@ 0x2E88 /* Ic configuration. */ } }; + +DigitalIn enable(PA_8); +/* Building a list of motor control components. */ +//L6470 **motors = x_nucleo_ihm02a1->GetComponents(); +L6470 **motors; +void highZ(){ + /* Preparing each motor to set High Impedance State. */ + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + motors[m]->PrepareHardHiZ(); + + /* Performing the action on each motor at the same time. */ + x_nucleo_ihm02a1->PerformPreparedActions(); +} + +void hardStop(int motor){ + // /*----- Hard Stop. -----*/ +// + /* Printing to the console. */ +// pc.printf("--> Hard Stop.\r\n"); + + /* Preparing each motor to perform a hard stop. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + motors[motor]->PrepareHardStop(); + + /* Performing the action on each motor at the same time. */ + x_nucleo_ihm02a1->PerformPreparedActions(); + + highZ(); + /* Waiting. */ +// wait_ms(DELAY_2); +} + +void stopAllMotors(){ + /* Preparing each motor to perform a hard stop. */ + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + motors[m]->PrepareHardStop(); + + /* Performing the action on each motor at the same time. */ + x_nucleo_ihm02a1->PerformPreparedActions(); + + highZ(); +} + +void setHome(int motor){ + motors[motor]->SetHome(); +} + +int getPosition(int motor){ + int position = motors[motor]->GetPosition(); + return position; +} + +void moveSteps(int motor, int steps){ + + if(steps < 0) + motors[motor]->Move(StepperMotor::BWD, steps*-1); + else + motors[motor]->Move(StepperMotor::FWD, steps); + motors[motor]->WaitWhileActive(); + hardStop(motor); +} + +void runAtSpeed(int motor, int speed){ + if(speed < 0) + motors[motor]->PrepareRun(StepperMotor::BWD, speed*-1); + else if(speed > 0) + motors[motor]->PrepareRun(StepperMotor::FWD, speed); + else{ + hardStop(motor); + return; + } + /* Performing the action on each motor at the same time. */ + x_nucleo_ihm02a1->PerformPreparedActions(); +} + +void moveInSync(int steps){ + if(steps < 0){ + motors[0]->PrepareMove(StepperMotor::BWD, steps*-1); + motors[1]->PrepareMove(StepperMotor::BWD, steps*-1); + } + else if(steps > 0){ + motors[0]->PrepareMove(StepperMotor::FWD, steps); + motors[1]->PrepareMove(StepperMotor::FWD, steps); + } + x_nucleo_ihm02a1->PerformPreparedActions(); + motors[0]->WaitWhileActive(); + motors[1]->WaitWhileActive(); +} + +void goXRHome(int speed){ + //while not pushing button move motor to the left? + motors[0]->PrepareRun(StepperMotor::BWD, speed); + motors[1]->PrepareRun(StepperMotor::BWD, speed); + + x_nucleo_ihm02a1->PerformPreparedActions(); + +// while( + wait_ms(5000); + + stopAllMotors(); +} + +void goHome(int motor, int speed){ + //while not pushing button move motor to the left? + motors[motor]->PrepareRun(StepperMotor::BWD, speed); + + x_nucleo_ihm02a1->PerformPreparedActions(); + +// while( + wait_ms(5000); + + stopAllMotors(); +} + +void readSerial(){ + char rx_line[10]; +// while(pc.readable()){ + pc.scanf("%s", rx_line); + //pc.printf("Spoken %s \r\n", rx_line); + + char cmd[10], cmdv[10], cmdv2[10]; + int values = sscanf(rx_line, "%[^','],%[^','],%s",cmd, cmdv, cmdv2); + //pc.printf("%d\r\n",values); + int cmd_value = atoi(cmdv); + int cmd_value2 = atoi(cmdv2); + //pc.printf("%s\r\n%d\r\n%d\r\n", cmd, cmd_value, cmd_value2); + + char c = cmd[0]; + //pc.printf("%c", c); + int pos; + int pos2; + switch(c){ + case 'a': + + return; + case 'b': + //set home + setHome(cmd_value); + pos = getPosition(cmd_value); + pc.printf("%c,%d,%d\r\n",c,cmd_value,pos); + return; + case 'c': + //get position + pos = getPosition(cmd_value); + pc.printf("%c,%d,%d\r\n",c,cmd_value,pos); + return; + case 'd': + + break; + case 'e': + //move steps + moveSteps(cmd_value, cmd_value2); + pos = getPosition(cmd_value); + pc.printf("%c,%d,%d\r\n",c,cmd_value,pos); + return; + case 'f': + //run at a given speed or change to run until hit bump + runAtSpeed(cmd_value, cmd_value2); + break; + case 'g': + //Halt + stopAllMotors(); + break; + case 'h': + //move X to home (and R cause connected) + goXRHome(cmd_value2); + pos = getPosition(0); + pos2 = getPosition(1); + pc.printf("%c,%d,%d\r\n",c,pos,pos2); + return; + case 'i': + //move X numebr of steps and R cause connected + moveInSync(cmd_value); + pos = getPosition(0); + pos2 = getPosition(1); + pc.printf("%c,%d,%d\r\n",c,pos,pos2); + return; + case 'j': + //go home + goHome(cmd_value, cmd_value2); + pos = getPosition(cmd_value); + pc.printf("%c,%d,%d\r\n",c,cmd_value,pos); + return; + default: + //N/A command + pc.printf("Do not understand commands: %s with value %d\r\n", cmd, cmd_value); + return; + } + pc.printf("complete\r\n"); +} /* Main ----------------------------------------------------------------------*/ int main() { - /*----- Initialization. -----*/ - /* Initializing SPI bus. */ - DevSPI dev_spi(D11, D12, D3); - + DevSPI dev_spi(D11, D12, D13); + /* Initializing Motor Control Expansion Board. */ x_nucleo_ihm02a1 = new X_NUCLEO_IHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi); - - /* Building a list of motor control components. */ - L6470 **motors = x_nucleo_ihm02a1->GetComponents(); - - /* Printing to the console. */ - printf("Motor Control Application Example for 2 Motors\r\n\n"); - - - /*----- Setting home and marke positions, getting positions, and going to positions. -----*/ - - /* Printing to the console. */ - printf("--> Setting home position.\r\n"); - - /* Setting the home position. */ - motors[0]->SetHome(); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Getting the current position. */ - int position = motors[0]->GetPosition(); - - /* Printing to the console. */ - printf("--> Getting the current position: %d\r\n", position); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Printing to the console. */ - printf("--> Moving forward %d steps.\r\n", STEPS_1); - - /* Moving. */ - motors[0]->Move(StepperMotor::FWD, STEPS_1); - - /* Waiting while active. */ - motors[0]->WaitWhileActive(); - - /* Getting the current position. */ - position = motors[0]->GetPosition(); - /* Printing to the console. */ - printf("--> Getting the current position: %d\r\n", position); - - /* Printing to the console. */ - printf("--> Marking the current position.\r\n"); - - /* Marking the current position. */ - motors[0]->SetMark(); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Printing to the console. */ - printf("--> Moving backward %d steps.\r\n", STEPS_2); - - /* Moving. */ - motors[0]->Move(StepperMotor::BWD, STEPS_2); - - /* Waiting while active. */ - motors[0]->WaitWhileActive(); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Getting the current position. */ - position = motors[0]->GetPosition(); - - /* Printing to the console. */ - printf("--> Getting the current position: %d\r\n", position); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Printing to the console. */ - printf("--> Going to marked position.\r\n"); - - /* Going to marked position. */ - motors[0]->GoMark(); - - /* Waiting while active. */ - motors[0]->WaitWhileActive(); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Getting the current position. */ - position = motors[0]->GetPosition(); - - /* Printing to the console. */ - printf("--> Getting the current position: %d\r\n", position); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Printing to the console. */ - printf("--> Going to home position.\r\n"); - - /* Going to home position. */ - motors[0]->GoHome(); - - /* Waiting while active. */ - motors[0]->WaitWhileActive(); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Getting the current position. */ - position = motors[0]->GetPosition(); - - /* Printing to the console. */ - printf("--> Getting the current position: %d\r\n", position); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Printing to the console. */ - printf("--> Halving the microsteps.\r\n"); - - /* Halving the microsteps. */ - init[0].step_sel = (init[0].step_sel > 0 ? init[0].step_sel - 1 : init[0].step_sel); - if (!motors[0]->SetStepMode((StepperMotor::step_mode_t) init[0].step_sel)) - printf(" Step Mode not allowed.\r\n"); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Printing to the console. */ - printf("--> Setting home position.\r\n"); - - /* Setting the home position. */ - motors[0]->SetHome(); - - /* Waiting. */ - wait_ms(DELAY_1); - - /* Getting the current position. */ - position = motors[0]->GetPosition(); - - /* Printing to the console. */ - printf("--> Getting the current position: %d\r\n", position); + motors = x_nucleo_ihm02a1->GetComponents(); - /* Waiting. */ - wait_ms(DELAY_1); - - /* Printing to the console. */ - printf("--> Moving forward %d steps.\r\n", STEPS_1); - - /* Moving. */ - motors[0]->Move(StepperMotor::FWD, STEPS_1); - - /* Waiting while active. */ - motors[0]->WaitWhileActive(); - - /* Getting the current position. */ - position = motors[0]->GetPosition(); + pc.attach(readSerial); + pc.printf("ready\r\n"); + + while(1){ + } - /* Printing to the console. */ - printf("--> Getting the current position: %d\r\n", position); - - /* Printing to the console. */ - printf("--> Marking the current position.\r\n"); - - /* Marking the current position. */ - motors[0]->SetMark(); - - /* Waiting. */ - wait_ms(DELAY_2); - - - /*----- Running together for a certain amount of time. -----*/ - - /* Printing to the console. */ - printf("--> Running together for %d seconds.\r\n", DELAY_3 / 1000); - - /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - motors[m]->PrepareRun(StepperMotor::BWD, 400); - - /* Performing the action on each motor at the same time. */ - x_nucleo_ihm02a1->PerformPreparedActions(); - - /* Waiting. */ - wait_ms(DELAY_3); - - - /*----- Increasing the speed while running. -----*/ - - /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - motors[m]->PrepareGetSpeed(); - - /* Performing the action on each motor at the same time. */ - uint32_t* results = x_nucleo_ihm02a1->PerformPreparedActions(); - - /* Printing to the console. */ - printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]); - - /* Printing to the console. */ - printf("--> Doublig the speed while running again for %d seconds.\r\n", DELAY_3 / 1000); - - /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - motors[m]->PrepareRun(StepperMotor::BWD, results[m] << 1); - - /* Performing the action on each motor at the same time. */ - results = x_nucleo_ihm02a1->PerformPreparedActions(); - - /* Waiting. */ - wait_ms(DELAY_3); - - /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - motors[m]->PrepareGetSpeed(); - - /* Performing the action on each motor at the same time. */ - results = x_nucleo_ihm02a1->PerformPreparedActions(); - - /* Printing to the console. */ - printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]); - - /* Waiting. */ - wait_ms(DELAY_1); - - - /*----- Hard Stop. -----*/ - - /* Printing to the console. */ - printf("--> Hard Stop.\r\n"); - - /* Preparing each motor to perform a hard stop. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - motors[m]->PrepareHardStop(); - - /* Performing the action on each motor at the same time. */ - x_nucleo_ihm02a1->PerformPreparedActions(); - - /* Waiting. */ - wait_ms(DELAY_2); - - - /*----- Doing a full revolution on each motor, one after the other. -----*/ - - /* Printing to the console. */ - printf("--> Doing a full revolution on each motor, one after the other.\r\n"); - - /* Doing a full revolution on each motor, one after the other. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - for (int i = 0; i < MPR_1; i++) - { - /* Computing the number of steps. */ - int steps = (int) (((int) init[m].fullstepsperrevolution * pow(2.0f, init[m].step_sel)) / MPR_1); - - /* Moving. */ - motors[m]->Move(StepperMotor::FWD, steps); - - /* Waiting while active. */ - motors[m]->WaitWhileActive(); - - /* Waiting. */ - wait_ms(DELAY_1); - } - - /* Waiting. */ - wait_ms(DELAY_2); - - - /*----- High Impedance State. -----*/ - - /* Printing to the console. */ - printf("--> High Impedance State.\r\n"); - - /* Preparing each motor to set High Impedance State. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - motors[m]->PrepareHardHiZ(); - - /* Performing the action on each motor at the same time. */ - x_nucleo_ihm02a1->PerformPreparedActions(); - - /* Waiting. */ - wait_ms(DELAY_2); + ///*----- Initialization. -----*/ +// +// /* Initializing SPI bus. */ +// DevSPI dev_spi(D11, D12, D13); +// +// /* Initializing Motor Control Expansion Board. */ +// x_nucleo_ihm02a1 = new X_NUCLEO_IHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi); +// +// /* Building a list of motor control components. */ +// L6470 **motors = x_nucleo_ihm02a1->GetComponents(); +// +// /* Printing to the console. */ +// pc.printf("Motor Control Application Example for 2 Motors\r\n\n"); +// +// +// /*----- Setting home and marke positions, getting positions, and going to positions. -----*/ +// +// /* Printing to the console. */ +// pc.printf("--> Setting home position.\r\n"); +// +// /* Setting the home position. */ +// motors[0]->SetHome(); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Getting the current position. */ +// int position = motors[0]->GetPosition(); +// +// /* Printing to the console. */ +// pc.printf("--> Getting the current position: %d\r\n", position); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Printing to the console. */ +// pc.printf("--> Moving forward %d steps.\r\n", STEPS_1); +// +// /* Moving. */ +// motors[0]->Move(StepperMotor::FWD, STEPS_1); +// +// /* Waiting while active. */ +// motors[0]->WaitWhileActive(); +// +// /* Getting the current position. */ +// position = motors[0]->GetPosition(); +// +// /* Printing to the console. */ +// pc.printf("--> Getting the current position: %d\r\n", position); +// +// /* Printing to the console. */ +// pc.printf("--> Marking the current position.\r\n"); +// +// /* Marking the current position. */ +// motors[0]->SetMark(); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Printing to the console. */ +// pc.printf("--> Moving backward %d steps.\r\n", STEPS_2); +// +// /* Moving. */ + //motors[0]->Move(StepperMotor::BWD, STEPS_2); +// +// /* Waiting while active. */ +// motors[0]->WaitWhileActive(); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Getting the current position. */ +// position = motors[0]->GetPosition(); +// +// /* Printing to the console. */ +// pc.printf("--> Getting the current position: %d\r\n", position); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Printing to the console. */ +// pc.printf("--> Going to marked position.\r\n"); +// +// /* Going to marked position. */ +// motors[0]->GoMark(); +// +// /* Waiting while active. */ +// motors[0]->WaitWhileActive(); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Getting the current position. */ +// position = motors[0]->GetPosition(); +// +// /* Printing to the console. */ +// pc.printf("--> Getting the current position: %d\r\n", position); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Printing to the console. */ +// pc.printf("--> Going to home position.\r\n"); +// +// /* Going to home position. */ +// motors[0]->GoHome(); +// +// /* Waiting while active. */ +// motors[0]->WaitWhileActive(); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Getting the current position. */ +// position = motors[0]->GetPosition(); +// +// /* Printing to the console. */ +// pc.printf("--> Getting the current position: %d\r\n", position); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Printing to the console. */ +// pc.printf("--> Halving the microsteps.\r\n"); +// +// /* Halving the microsteps. */ +// init[0].step_sel = (init[0].step_sel > 0 ? init[0].step_sel - 1 : init[0].step_sel); +// if (!motors[0]->SetStepMode((StepperMotor::step_mode_t) init[0].step_sel)) +// pc.printf(" Step Mode not allowed.\r\n"); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Printing to the console. */ +// pc.printf("--> Setting home position.\r\n"); +// +// /* Setting the home position. */ +// motors[0]->SetHome(); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Getting the current position. */ +// position = motors[0]->GetPosition(); +// +// /* Printing to the console. */ +// pc.printf("--> Getting the current position: %d\r\n", position); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// /* Printing to the console. */ +// pc.printf("--> Moving forward %d steps.\r\n", STEPS_1); +// +// /* Moving. */ +// motors[0]->Move(StepperMotor::FWD, STEPS_1); +// +// /* Waiting while active. */ +// motors[0]->WaitWhileActive(); +// +// /* Getting the current position. */ +// position = motors[0]->GetPosition(); +// +// /* Printing to the console. */ +// pc.printf("--> Getting the current position: %d\r\n", position); +// +// /* Printing to the console. */ +// pc.printf("--> Marking the current position.\r\n"); +// +// /* Marking the current position. */ +// motors[0]->SetMark(); +// +// /* Waiting. */ +// wait_ms(DELAY_2); +// +// +// /*----- Running together for a certain amount of time. -----*/ +// +// /* Printing to the console. */ +// pc.printf("--> Running together for %d seconds.\r\n", DELAY_3 / 1000); +// +// /* Preparing each motor to perform a run at a specified speed. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) +// motors[m]->PrepareRun(StepperMotor::BWD, 400); +// +// /* Performing the action on each motor at the same time. */ +// x_nucleo_ihm02a1->PerformPreparedActions(); +// +// /* Waiting. */ +// wait_ms(DELAY_3); +// +// +// /*----- Increasing the speed while running. -----*/ +// +// /* Preparing each motor to perform a run at a specified speed. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) +// motors[m]->PrepareGetSpeed(); +// +// /* Performing the action on each motor at the same time. */ +// uint32_t* results = x_nucleo_ihm02a1->PerformPreparedActions(); +// +// /* Printing to the console. */ +// pc.printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]); +// +// /* Printing to the console. */ +// pc.printf("--> Doublig the speed while running again for %d seconds.\r\n", DELAY_3 / 1000); +// +// /* Preparing each motor to perform a run at a specified speed. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) +// motors[m]->PrepareRun(StepperMotor::BWD, results[m] << 1); +// +// /* Performing the action on each motor at the same time. */ +// results = x_nucleo_ihm02a1->PerformPreparedActions(); +// +// /* Waiting. */ +// wait_ms(DELAY_3); +// +// /* Preparing each motor to perform a run at a specified speed. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) +// motors[m]->PrepareGetSpeed(); +// +// /* Performing the action on each motor at the same time. */ +// results = x_nucleo_ihm02a1->PerformPreparedActions(); +// +// /* Printing to the console. */ +// pc.printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// +// +// /*----- Hard Stop. -----*/ +// +// /* Printing to the console. */ +// pc.printf("--> Hard Stop.\r\n"); +// +// /* Preparing each motor to perform a hard stop. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) +// motors[m]->PrepareHardStop(); +// +// /* Performing the action on each motor at the same time. */ +// x_nucleo_ihm02a1->PerformPreparedActions(); +// +// /* Waiting. */ +// wait_ms(DELAY_2); +// +// +// /*----- Doing a full revolution on each motor, one after the other. -----*/ +// +// /* Printing to the console. */ +// pc.printf("--> Doing a full revolution on each motor, one after the other.\r\n"); +// +// /* Doing a full revolution on each motor, one after the other. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) +// for (int i = 0; i < MPR_1; i++) +// { +// /* Computing the number of steps. */ +// int steps = (int) (((int) init[m].fullstepsperrevolution * pow(2.0f, init[m].step_sel)) / MPR_1); +// +// /* Moving. */ +// motors[m]->Move(StepperMotor::FWD, steps); +// +// /* Waiting while active. */ +// motors[m]->WaitWhileActive(); +// +// /* Waiting. */ +// wait_ms(DELAY_1); +// } +// +// /* Waiting. */ +// wait_ms(DELAY_2); +// +// +// /*----- High Impedance State. -----*/ +// +// /* Printing to the console. */ +// pc.printf("--> High Impedance State.\r\n"); +// +// /* Preparing each motor to set High Impedance State. */ +// for (int m = 0; m < L6470DAISYCHAINSIZE; m++) +// motors[m]->PrepareHardHiZ(); +// +// /* Performing the action on each motor at the same time. */ +// x_nucleo_ihm02a1->PerformPreparedActions(); +// +// /* Waiting. */ +// wait_ms(DELAY_2); } \ No newline at end of file