Simple test application for the STMicroelectronics X-NUCLEO-IHM02A1 Stepper Motor Control Expansion Board.

Dependencies:   X_NUCLEO_IHM02A1 mbed

Fork of HelloWorld_IHM02A1 by ST Expansion SW Team

Motor Control with the X-NUCLEO-IHM02A1 Expansion Board

This application provides a simple example of usage of the X-NUCLEO-IHM02A1 Stepper Motor Control Expansion Board.
It shows how to use two stepper motors connected in daisy chain configuration to the board, moving the rotors to specific positions, with given speed values, direction of rotations, etc.

Committer:
Davidroid
Date:
Thu Jan 14 10:01:18 2016 +0000
Revision:
11:79fcaf38c09d
Parent:
9:f35fbeedb8f4
Child:
12:5be6dd48b94a
+ Updated with the new version of the library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:5148e9486cf2 1 /**
Davidroid 0:5148e9486cf2 2 ******************************************************************************
Davidroid 0:5148e9486cf2 3 * @file main.cpp
Davidroid 2:41eeee48951b 4 * @author Davide Aliprandi, STMicrolectronics
Davidroid 0:5148e9486cf2 5 * @version V1.0.0
Davidroid 0:5148e9486cf2 6 * @date November 4th, 2015
Davidroid 1:9f1974b0960d 7 * @brief mbed test application for the STMicrolectronics X-NUCLEO-IHM02A1
Davidroid 1:9f1974b0960d 8 * Motor Control Expansion Board: control of 2 motors.
Davidroid 0:5148e9486cf2 9 ******************************************************************************
Davidroid 0:5148e9486cf2 10 * @attention
Davidroid 0:5148e9486cf2 11 *
Davidroid 0:5148e9486cf2 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Davidroid 0:5148e9486cf2 13 *
Davidroid 0:5148e9486cf2 14 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 0:5148e9486cf2 15 * are permitted provided that the following conditions are met:
Davidroid 0:5148e9486cf2 16 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 0:5148e9486cf2 17 * this list of conditions and the following disclaimer.
Davidroid 0:5148e9486cf2 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 0:5148e9486cf2 19 * this list of conditions and the following disclaimer in the documentation
Davidroid 0:5148e9486cf2 20 * and/or other materials provided with the distribution.
Davidroid 0:5148e9486cf2 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 0:5148e9486cf2 22 * may be used to endorse or promote products derived from this software
Davidroid 0:5148e9486cf2 23 * without specific prior written permission.
Davidroid 0:5148e9486cf2 24 *
Davidroid 0:5148e9486cf2 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 0:5148e9486cf2 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 0:5148e9486cf2 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 0:5148e9486cf2 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 0:5148e9486cf2 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 0:5148e9486cf2 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 0:5148e9486cf2 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 0:5148e9486cf2 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 0:5148e9486cf2 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 0:5148e9486cf2 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 0:5148e9486cf2 35 *
Davidroid 0:5148e9486cf2 36 ******************************************************************************
Davidroid 0:5148e9486cf2 37 */
Davidroid 0:5148e9486cf2 38
Davidroid 0:5148e9486cf2 39
Davidroid 0:5148e9486cf2 40 /* Includes ------------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 41
Davidroid 0:5148e9486cf2 42 /* mbed specific header files. */
Davidroid 0:5148e9486cf2 43 #include "mbed.h"
Davidroid 0:5148e9486cf2 44
Davidroid 0:5148e9486cf2 45 /* Helper header files. */
Davidroid 0:5148e9486cf2 46 #include "DevSPI.h"
Davidroid 0:5148e9486cf2 47
Davidroid 0:5148e9486cf2 48 /* Expansion Board specific header files. */
Davidroid 0:5148e9486cf2 49 #include "x_nucleo_ihm02a1_class.h"
Davidroid 0:5148e9486cf2 50
Davidroid 0:5148e9486cf2 51
Davidroid 0:5148e9486cf2 52 /* Definitions ---------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 53
Davidroid 0:5148e9486cf2 54 /* Number of movements per revolution. */
Davidroid 0:5148e9486cf2 55 #define MPR_1 4
Davidroid 1:9f1974b0960d 56
Davidroid 1:9f1974b0960d 57 /* Number of steps. */
Davidroid 1:9f1974b0960d 58 #define STEPS_1 100000
Davidroid 1:9f1974b0960d 59 #define STEPS_2 200000
Davidroid 0:5148e9486cf2 60
Davidroid 0:5148e9486cf2 61 /* Delay in milliseconds. */
Davidroid 1:9f1974b0960d 62 #define DELAY_1 1000
Davidroid 0:5148e9486cf2 63 #define DELAY_2 2000
Davidroid 0:5148e9486cf2 64 #define DELAY_3 5000
Davidroid 0:5148e9486cf2 65
Davidroid 0:5148e9486cf2 66
Davidroid 0:5148e9486cf2 67 /* Variables -----------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 68
Davidroid 0:5148e9486cf2 69 /* Motor Control Expansion Board. */
Davidroid 0:5148e9486cf2 70 X_NUCLEO_IHM02A1 *x_nucleo_ihm02a1;
Davidroid 0:5148e9486cf2 71
Davidroid 9:f35fbeedb8f4 72 /* Initialization parameters of the motors connected to the expansion board. */
Davidroid 11:79fcaf38c09d 73 L6470_InitTypeDef init[L6470DAISYCHAINSIZE] =
Davidroid 9:f35fbeedb8f4 74 {
Davidroid 9:f35fbeedb8f4 75 /* First Motor. */
Davidroid 9:f35fbeedb8f4 76 {
Davidroid 9:f35fbeedb8f4 77 9.0, /* Motor supply voltage in V. */
Davidroid 11:79fcaf38c09d 78 400, /* Min number of steps per revolution for the motor. */
Davidroid 9:f35fbeedb8f4 79 1.7, /* Max motor phase voltage in A. */
Davidroid 9:f35fbeedb8f4 80 3.06, /* Max motor phase voltage in V. */
Davidroid 9:f35fbeedb8f4 81 300.0, /* Motor initial speed [step/s]. */
Davidroid 9:f35fbeedb8f4 82 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
Davidroid 9:f35fbeedb8f4 83 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
Davidroid 9:f35fbeedb8f4 84 992.0, /* Motor maximum speed [step/s]. */
Davidroid 9:f35fbeedb8f4 85 0.0, /* Motor minimum speed [step/s]. */
Davidroid 9:f35fbeedb8f4 86 602.7, /* Motor full-step speed threshold [step/s]. */
Davidroid 9:f35fbeedb8f4 87 3.06, /* Holding kval [V]. */
Davidroid 9:f35fbeedb8f4 88 3.06, /* Constant speed kval [V]. */
Davidroid 9:f35fbeedb8f4 89 3.06, /* Acceleration starting kval [V]. */
Davidroid 9:f35fbeedb8f4 90 3.06, /* Deceleration starting kval [V]. */
Davidroid 9:f35fbeedb8f4 91 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */
Davidroid 9:f35fbeedb8f4 92 392.1569e-6, /* Start slope [s/step]. */
Davidroid 9:f35fbeedb8f4 93 643.1372e-6, /* Acceleration final slope [s/step]. */
Davidroid 9:f35fbeedb8f4 94 643.1372e-6, /* Deceleration final slope [s/step]. */
Davidroid 9:f35fbeedb8f4 95 0, /* Thermal compensation factor (range [0, 15]). */
Davidroid 9:f35fbeedb8f4 96 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
Davidroid 9:f35fbeedb8f4 97 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
Davidroid 9:f35fbeedb8f4 98 MICROSTEP_1_128, /* Step mode selection. */
Davidroid 9:f35fbeedb8f4 99 0xFF, /* Alarm conditions enable. */
Davidroid 9:f35fbeedb8f4 100 0x2E88 /* Ic configuration. */
Davidroid 9:f35fbeedb8f4 101 },
Davidroid 9:f35fbeedb8f4 102
Davidroid 9:f35fbeedb8f4 103 /* Second Motor. */
Davidroid 9:f35fbeedb8f4 104 {
Davidroid 9:f35fbeedb8f4 105 9.0, /* Motor supply voltage in V. */
Davidroid 11:79fcaf38c09d 106 400, /* Min number of steps per revolution for the motor. */
Davidroid 9:f35fbeedb8f4 107 1.7, /* Max motor phase voltage in A. */
Davidroid 9:f35fbeedb8f4 108 3.06, /* Max motor phase voltage in V. */
Davidroid 9:f35fbeedb8f4 109 300.0, /* Motor initial speed [step/s]. */
Davidroid 9:f35fbeedb8f4 110 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
Davidroid 9:f35fbeedb8f4 111 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
Davidroid 9:f35fbeedb8f4 112 992.0, /* Motor maximum speed [step/s]. */
Davidroid 9:f35fbeedb8f4 113 0.0, /* Motor minimum speed [step/s]. */
Davidroid 9:f35fbeedb8f4 114 602.7, /* Motor full-step speed threshold [step/s]. */
Davidroid 9:f35fbeedb8f4 115 3.06, /* Holding kval [V]. */
Davidroid 9:f35fbeedb8f4 116 3.06, /* Constant speed kval [V]. */
Davidroid 9:f35fbeedb8f4 117 3.06, /* Acceleration starting kval [V]. */
Davidroid 9:f35fbeedb8f4 118 3.06, /* Deceleration starting kval [V]. */
Davidroid 9:f35fbeedb8f4 119 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */
Davidroid 9:f35fbeedb8f4 120 392.1569e-6, /* Start slope [s/step]. */
Davidroid 9:f35fbeedb8f4 121 643.1372e-6, /* Acceleration final slope [s/step]. */
Davidroid 9:f35fbeedb8f4 122 643.1372e-6, /* Deceleration final slope [s/step]. */
Davidroid 9:f35fbeedb8f4 123 0, /* Thermal compensation factor (range [0, 15]). */
Davidroid 9:f35fbeedb8f4 124 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
Davidroid 9:f35fbeedb8f4 125 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
Davidroid 9:f35fbeedb8f4 126 MICROSTEP_1_128, /* Step mode selection. */
Davidroid 9:f35fbeedb8f4 127 0xFF, /* Alarm conditions enable. */
Davidroid 9:f35fbeedb8f4 128 0x2E88 /* Ic configuration. */
Davidroid 9:f35fbeedb8f4 129 }
Davidroid 9:f35fbeedb8f4 130 };
Davidroid 9:f35fbeedb8f4 131
Davidroid 0:5148e9486cf2 132
Davidroid 0:5148e9486cf2 133 /* Main ----------------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 134
Davidroid 0:5148e9486cf2 135 int main()
Davidroid 0:5148e9486cf2 136 {
Davidroid 1:9f1974b0960d 137 /*----- Initialization. -----*/
Davidroid 1:9f1974b0960d 138
Davidroid 2:41eeee48951b 139 /* Initializing SPI bus. */
Davidroid 3:fd280b953f77 140 DevSPI dev_spi(D11, D12, D3);
Davidroid 0:5148e9486cf2 141
Davidroid 5:3b8e19bbf386 142 /* Initializing Motor Control Expansion Board. */
Davidroid 9:f35fbeedb8f4 143 x_nucleo_ihm02a1 = new X_NUCLEO_IHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);
Davidroid 0:5148e9486cf2 144
Davidroid 1:9f1974b0960d 145 /* Building a list of motor control components. */
Davidroid 1:9f1974b0960d 146 L6470 **motors = x_nucleo_ihm02a1->GetComponents();
Davidroid 0:5148e9486cf2 147
Davidroid 0:5148e9486cf2 148 /* Printing to the console. */
Davidroid 0:5148e9486cf2 149 printf("Motor Control Application Example for 2 Motors\r\n\n");
Davidroid 0:5148e9486cf2 150
Davidroid 1:9f1974b0960d 151
Davidroid 1:9f1974b0960d 152 /*----- Setting home and marke positions, getting positions, and going to positions. -----*/
Davidroid 1:9f1974b0960d 153
Davidroid 1:9f1974b0960d 154 /* Printing to the console. */
Davidroid 1:9f1974b0960d 155 printf("--> Setting home position.\r\n");
Davidroid 1:9f1974b0960d 156
Davidroid 1:9f1974b0960d 157 /* Setting the home position. */
Davidroid 1:9f1974b0960d 158 motors[0]->SetHome();
Davidroid 1:9f1974b0960d 159
Davidroid 1:9f1974b0960d 160 /* Waiting. */
Davidroid 1:9f1974b0960d 161 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 162
Davidroid 1:9f1974b0960d 163 /* Getting the current position. */
Davidroid 1:9f1974b0960d 164 int position = motors[0]->GetPosition();
Davidroid 1:9f1974b0960d 165
Davidroid 1:9f1974b0960d 166 /* Printing to the console. */
Davidroid 1:9f1974b0960d 167 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 168
Davidroid 1:9f1974b0960d 169 /* Waiting. */
Davidroid 1:9f1974b0960d 170 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 171
Davidroid 1:9f1974b0960d 172 /* Printing to the console. */
Davidroid 1:9f1974b0960d 173 printf("--> Moving forward %d steps.\r\n", STEPS_1);
Davidroid 1:9f1974b0960d 174
Davidroid 1:9f1974b0960d 175 /* Moving. */
Davidroid 1:9f1974b0960d 176 motors[0]->Move(StepperMotor::FWD, STEPS_1);
Davidroid 0:5148e9486cf2 177
Davidroid 1:9f1974b0960d 178 /* Waiting while active. */
Davidroid 1:9f1974b0960d 179 motors[0]->WaitWhileActive();
Davidroid 1:9f1974b0960d 180
Davidroid 1:9f1974b0960d 181 /* Getting the current position. */
Davidroid 1:9f1974b0960d 182 position = motors[0]->GetPosition();
Davidroid 1:9f1974b0960d 183
Davidroid 1:9f1974b0960d 184 /* Printing to the console. */
Davidroid 1:9f1974b0960d 185 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 186
Davidroid 1:9f1974b0960d 187 /* Printing to the console. */
Davidroid 1:9f1974b0960d 188 printf("--> Marking the current position.\r\n");
Davidroid 0:5148e9486cf2 189
Davidroid 1:9f1974b0960d 190 /* Marking the current position. */
Davidroid 1:9f1974b0960d 191 motors[0]->SetMark();
Davidroid 1:9f1974b0960d 192
Davidroid 1:9f1974b0960d 193 /* Waiting. */
Davidroid 1:9f1974b0960d 194 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 195
Davidroid 1:9f1974b0960d 196 /* Printing to the console. */
Davidroid 1:9f1974b0960d 197 printf("--> Moving backward %d steps.\r\n", STEPS_2);
Davidroid 1:9f1974b0960d 198
Davidroid 1:9f1974b0960d 199 /* Moving. */
Davidroid 1:9f1974b0960d 200 motors[0]->Move(StepperMotor::BWD, STEPS_2);
Davidroid 1:9f1974b0960d 201
Davidroid 1:9f1974b0960d 202 /* Waiting while active. */
Davidroid 1:9f1974b0960d 203 motors[0]->WaitWhileActive();
Davidroid 0:5148e9486cf2 204
Davidroid 1:9f1974b0960d 205 /* Waiting. */
Davidroid 1:9f1974b0960d 206 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 207
Davidroid 1:9f1974b0960d 208 /* Getting the current position. */
Davidroid 1:9f1974b0960d 209 position = motors[0]->GetPosition();
Davidroid 1:9f1974b0960d 210
Davidroid 1:9f1974b0960d 211 /* Printing to the console. */
Davidroid 1:9f1974b0960d 212 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 213
Davidroid 1:9f1974b0960d 214 /* Waiting. */
Davidroid 1:9f1974b0960d 215 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 216
Davidroid 1:9f1974b0960d 217 /* Printing to the console. */
Davidroid 1:9f1974b0960d 218 printf("--> Going to marked position.\r\n");
Davidroid 0:5148e9486cf2 219
Davidroid 1:9f1974b0960d 220 /* Going to marked position. */
Davidroid 1:9f1974b0960d 221 motors[0]->GoMark();
Davidroid 1:9f1974b0960d 222
Davidroid 1:9f1974b0960d 223 /* Waiting while active. */
Davidroid 1:9f1974b0960d 224 motors[0]->WaitWhileActive();
Davidroid 0:5148e9486cf2 225
Davidroid 1:9f1974b0960d 226 /* Waiting. */
Davidroid 1:9f1974b0960d 227 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 228
Davidroid 1:9f1974b0960d 229 /* Getting the current position. */
Davidroid 1:9f1974b0960d 230 position = motors[0]->GetPosition();
Davidroid 1:9f1974b0960d 231
Davidroid 1:9f1974b0960d 232 /* Printing to the console. */
Davidroid 1:9f1974b0960d 233 printf("--> Getting the current position: %d\r\n", position);
Davidroid 0:5148e9486cf2 234
Davidroid 1:9f1974b0960d 235 /* Waiting. */
Davidroid 1:9f1974b0960d 236 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 237
Davidroid 1:9f1974b0960d 238 /* Printing to the console. */
Davidroid 1:9f1974b0960d 239 printf("--> Going to home position.\r\n");
Davidroid 0:5148e9486cf2 240
Davidroid 1:9f1974b0960d 241 /* Going to home position. */
Davidroid 1:9f1974b0960d 242 motors[0]->GoHome();
Davidroid 1:9f1974b0960d 243
Davidroid 1:9f1974b0960d 244 /* Waiting while active. */
Davidroid 1:9f1974b0960d 245 motors[0]->WaitWhileActive();
Davidroid 1:9f1974b0960d 246
Davidroid 1:9f1974b0960d 247 /* Waiting. */
Davidroid 1:9f1974b0960d 248 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 249
Davidroid 1:9f1974b0960d 250 /* Getting the current position. */
Davidroid 1:9f1974b0960d 251 position = motors[0]->GetPosition();
Davidroid 1:9f1974b0960d 252
Davidroid 1:9f1974b0960d 253 /* Printing to the console. */
Davidroid 1:9f1974b0960d 254 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 255
Davidroid 1:9f1974b0960d 256 /* Waiting. */
Davidroid 1:9f1974b0960d 257 wait_ms(DELAY_2);
Davidroid 0:5148e9486cf2 258
Davidroid 0:5148e9486cf2 259
Davidroid 1:9f1974b0960d 260 /*----- Running together for a certain amount of time. -----*/
Davidroid 1:9f1974b0960d 261
Davidroid 1:9f1974b0960d 262 /* Printing to the console. */
Davidroid 1:9f1974b0960d 263 printf("--> Running together for %d seconds.\r\n", DELAY_3 / 1000);
Davidroid 0:5148e9486cf2 264
Davidroid 1:9f1974b0960d 265 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 1:9f1974b0960d 266 for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
Davidroid 1:9f1974b0960d 267 motors[m]->PrepareRun(StepperMotor::BWD, 400);
Davidroid 0:5148e9486cf2 268
Davidroid 1:9f1974b0960d 269 /* Performing the action on each motor at the same time. */
Davidroid 1:9f1974b0960d 270 x_nucleo_ihm02a1->PerformPreparedActions();
Davidroid 0:5148e9486cf2 271
Davidroid 1:9f1974b0960d 272 /* Waiting. */
Davidroid 1:9f1974b0960d 273 wait_ms(DELAY_3);
Davidroid 1:9f1974b0960d 274
Davidroid 1:9f1974b0960d 275
Davidroid 1:9f1974b0960d 276 /*----- Increasing the speed while running. -----*/
Davidroid 0:5148e9486cf2 277
Davidroid 1:9f1974b0960d 278 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 1:9f1974b0960d 279 for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
Davidroid 1:9f1974b0960d 280 motors[m]->PrepareGetSpeed();
Davidroid 0:5148e9486cf2 281
Davidroid 1:9f1974b0960d 282 /* Performing the action on each motor at the same time. */
Davidroid 1:9f1974b0960d 283 uint32_t* results = x_nucleo_ihm02a1->PerformPreparedActions();
Davidroid 0:5148e9486cf2 284
Davidroid 1:9f1974b0960d 285 /* Printing to the console. */
Davidroid 1:9f1974b0960d 286 printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]);
Davidroid 1:9f1974b0960d 287
Davidroid 1:9f1974b0960d 288 /* Printing to the console. */
Davidroid 1:9f1974b0960d 289 printf("--> Doublig the speed while running.\r\n");
Davidroid 0:5148e9486cf2 290
Davidroid 1:9f1974b0960d 291 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 1:9f1974b0960d 292 for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
Davidroid 1:9f1974b0960d 293 motors[m]->PrepareRun(StepperMotor::BWD, results[m] << 1);
Davidroid 1:9f1974b0960d 294
Davidroid 1:9f1974b0960d 295 /* Performing the action on each motor at the same time. */
Davidroid 1:9f1974b0960d 296 results = x_nucleo_ihm02a1->PerformPreparedActions();
Davidroid 0:5148e9486cf2 297
Davidroid 1:9f1974b0960d 298 /* Waiting. */
Davidroid 1:9f1974b0960d 299 wait_ms(DELAY_3);
Davidroid 0:5148e9486cf2 300
Davidroid 1:9f1974b0960d 301 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 1:9f1974b0960d 302 for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
Davidroid 1:9f1974b0960d 303 motors[m]->PrepareGetSpeed();
Davidroid 0:5148e9486cf2 304
Davidroid 1:9f1974b0960d 305 /* Performing the action on each motor at the same time. */
Davidroid 1:9f1974b0960d 306 results = x_nucleo_ihm02a1->PerformPreparedActions();
Davidroid 0:5148e9486cf2 307
Davidroid 1:9f1974b0960d 308 /* Printing to the console. */
Davidroid 1:9f1974b0960d 309 printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]);
Davidroid 1:9f1974b0960d 310
Davidroid 1:9f1974b0960d 311 /* Waiting. */
Davidroid 1:9f1974b0960d 312 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 313
Davidroid 0:5148e9486cf2 314
Davidroid 1:9f1974b0960d 315 /*----- Hard Stop. -----*/
Davidroid 0:5148e9486cf2 316
Davidroid 1:9f1974b0960d 317 /* Printing to the console. */
Davidroid 1:9f1974b0960d 318 printf("--> Hard Stop.\r\n");
Davidroid 0:5148e9486cf2 319
Davidroid 1:9f1974b0960d 320 /* Preparing each motor to perform a hard stop. */
Davidroid 1:9f1974b0960d 321 for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
Davidroid 1:9f1974b0960d 322 motors[m]->PrepareHardStop();
Davidroid 0:5148e9486cf2 323
Davidroid 1:9f1974b0960d 324 /* Performing the action on each motor at the same time. */
Davidroid 1:9f1974b0960d 325 x_nucleo_ihm02a1->PerformPreparedActions();
Davidroid 0:5148e9486cf2 326
Davidroid 1:9f1974b0960d 327 /* Waiting. */
Davidroid 1:9f1974b0960d 328 wait_ms(DELAY_2);
Davidroid 0:5148e9486cf2 329
Davidroid 0:5148e9486cf2 330
Davidroid 1:9f1974b0960d 331 /*----- Doing a full revolution on each motor, one after the other. -----*/
Davidroid 1:9f1974b0960d 332
Davidroid 1:9f1974b0960d 333 /* Printing to the console. */
Davidroid 1:9f1974b0960d 334 printf("--> Doing a full revolution on each motor, one after the other.\r\n");
Davidroid 1:9f1974b0960d 335
Davidroid 1:9f1974b0960d 336 /* Doing a full revolution on each motor, one after the other. */
Davidroid 1:9f1974b0960d 337 for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
Davidroid 1:9f1974b0960d 338 for (int i = 0; i < MPR_1; i++)
Davidroid 1:9f1974b0960d 339 {
Davidroid 1:9f1974b0960d 340 /* Computing the number of steps. */
Davidroid 9:f35fbeedb8f4 341 int steps = (int) (((int) init[m].fullstepsperrevolution * pow(2.0f, init[m].step_sel)) / MPR_1);
Davidroid 1:9f1974b0960d 342
Davidroid 1:9f1974b0960d 343 /* Moving. */
Davidroid 1:9f1974b0960d 344 motors[m]->Move(StepperMotor::FWD, steps);
Davidroid 1:9f1974b0960d 345
Davidroid 1:9f1974b0960d 346 /* Waiting while active. */
Davidroid 1:9f1974b0960d 347 motors[m]->WaitWhileActive();
Davidroid 1:9f1974b0960d 348
Davidroid 1:9f1974b0960d 349 /* Waiting. */
Davidroid 1:9f1974b0960d 350 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 351 }
Davidroid 1:9f1974b0960d 352
Davidroid 1:9f1974b0960d 353 /* Waiting. */
Davidroid 1:9f1974b0960d 354 wait_ms(DELAY_2);
Davidroid 1:9f1974b0960d 355
Davidroid 1:9f1974b0960d 356
Davidroid 1:9f1974b0960d 357 /*----- High Impedance State. -----*/
Davidroid 1:9f1974b0960d 358
Davidroid 1:9f1974b0960d 359 /* Printing to the console. */
Davidroid 1:9f1974b0960d 360 printf("--> High Impedance State.\r\n");
Davidroid 1:9f1974b0960d 361
Davidroid 1:9f1974b0960d 362 /* Preparing each motor to set High Impedance State. */
Davidroid 1:9f1974b0960d 363 for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
Davidroid 1:9f1974b0960d 364 motors[m]->PrepareHardHiZ();
Davidroid 1:9f1974b0960d 365
Davidroid 1:9f1974b0960d 366 /* Performing the action on each motor at the same time. */
Davidroid 1:9f1974b0960d 367 x_nucleo_ihm02a1->PerformPreparedActions();
Davidroid 1:9f1974b0960d 368
Davidroid 1:9f1974b0960d 369 /* Waiting. */
Davidroid 1:9f1974b0960d 370 wait_ms(DELAY_2);
Davidroid 0:5148e9486cf2 371 }