![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Smartphone app control stepper motors via bluetooth low energy(BLE) on stm32F401RE x IHM02A1 x IDB05A1.
Dependencies: BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IHM02A1 mbed
Fork of BLE_LED_IDB0XA1_demo by
main.cpp@11:6deabd374c96, 2018-02-23 (annotated)
- Committer:
- yong304
- Date:
- Fri Feb 23 08:12:54 2018 +0000
- Revision:
- 11:6deabd374c96
- Parent:
- 10:21eecb227c05
20180223
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apalmieri | 0:aae2d6c2a9eb | 1 | /* mbed Microcontroller Library |
apalmieri | 0:aae2d6c2a9eb | 2 | * Copyright (c) 2006-2013 ARM Limited |
apalmieri | 0:aae2d6c2a9eb | 3 | * |
apalmieri | 0:aae2d6c2a9eb | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
apalmieri | 0:aae2d6c2a9eb | 5 | * you may not use this file except in compliance with the License. |
apalmieri | 0:aae2d6c2a9eb | 6 | * You may obtain a copy of the License at |
apalmieri | 0:aae2d6c2a9eb | 7 | * |
apalmieri | 0:aae2d6c2a9eb | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
apalmieri | 0:aae2d6c2a9eb | 9 | * |
apalmieri | 0:aae2d6c2a9eb | 10 | * Unless required by applicable law or agreed to in writing, software |
apalmieri | 0:aae2d6c2a9eb | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
apalmieri | 0:aae2d6c2a9eb | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
apalmieri | 0:aae2d6c2a9eb | 13 | * See the License for the specific language governing permissions and |
apalmieri | 0:aae2d6c2a9eb | 14 | * limitations under the License. |
apalmieri | 0:aae2d6c2a9eb | 15 | */ |
barry210110 | 7:126b141a8c86 | 16 | |
barry210110 | 7:126b141a8c86 | 17 | /* Includes ------------------------------------------------------------------*/ |
barry210110 | 7:126b141a8c86 | 18 | |
barry210110 | 7:126b141a8c86 | 19 | |
yong304 | 10:21eecb227c05 | 20 | |
barry210110 | 7:126b141a8c86 | 21 | /* Helper header files. */ |
barry210110 | 7:126b141a8c86 | 22 | #include "DevSPI.h" |
yong304 | 10:21eecb227c05 | 23 | void FWD(); |
yong304 | 10:21eecb227c05 | 24 | void BWD(); |
yong304 | 10:21eecb227c05 | 25 | void LEFT(); |
yong304 | 10:21eecb227c05 | 26 | void RIGHT(); |
yong304 | 11:6deabd374c96 | 27 | void SOFTSTOP(); |
barry210110 | 7:126b141a8c86 | 28 | /* Expansion Board specific header files. */ |
barry210110 | 7:126b141a8c86 | 29 | #include "XNucleoIHM02A1.h" |
apalmieri | 0:aae2d6c2a9eb | 30 | |
apalmieri | 0:aae2d6c2a9eb | 31 | #include "mbed.h" |
apalmieri | 0:aae2d6c2a9eb | 32 | #include "ble/BLE.h" |
apalmieri | 0:aae2d6c2a9eb | 33 | #include "LEDService.h" |
yong304 | 10:21eecb227c05 | 34 | |
barry210110 | 9:ef9b37e2464f | 35 | |
barry210110 | 7:126b141a8c86 | 36 | /* Definitions ---------------------------------------------------------------*/ |
apalmieri | 0:aae2d6c2a9eb | 37 | |
barry210110 | 7:126b141a8c86 | 38 | /* Number of movements per revolution. */ |
barry210110 | 7:126b141a8c86 | 39 | #define MPR_1 4 |
barry210110 | 7:126b141a8c86 | 40 | |
barry210110 | 7:126b141a8c86 | 41 | /* Number of steps. */ |
barry210110 | 7:126b141a8c86 | 42 | #define STEPS_1 (400 * 128) /* 1 revolution given a 400 steps motor configured at 1/128 microstep mode. */ |
barry210110 | 7:126b141a8c86 | 43 | #define STEPS_2 (STEPS_1 * 2) |
barry210110 | 7:126b141a8c86 | 44 | |
barry210110 | 7:126b141a8c86 | 45 | /* Delay in milliseconds. */ |
barry210110 | 7:126b141a8c86 | 46 | #define DELAY_1 1000 |
barry210110 | 7:126b141a8c86 | 47 | #define DELAY_2 2000 |
barry210110 | 7:126b141a8c86 | 48 | #define DELAY_3 5000 |
barry210110 | 7:126b141a8c86 | 49 | |
barry210110 | 9:ef9b37e2464f | 50 | #ifdef TARGET_STM32F401 |
barry210110 | 9:ef9b37e2464f | 51 | DevSPI dev_spi(PB_15, PB_14, PB_13); |
barry210110 | 9:ef9b37e2464f | 52 | #else |
barry210110 | 9:ef9b37e2464f | 53 | DevSPI dev_spi(PB_15, PB_14, PB_13); |
barry210110 | 9:ef9b37e2464f | 54 | #endif |
yong304 | 10:21eecb227c05 | 55 | |
barry210110 | 7:126b141a8c86 | 56 | /* Variables -----------------------------------------------------------------*/ |
barry210110 | 7:126b141a8c86 | 57 | |
barry210110 | 7:126b141a8c86 | 58 | /* Initialization parameters of the motors connected to the expansion board. */ |
barry210110 | 7:126b141a8c86 | 59 | L6470_init_t init[L6470DAISYCHAINSIZE] = { |
barry210110 | 7:126b141a8c86 | 60 | /* First Motor. */ |
barry210110 | 7:126b141a8c86 | 61 | { |
barry210110 | 7:126b141a8c86 | 62 | 9.0, /* Motor supply voltage in V. */ |
barry210110 | 7:126b141a8c86 | 63 | 400, /* Min number of steps per revolution for the motor. */ |
barry210110 | 7:126b141a8c86 | 64 | 1.7, /* Max motor phase voltage in A. */ |
barry210110 | 7:126b141a8c86 | 65 | 3.06, /* Max motor phase voltage in V. */ |
barry210110 | 7:126b141a8c86 | 66 | 300.0, /* Motor initial speed [step/s]. */ |
barry210110 | 7:126b141a8c86 | 67 | 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ |
barry210110 | 7:126b141a8c86 | 68 | 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ |
barry210110 | 7:126b141a8c86 | 69 | 992.0, /* Motor maximum speed [step/s]. */ |
barry210110 | 7:126b141a8c86 | 70 | 0.0, /* Motor minimum speed [step/s]. */ |
barry210110 | 7:126b141a8c86 | 71 | 602.7, /* Motor full-step speed threshold [step/s]. */ |
barry210110 | 7:126b141a8c86 | 72 | 3.06, /* Holding kval [V]. */ |
barry210110 | 7:126b141a8c86 | 73 | 3.06, /* Constant speed kval [V]. */ |
barry210110 | 7:126b141a8c86 | 74 | 3.06, /* Acceleration starting kval [V]. */ |
barry210110 | 7:126b141a8c86 | 75 | 3.06, /* Deceleration starting kval [V]. */ |
barry210110 | 7:126b141a8c86 | 76 | 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */ |
barry210110 | 7:126b141a8c86 | 77 | 392.1569e-6, /* Start slope [s/step]. */ |
barry210110 | 7:126b141a8c86 | 78 | 643.1372e-6, /* Acceleration final slope [s/step]. */ |
barry210110 | 7:126b141a8c86 | 79 | 643.1372e-6, /* Deceleration final slope [s/step]. */ |
barry210110 | 7:126b141a8c86 | 80 | 0, /* Thermal compensation factor (range [0, 15]). */ |
barry210110 | 7:126b141a8c86 | 81 | 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */ |
barry210110 | 7:126b141a8c86 | 82 | 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */ |
barry210110 | 7:126b141a8c86 | 83 | StepperMotor::STEP_MODE_1_128, /* Step mode selection. */ |
barry210110 | 7:126b141a8c86 | 84 | 0xFF, /* Alarm conditions enable. */ |
barry210110 | 7:126b141a8c86 | 85 | 0x2E88 /* Ic configuration. */ |
barry210110 | 7:126b141a8c86 | 86 | }, |
barry210110 | 7:126b141a8c86 | 87 | |
barry210110 | 7:126b141a8c86 | 88 | /* Second Motor. */ |
barry210110 | 7:126b141a8c86 | 89 | { |
barry210110 | 7:126b141a8c86 | 90 | 9.0, /* Motor supply voltage in V. */ |
barry210110 | 7:126b141a8c86 | 91 | 400, /* Min number of steps per revolution for the motor. */ |
barry210110 | 7:126b141a8c86 | 92 | 1.7, /* Max motor phase voltage in A. */ |
barry210110 | 7:126b141a8c86 | 93 | 3.06, /* Max motor phase voltage in V. */ |
barry210110 | 7:126b141a8c86 | 94 | 300.0, /* Motor initial speed [step/s]. */ |
barry210110 | 7:126b141a8c86 | 95 | 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ |
barry210110 | 7:126b141a8c86 | 96 | 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ |
barry210110 | 7:126b141a8c86 | 97 | 992.0, /* Motor maximum speed [step/s]. */ |
barry210110 | 7:126b141a8c86 | 98 | 0.0, /* Motor minimum speed [step/s]. */ |
barry210110 | 7:126b141a8c86 | 99 | 602.7, /* Motor full-step speed threshold [step/s]. */ |
barry210110 | 7:126b141a8c86 | 100 | 3.06, /* Holding kval [V]. */ |
barry210110 | 7:126b141a8c86 | 101 | 3.06, /* Constant speed kval [V]. */ |
barry210110 | 7:126b141a8c86 | 102 | 3.06, /* Acceleration starting kval [V]. */ |
barry210110 | 7:126b141a8c86 | 103 | 3.06, /* Deceleration starting kval [V]. */ |
barry210110 | 7:126b141a8c86 | 104 | 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */ |
barry210110 | 7:126b141a8c86 | 105 | 392.1569e-6, /* Start slope [s/step]. */ |
barry210110 | 7:126b141a8c86 | 106 | 643.1372e-6, /* Acceleration final slope [s/step]. */ |
barry210110 | 7:126b141a8c86 | 107 | 643.1372e-6, /* Deceleration final slope [s/step]. */ |
barry210110 | 7:126b141a8c86 | 108 | 0, /* Thermal compensation factor (range [0, 15]). */ |
barry210110 | 7:126b141a8c86 | 109 | 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */ |
barry210110 | 7:126b141a8c86 | 110 | 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */ |
barry210110 | 7:126b141a8c86 | 111 | StepperMotor::STEP_MODE_1_128, /* Step mode selection. */ |
barry210110 | 7:126b141a8c86 | 112 | 0xFF, /* Alarm conditions enable. */ |
barry210110 | 7:126b141a8c86 | 113 | 0x2E88 /* Ic configuration. */ |
barry210110 | 7:126b141a8c86 | 114 | } |
barry210110 | 7:126b141a8c86 | 115 | }; |
barry210110 | 7:126b141a8c86 | 116 | |
yong304 | 10:21eecb227c05 | 117 | |
yong304 | 10:21eecb227c05 | 118 | /* Motor Control Expansion Board. */ |
yong304 | 11:6deabd374c96 | 119 | XNucleoIHM02A1* x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, D10, &dev_spi); |
barry210110 | 9:ef9b37e2464f | 120 | |
barry210110 | 7:126b141a8c86 | 121 | DigitalOut actuatedLED(LED2); |
barry210110 | 7:126b141a8c86 | 122 | const static char DEVICE_NAME[] = "mydevice"; // CHANGE NAME |
barry210110 | 7:126b141a8c86 | 123 | static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID}; // GATT ATTRIBUTE UUID |
apalmieri | 0:aae2d6c2a9eb | 124 | |
apalmieri | 0:aae2d6c2a9eb | 125 | LEDService *ledServicePtr; |
apalmieri | 0:aae2d6c2a9eb | 126 | |
apalmieri | 0:aae2d6c2a9eb | 127 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) |
apalmieri | 0:aae2d6c2a9eb | 128 | { |
apalmieri | 0:aae2d6c2a9eb | 129 | (void)params; |
apalmieri | 3:e0efdb741bd4 | 130 | BLE::Instance().gap().startAdvertising(); // restart advertising |
apalmieri | 0:aae2d6c2a9eb | 131 | } |
apalmieri | 0:aae2d6c2a9eb | 132 | |
apalmieri | 0:aae2d6c2a9eb | 133 | /** |
apalmieri | 0:aae2d6c2a9eb | 134 | * This callback allows the LEDService to receive updates to the ledState Characteristic. |
apalmieri | 0:aae2d6c2a9eb | 135 | * |
apalmieri | 0:aae2d6c2a9eb | 136 | * @param[in] params |
apalmieri | 0:aae2d6c2a9eb | 137 | * Information about the characterisitc being updated. |
apalmieri | 0:aae2d6c2a9eb | 138 | */ |
apalmieri | 0:aae2d6c2a9eb | 139 | void onDataWrittenCallback(const GattWriteCallbackParams *params) { |
apalmieri | 0:aae2d6c2a9eb | 140 | if ((params->handle == ledServicePtr->getValueHandle()) && (params->len == 1)) { |
yong304 | 10:21eecb227c05 | 141 | |
yong304 | 11:6deabd374c96 | 142 | if ( *(params->data)== 0x41 ) |
barry210110 | 7:126b141a8c86 | 143 | { |
barry210110 | 7:126b141a8c86 | 144 | actuatedLED=1 ; |
yong304 | 11:6deabd374c96 | 145 | FWD(); |
yong304 | 11:6deabd374c96 | 146 | } |
yong304 | 11:6deabd374c96 | 147 | else if (*(params->data)== 0x42) |
yong304 | 11:6deabd374c96 | 148 | { |
barry210110 | 7:126b141a8c86 | 149 | actuatedLED=0 ; |
yong304 | 11:6deabd374c96 | 150 | //SOFTSTOP(); |
yong304 | 11:6deabd374c96 | 151 | |
yong304 | 11:6deabd374c96 | 152 | } |
yong304 | 11:6deabd374c96 | 153 | else if (*(params->data)== 0x43) |
yong304 | 11:6deabd374c96 | 154 | { |
barry210110 | 7:126b141a8c86 | 155 | actuatedLED=1 ; |
yong304 | 11:6deabd374c96 | 156 | //FWD(); |
yong304 | 11:6deabd374c96 | 157 | |
yong304 | 11:6deabd374c96 | 158 | |
yong304 | 11:6deabd374c96 | 159 | } |
yong304 | 11:6deabd374c96 | 160 | else if (*(params->data)== 0x44) |
yong304 | 11:6deabd374c96 | 161 | { |
barry210110 | 7:126b141a8c86 | 162 | actuatedLED=0 ; |
yong304 | 11:6deabd374c96 | 163 | wait(0.1) ; |
yong304 | 11:6deabd374c96 | 164 | BWD(); |
yong304 | 10:21eecb227c05 | 165 | } |
yong304 | 10:21eecb227c05 | 166 | else if (*(params->data)== 0x01) |
yong304 | 10:21eecb227c05 | 167 | { |
yong304 | 10:21eecb227c05 | 168 | actuatedLED=1 ; |
yong304 | 10:21eecb227c05 | 169 | FWD(); |
yong304 | 10:21eecb227c05 | 170 | } |
yong304 | 10:21eecb227c05 | 171 | else if (*(params->data)== 0x02) { |
barry210110 | 7:126b141a8c86 | 172 | actuatedLED=1 ; |
yong304 | 10:21eecb227c05 | 173 | BWD(); |
barry210110 | 7:126b141a8c86 | 174 | } |
yong304 | 10:21eecb227c05 | 175 | else if (*(params->data)== 0x03) { |
yong304 | 10:21eecb227c05 | 176 | actuatedLED=1 ; |
yong304 | 10:21eecb227c05 | 177 | RIGHT(); |
yong304 | 10:21eecb227c05 | 178 | } |
yong304 | 10:21eecb227c05 | 179 | else if (*(params->data)== 0x04) { |
yong304 | 10:21eecb227c05 | 180 | actuatedLED=1 ; |
yong304 | 10:21eecb227c05 | 181 | LEFT(); |
yong304 | 10:21eecb227c05 | 182 | } |
yong304 | 10:21eecb227c05 | 183 | |
barry210110 | 7:126b141a8c86 | 184 | |
apalmieri | 0:aae2d6c2a9eb | 185 | } |
barry210110 | 7:126b141a8c86 | 186 | |
apalmieri | 0:aae2d6c2a9eb | 187 | } |
apalmieri | 0:aae2d6c2a9eb | 188 | |
apalmieri | 0:aae2d6c2a9eb | 189 | /** |
apalmieri | 0:aae2d6c2a9eb | 190 | * This function is called when the ble initialization process has failled |
apalmieri | 0:aae2d6c2a9eb | 191 | */ |
barry210110 | 7:126b141a8c86 | 192 | int onBleInitError(BLE &ble, ble_error_t error) |
apalmieri | 0:aae2d6c2a9eb | 193 | { |
apalmieri | 0:aae2d6c2a9eb | 194 | /* Initialization error handling should go here */ |
apalmieri | 0:aae2d6c2a9eb | 195 | } |
apalmieri | 0:aae2d6c2a9eb | 196 | |
apalmieri | 0:aae2d6c2a9eb | 197 | /** |
apalmieri | 0:aae2d6c2a9eb | 198 | * Callback triggered when the ble initialization process has finished |
apalmieri | 0:aae2d6c2a9eb | 199 | */ |
apalmieri | 0:aae2d6c2a9eb | 200 | void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) |
apalmieri | 0:aae2d6c2a9eb | 201 | { |
apalmieri | 0:aae2d6c2a9eb | 202 | BLE& ble = params->ble; |
apalmieri | 0:aae2d6c2a9eb | 203 | ble_error_t error = params->error; |
apalmieri | 0:aae2d6c2a9eb | 204 | |
apalmieri | 0:aae2d6c2a9eb | 205 | if (error != BLE_ERROR_NONE) { |
apalmieri | 0:aae2d6c2a9eb | 206 | /* In case of error, forward the error handling to onBleInitError */ |
apalmieri | 0:aae2d6c2a9eb | 207 | onBleInitError(ble, error); |
yong304 | 10:21eecb227c05 | 208 | return; |
apalmieri | 0:aae2d6c2a9eb | 209 | } |
apalmieri | 0:aae2d6c2a9eb | 210 | |
apalmieri | 0:aae2d6c2a9eb | 211 | /* Ensure that it is the default instance of BLE */ |
apalmieri | 0:aae2d6c2a9eb | 212 | if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { |
apalmieri | 0:aae2d6c2a9eb | 213 | return; |
apalmieri | 0:aae2d6c2a9eb | 214 | } |
apalmieri | 0:aae2d6c2a9eb | 215 | |
apalmieri | 0:aae2d6c2a9eb | 216 | ble.gap().onDisconnection(disconnectionCallback); |
apalmieri | 0:aae2d6c2a9eb | 217 | ble.gattServer().onDataWritten(onDataWrittenCallback); |
apalmieri | 0:aae2d6c2a9eb | 218 | |
apalmieri | 0:aae2d6c2a9eb | 219 | bool initialValueForLEDCharacteristic = true; |
apalmieri | 3:e0efdb741bd4 | 220 | ledServicePtr = new LEDService(ble, initialValueForLEDCharacteristic); |
apalmieri | 0:aae2d6c2a9eb | 221 | |
apalmieri | 0:aae2d6c2a9eb | 222 | /* setup advertising */ |
apalmieri | 0:aae2d6c2a9eb | 223 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
apalmieri | 0:aae2d6c2a9eb | 224 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); |
apalmieri | 0:aae2d6c2a9eb | 225 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); |
apalmieri | 0:aae2d6c2a9eb | 226 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
apalmieri | 0:aae2d6c2a9eb | 227 | ble.gap().setAdvertisingInterval(1000); /* 1000ms. */ |
apalmieri | 0:aae2d6c2a9eb | 228 | ble.gap().startAdvertising(); |
barry210110 | 7:126b141a8c86 | 229 | |
apalmieri | 0:aae2d6c2a9eb | 230 | while (true) { |
apalmieri | 0:aae2d6c2a9eb | 231 | ble.waitForEvent(); |
apalmieri | 0:aae2d6c2a9eb | 232 | } |
apalmieri | 0:aae2d6c2a9eb | 233 | } |
apalmieri | 0:aae2d6c2a9eb | 234 | |
apalmieri | 0:aae2d6c2a9eb | 235 | int main(void) |
barry210110 | 7:126b141a8c86 | 236 | { |
barry210110 | 7:126b141a8c86 | 237 | |
apalmieri | 0:aae2d6c2a9eb | 238 | BLE &ble = BLE::Instance(); |
apalmieri | 0:aae2d6c2a9eb | 239 | |
barry210110 | 7:126b141a8c86 | 240 | ble.init(bleInitComplete); |
barry210110 | 7:126b141a8c86 | 241 | |
apalmieri | 0:aae2d6c2a9eb | 242 | } |
yong304 | 10:21eecb227c05 | 243 | |
yong304 | 10:21eecb227c05 | 244 | void FWD() |
yong304 | 10:21eecb227c05 | 245 | { |
barry210110 | 9:ef9b37e2464f | 246 | |
barry210110 | 7:126b141a8c86 | 247 | /* Building a list of motor control components. */ |
barry210110 | 7:126b141a8c86 | 248 | L6470 **motors = x_nucleo_ihm02a1->get_components(); |
yong304 | 11:6deabd374c96 | 249 | //otors[0]->set_home(); |
yong304 | 10:21eecb227c05 | 250 | |
yong304 | 10:21eecb227c05 | 251 | /* Getting the current position. */ |
yong304 | 11:6deabd374c96 | 252 | //t position = motors[0]->get_position(); |
yong304 | 10:21eecb227c05 | 253 | |
yong304 | 11:6deabd374c96 | 254 | /* Preparing each motor to perform a run at a specified speed. */ |
yong304 | 10:21eecb227c05 | 255 | for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { |
yong304 | 11:6deabd374c96 | 256 | motors[m]->prepare_run(StepperMotor::FWD, 400); |
yong304 | 10:21eecb227c05 | 257 | } |
yong304 | 10:21eecb227c05 | 258 | |
yong304 | 10:21eecb227c05 | 259 | /* Performing the action on each motor at the same time. */ |
yong304 | 10:21eecb227c05 | 260 | x_nucleo_ihm02a1->perform_prepared_actions(); |
yong304 | 10:21eecb227c05 | 261 | |
yong304 | 10:21eecb227c05 | 262 | /* Waiting while active. */ |
yong304 | 10:21eecb227c05 | 263 | motors[0]->wait_while_active(); |
yong304 | 11:6deabd374c96 | 264 | motors[1]->wait_while_active(); |
yong304 | 10:21eecb227c05 | 265 | } |
yong304 | 10:21eecb227c05 | 266 | |
yong304 | 10:21eecb227c05 | 267 | void BWD() |
yong304 | 10:21eecb227c05 | 268 | { |
yong304 | 10:21eecb227c05 | 269 | |
yong304 | 10:21eecb227c05 | 270 | /* Building a list of motor control components. */ |
yong304 | 10:21eecb227c05 | 271 | L6470 **motors = x_nucleo_ihm02a1->get_components(); |
yong304 | 11:6deabd374c96 | 272 | // motors[0]->set_home(); |
barry210110 | 7:126b141a8c86 | 273 | |
barry210110 | 7:126b141a8c86 | 274 | /* Getting the current position. */ |
yong304 | 11:6deabd374c96 | 275 | // int position = motors[0]->get_position(); |
barry210110 | 7:126b141a8c86 | 276 | |
yong304 | 10:21eecb227c05 | 277 | /* Preparing each motor to perform a run at a specified speed. */ |
yong304 | 10:21eecb227c05 | 278 | for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { |
yong304 | 10:21eecb227c05 | 279 | motors[m]->prepare_move(StepperMotor::BWD, 25600); |
yong304 | 10:21eecb227c05 | 280 | } |
yong304 | 10:21eecb227c05 | 281 | |
yong304 | 10:21eecb227c05 | 282 | /* Performing the action on each motor at the same time. */ |
yong304 | 10:21eecb227c05 | 283 | x_nucleo_ihm02a1->perform_prepared_actions(); |
yong304 | 10:21eecb227c05 | 284 | |
yong304 | 10:21eecb227c05 | 285 | /* Waiting while active. */ |
yong304 | 10:21eecb227c05 | 286 | motors[0]->wait_while_active(); |
yong304 | 11:6deabd374c96 | 287 | motors[1]->wait_while_active(); |
yong304 | 10:21eecb227c05 | 288 | } |
yong304 | 10:21eecb227c05 | 289 | void LEFT() |
yong304 | 10:21eecb227c05 | 290 | { |
yong304 | 10:21eecb227c05 | 291 | |
yong304 | 10:21eecb227c05 | 292 | /* Building a list of motor control components. */ |
yong304 | 10:21eecb227c05 | 293 | L6470 **motors = x_nucleo_ihm02a1->get_components(); |
yong304 | 11:6deabd374c96 | 294 | // motors[0]->set_home(); |
yong304 | 10:21eecb227c05 | 295 | |
yong304 | 10:21eecb227c05 | 296 | /* Getting the current position. */ |
yong304 | 11:6deabd374c96 | 297 | // int position = motors[0]->get_position(); |
yong304 | 10:21eecb227c05 | 298 | |
yong304 | 10:21eecb227c05 | 299 | /* Preparing each motor to perform a run at a specified speed. */ |
yong304 | 10:21eecb227c05 | 300 | motors[0]->prepare_move(StepperMotor::FWD, 25600); |
yong304 | 10:21eecb227c05 | 301 | motors[1]->prepare_move(StepperMotor::BWD, 25600); |
barry210110 | 7:126b141a8c86 | 302 | |
yong304 | 10:21eecb227c05 | 303 | /* Performing the action on each motor at the same time. */ |
yong304 | 10:21eecb227c05 | 304 | x_nucleo_ihm02a1->perform_prepared_actions(); |
barry210110 | 7:126b141a8c86 | 305 | |
yong304 | 10:21eecb227c05 | 306 | /* Waiting while active. */ |
yong304 | 10:21eecb227c05 | 307 | motors[0]->wait_while_active(); |
yong304 | 11:6deabd374c96 | 308 | motors[1]->wait_while_active(); |
yong304 | 10:21eecb227c05 | 309 | } |
yong304 | 10:21eecb227c05 | 310 | void RIGHT() |
yong304 | 10:21eecb227c05 | 311 | { |
yong304 | 10:21eecb227c05 | 312 | |
yong304 | 10:21eecb227c05 | 313 | /* Building a list of motor control components. */ |
yong304 | 10:21eecb227c05 | 314 | L6470 **motors = x_nucleo_ihm02a1->get_components(); |
yong304 | 11:6deabd374c96 | 315 | // motors[0]->set_home(); |
yong304 | 10:21eecb227c05 | 316 | |
yong304 | 10:21eecb227c05 | 317 | /* Getting the current position. */ |
yong304 | 11:6deabd374c96 | 318 | // int position = motors[0]->get_position(); |
yong304 | 10:21eecb227c05 | 319 | |
yong304 | 10:21eecb227c05 | 320 | /* Preparing each motor to perform a run at a specified speed. */ |
yong304 | 10:21eecb227c05 | 321 | motors[1]->prepare_move(StepperMotor::FWD, 25600); |
yong304 | 10:21eecb227c05 | 322 | motors[0]->prepare_move(StepperMotor::BWD, 25600); |
yong304 | 10:21eecb227c05 | 323 | |
yong304 | 10:21eecb227c05 | 324 | /* Performing the action on each motor at the same time. */ |
yong304 | 10:21eecb227c05 | 325 | x_nucleo_ihm02a1->perform_prepared_actions(); |
barry210110 | 9:ef9b37e2464f | 326 | |
yong304 | 10:21eecb227c05 | 327 | /* Waiting while active. */ |
yong304 | 10:21eecb227c05 | 328 | motors[0]->wait_while_active(); |
yong304 | 11:6deabd374c96 | 329 | motors[1]->wait_while_active(); |
yong304 | 11:6deabd374c96 | 330 | } |
yong304 | 11:6deabd374c96 | 331 | void SOFTSTOP() |
yong304 | 11:6deabd374c96 | 332 | { |
yong304 | 11:6deabd374c96 | 333 | |
yong304 | 11:6deabd374c96 | 334 | /* Building a list of motor control components. */ |
yong304 | 11:6deabd374c96 | 335 | L6470 **motors = x_nucleo_ihm02a1->get_components(); |
yong304 | 11:6deabd374c96 | 336 | /* Preparing each motor to perform a hard stop. */ |
yong304 | 11:6deabd374c96 | 337 | for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { |
yong304 | 11:6deabd374c96 | 338 | motors[m]->prepare_soft_stop(); |
yong304 | 11:6deabd374c96 | 339 | } |
yong304 | 11:6deabd374c96 | 340 | |
yong304 | 11:6deabd374c96 | 341 | /* Performing the action on each motor at the same time. */ |
yong304 | 11:6deabd374c96 | 342 | x_nucleo_ihm02a1->perform_prepared_actions(); |
yong304 | 11:6deabd374c96 | 343 | |
yong304 | 11:6deabd374c96 | 344 | } |