![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
20180223
Dependencies: BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IHM02A1 mbed
Fork of Motor_Ble_v1 by
Revision 11:6deabd374c96, committed 2018-02-23
- Comitter:
- yong304
- Date:
- Fri Feb 23 08:12:54 2018 +0000
- Parent:
- 10:21eecb227c05
- Commit message:
- 20180223
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 21eecb227c05 -r 6deabd374c96 main.cpp --- a/main.cpp Tue Feb 06 07:51:55 2018 +0000 +++ b/main.cpp Fri Feb 23 08:12:54 2018 +0000 @@ -24,6 +24,7 @@ void BWD(); void LEFT(); void RIGHT(); +void SOFTSTOP(); /* Expansion Board specific header files. */ #include "XNucleoIHM02A1.h" @@ -115,7 +116,7 @@ /* Motor Control Expansion Board. */ -XNucleoIHM02A1* x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi); +XNucleoIHM02A1* x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, D10, &dev_spi); DigitalOut actuatedLED(LED2); const static char DEVICE_NAME[] = "mydevice"; // CHANGE NAME @@ -138,21 +139,29 @@ void onDataWrittenCallback(const GattWriteCallbackParams *params) { if ((params->handle == ledServicePtr->getValueHandle()) && (params->len == 1)) { - if ( *(params->data)== 0x00 ) + if ( *(params->data)== 0x41 ) { - actuatedLED=0 ; - wait(0.5) ; actuatedLED=1 ; - wait(0.5) ; + FWD(); + } + else if (*(params->data)== 0x42) + { actuatedLED=0 ; - wait(0.5) ; + //SOFTSTOP(); + + } + else if (*(params->data)== 0x43) + { actuatedLED=1 ; - wait(0.5) ; + //FWD(); + + + } + else if (*(params->data)== 0x44) + { actuatedLED=0 ; - wait(0.5) ; - actuatedLED=1 ; - wait(0.5) ; - actuatedLED=0 ; + wait(0.1) ; + BWD(); } else if (*(params->data)== 0x01) { @@ -237,14 +246,14 @@ /* Building a list of motor control components. */ L6470 **motors = x_nucleo_ihm02a1->get_components(); - motors[0]->set_home(); + //otors[0]->set_home(); /* Getting the current position. */ - int position = motors[0]->get_position(); + //t position = motors[0]->get_position(); - /* Preparing each motor to perform a run at a specified speed. */ + /* Preparing each motor to perform a run at a specified speed. */ for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { - motors[m]->prepare_move(StepperMotor::FWD, 25600); + motors[m]->prepare_run(StepperMotor::FWD, 400); } /* Performing the action on each motor at the same time. */ @@ -252,6 +261,7 @@ /* Waiting while active. */ motors[0]->wait_while_active(); + motors[1]->wait_while_active(); } void BWD() @@ -259,10 +269,10 @@ /* Building a list of motor control components. */ L6470 **motors = x_nucleo_ihm02a1->get_components(); - motors[0]->set_home(); + // motors[0]->set_home(); /* Getting the current position. */ - int position = motors[0]->get_position(); +// int position = motors[0]->get_position(); /* Preparing each motor to perform a run at a specified speed. */ for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { @@ -274,16 +284,17 @@ /* Waiting while active. */ motors[0]->wait_while_active(); + motors[1]->wait_while_active(); } void LEFT() { /* Building a list of motor control components. */ L6470 **motors = x_nucleo_ihm02a1->get_components(); - motors[0]->set_home(); + // motors[0]->set_home(); /* Getting the current position. */ - int position = motors[0]->get_position(); + // int position = motors[0]->get_position(); /* Preparing each motor to perform a run at a specified speed. */ motors[0]->prepare_move(StepperMotor::FWD, 25600); @@ -294,16 +305,17 @@ /* Waiting while active. */ motors[0]->wait_while_active(); + motors[1]->wait_while_active(); } void RIGHT() { /* Building a list of motor control components. */ L6470 **motors = x_nucleo_ihm02a1->get_components(); - motors[0]->set_home(); + // motors[0]->set_home(); /* Getting the current position. */ - int position = motors[0]->get_position(); +// int position = motors[0]->get_position(); /* Preparing each motor to perform a run at a specified speed. */ motors[1]->prepare_move(StepperMotor::FWD, 25600); @@ -314,4 +326,19 @@ /* Waiting while active. */ motors[0]->wait_while_active(); -} \ No newline at end of file + motors[1]->wait_while_active(); +} +void SOFTSTOP() +{ + + /* Building a list of motor control components. */ + L6470 **motors = x_nucleo_ihm02a1->get_components(); + /* Preparing each motor to perform a hard stop. */ + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { + motors[m]->prepare_soft_stop(); + } + + /* Performing the action on each motor at the same time. */ + x_nucleo_ihm02a1->perform_prepared_actions(); + + } \ No newline at end of file