Simple code to run steps

Dependencies:   X-NUCLEO-IHM05A1 mbed

Fork of HelloWorld_IHM05A1 by ST

Committer:
nucleosam
Date:
Fri Apr 29 14:59:26 2016 +0000
Revision:
2:c5f455885df7
Parent:
0:36aa6787d4f9
Child:
3:a6e155687c6a
Removed inclusion of ?DevSPI.h?; Fixed comments.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucleosam 0:36aa6787d4f9 1 /**
nucleosam 0:36aa6787d4f9 2 ******************************************************************************
nucleosam 0:36aa6787d4f9 3 * @file main.cpp
nucleosam 0:36aa6787d4f9 4 * @author IPC Rennes
nucleosam 0:36aa6787d4f9 5 * @version V1.0.0
nucleosam 0:36aa6787d4f9 6 * @date April 13th, 2016
nucleosam 2:c5f455885df7 7 * @brief mbed simple application for the STMicroelectronics X-NUCLEO-IHM05A1
nucleosam 0:36aa6787d4f9 8 * Motor Control Expansion Board: control of 1 motor.
nucleosam 0:36aa6787d4f9 9 ******************************************************************************
nucleosam 0:36aa6787d4f9 10 * @attention
nucleosam 0:36aa6787d4f9 11 *
nucleosam 0:36aa6787d4f9 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nucleosam 0:36aa6787d4f9 13 *
nucleosam 0:36aa6787d4f9 14 * Redistribution and use in source and binary forms, with or without modification,
nucleosam 0:36aa6787d4f9 15 * are permitted provided that the following conditions are met:
nucleosam 0:36aa6787d4f9 16 * 1. Redistributions of source code must retain the above copyright notice,
nucleosam 0:36aa6787d4f9 17 * this list of conditions and the following disclaimer.
nucleosam 0:36aa6787d4f9 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nucleosam 0:36aa6787d4f9 19 * this list of conditions and the following disclaimer in the documentation
nucleosam 0:36aa6787d4f9 20 * and/or other materials provided with the distribution.
nucleosam 0:36aa6787d4f9 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nucleosam 0:36aa6787d4f9 22 * may be used to endorse or promote products derived from this software
nucleosam 0:36aa6787d4f9 23 * without specific prior written permission.
nucleosam 0:36aa6787d4f9 24 *
nucleosam 0:36aa6787d4f9 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nucleosam 0:36aa6787d4f9 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nucleosam 0:36aa6787d4f9 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nucleosam 0:36aa6787d4f9 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nucleosam 0:36aa6787d4f9 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nucleosam 0:36aa6787d4f9 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nucleosam 0:36aa6787d4f9 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nucleosam 0:36aa6787d4f9 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nucleosam 0:36aa6787d4f9 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nucleosam 0:36aa6787d4f9 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nucleosam 0:36aa6787d4f9 35 *
nucleosam 0:36aa6787d4f9 36 ******************************************************************************
nucleosam 0:36aa6787d4f9 37 */
nucleosam 0:36aa6787d4f9 38
nucleosam 0:36aa6787d4f9 39 /* Includes ------------------------------------------------------------------*/
nucleosam 0:36aa6787d4f9 40
nucleosam 0:36aa6787d4f9 41 /* mbed specific header files. */
nucleosam 0:36aa6787d4f9 42 #include "mbed.h"
nucleosam 0:36aa6787d4f9 43
nucleosam 0:36aa6787d4f9 44 /* Component specific header files. */
nucleosam 0:36aa6787d4f9 45 #include "l6208_class.h"
nucleosam 0:36aa6787d4f9 46
nucleosam 0:36aa6787d4f9 47
nucleosam 0:36aa6787d4f9 48 /* Definitions ---------------------------------------------------------------*/
nucleosam 0:36aa6787d4f9 49 #ifdef TARGET_NUCLEO_F334R8
nucleosam 0:36aa6787d4f9 50 #define VREFA_PWM_PIN D11
nucleosam 0:36aa6787d4f9 51 #else
nucleosam 0:36aa6787d4f9 52 #define VREFA_PWM_PIN D3
nucleosam 0:36aa6787d4f9 53 #endif
nucleosam 0:36aa6787d4f9 54
nucleosam 0:36aa6787d4f9 55 /* Variables -----------------------------------------------------------------*/
nucleosam 0:36aa6787d4f9 56
nucleosam 0:36aa6787d4f9 57 /* Initialization parameters of the motor connected to the expansion board. */
nucleosam 0:36aa6787d4f9 58 l6208_Init_t initDeviceParameters =
nucleosam 0:36aa6787d4f9 59 {
nucleosam 0:36aa6787d4f9 60 1500, //Acceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
nucleosam 0:36aa6787d4f9 61 40, //Acceleration current torque in % (from 0 to 100)
nucleosam 0:36aa6787d4f9 62 1500, //Deceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
nucleosam 0:36aa6787d4f9 63 30, //Deceleration current torque in % (from 0 to 100)
nucleosam 0:36aa6787d4f9 64 1500, //Running speed in step/s or (1/16)th step/s for microstep modes
nucleosam 0:36aa6787d4f9 65 50, //Running current torque in % (from 0 to 100)
nucleosam 0:36aa6787d4f9 66 20, //Holding current torque in % (from 0 to 100)
nucleosam 0:36aa6787d4f9 67 STEP_MODE_1_16, //Step mode via enum motorStepMode_t
nucleosam 0:36aa6787d4f9 68 FAST_DECAY, //Decay mode via enum motorDecayMode_t
nucleosam 0:36aa6787d4f9 69 0, //Dwelling time in ms
nucleosam 0:36aa6787d4f9 70 FALSE, //Automatic HIZ STOP
nucleosam 0:36aa6787d4f9 71 100000 //VREFA and VREFB PWM frequency (Hz)
nucleosam 0:36aa6787d4f9 72 };
nucleosam 0:36aa6787d4f9 73
nucleosam 0:36aa6787d4f9 74 /* Motor Control Component. */
nucleosam 0:36aa6787d4f9 75 L6208 *motor;
nucleosam 0:36aa6787d4f9 76
nucleosam 0:36aa6787d4f9 77 /* Functions -----------------------------------------------------------------*/
nucleosam 0:36aa6787d4f9 78
nucleosam 0:36aa6787d4f9 79 /**
nucleosam 0:36aa6787d4f9 80 * @brief This is an example of user handler for the flag interrupt.
nucleosam 0:36aa6787d4f9 81 * @param None
nucleosam 0:36aa6787d4f9 82 * @retval None
nucleosam 0:36aa6787d4f9 83 * @note If needed, implement it, and then attach and enable it:
nucleosam 0:36aa6787d4f9 84 * + motor->AttachFlagIRQ(&myFlagIRQHandler);
nucleosam 0:36aa6787d4f9 85 * + motor->EnableFlagIRQ();
nucleosam 0:36aa6787d4f9 86 * To disable it:
nucleosam 0:36aa6787d4f9 87 * + motor->DisbleFlagIRQ();
nucleosam 0:36aa6787d4f9 88 */
nucleosam 0:36aa6787d4f9 89 void myFlagIRQHandler(void)
nucleosam 0:36aa6787d4f9 90 {
nucleosam 0:36aa6787d4f9 91 printf(" WARNING: \"FLAG\" interrupt triggered:\r\n");
nucleosam 0:36aa6787d4f9 92 motor->Disable();
nucleosam 0:36aa6787d4f9 93 printf(" Motor disabled.\r\n\n");
nucleosam 0:36aa6787d4f9 94 }
nucleosam 0:36aa6787d4f9 95
nucleosam 0:36aa6787d4f9 96 /**
nucleosam 0:36aa6787d4f9 97 * @brief This is an example of error handler.
nucleosam 0:36aa6787d4f9 98 * @param[in] error Number of the error
nucleosam 0:36aa6787d4f9 99 * @retval None
nucleosam 0:36aa6787d4f9 100 * @note If needed, implement it, and then attach it:
nucleosam 0:36aa6787d4f9 101 * + motor->AttachErrorHandler(&myErrorHandler);
nucleosam 0:36aa6787d4f9 102 */
nucleosam 0:36aa6787d4f9 103 void myErrorHandler(uint16_t error)
nucleosam 0:36aa6787d4f9 104 {
nucleosam 0:36aa6787d4f9 105 /* Printing to the console. */
nucleosam 0:36aa6787d4f9 106 printf("Error %d detected\r\n\n", error);
nucleosam 0:36aa6787d4f9 107
nucleosam 0:36aa6787d4f9 108 /* Infinite loop */
nucleosam 0:36aa6787d4f9 109 while(1)
nucleosam 0:36aa6787d4f9 110 {
nucleosam 0:36aa6787d4f9 111 }
nucleosam 0:36aa6787d4f9 112 }
nucleosam 0:36aa6787d4f9 113
nucleosam 0:36aa6787d4f9 114 /* Main ----------------------------------------------------------------------*/
nucleosam 0:36aa6787d4f9 115
nucleosam 0:36aa6787d4f9 116 int main()
nucleosam 0:36aa6787d4f9 117 {
nucleosam 0:36aa6787d4f9 118 /* Printing to the console. */
nucleosam 0:36aa6787d4f9 119 printf("STARTING MAIN PROGRAM\r\n");
nucleosam 0:36aa6787d4f9 120 printf(" Reminder:\r\n");
nucleosam 0:36aa6787d4f9 121 printf(" The position unit is in agreement to the step mode.\r\n");
nucleosam 0:36aa6787d4f9 122 printf(" The speed, acceleration or deceleration unit depend on the step mode:\r\n");
nucleosam 0:36aa6787d4f9 123 printf(" - For normal mode and half step mode, the unit is steps/s or /s^2.\r\n");
nucleosam 0:36aa6787d4f9 124 printf(" - For microstep modes, the unit is (1/16)steps/s or /s^2.\r\n");
nucleosam 0:36aa6787d4f9 125
nucleosam 0:36aa6787d4f9 126 //----- Initialization
nucleosam 0:36aa6787d4f9 127 /* Initializing Motor Control Component. */
nucleosam 0:36aa6787d4f9 128 motor = new L6208(D2, D8, D7, D4, D5, D6, VREFA_PWM_PIN, D9);
nucleosam 0:36aa6787d4f9 129 if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE);
nucleosam 0:36aa6787d4f9 130
nucleosam 0:36aa6787d4f9 131 /* Attaching and enabling an interrupt handler. */
nucleosam 0:36aa6787d4f9 132 motor->AttachFlagIRQ(&myFlagIRQHandler);
nucleosam 0:36aa6787d4f9 133 motor->EnableFlagIRQ();
nucleosam 0:36aa6787d4f9 134
nucleosam 0:36aa6787d4f9 135 /* Attaching an error handler */
nucleosam 0:36aa6787d4f9 136 motor->AttachErrorHandler(&myErrorHandler);
nucleosam 0:36aa6787d4f9 137
nucleosam 0:36aa6787d4f9 138 /* Printing to the console. */
nucleosam 0:36aa6787d4f9 139 printf("Motor Control Application Example for 1 Motor\r\n");
nucleosam 0:36aa6787d4f9 140
nucleosam 0:36aa6787d4f9 141 //----- Run the motor BACKWARD
nucleosam 0:36aa6787d4f9 142 printf("--> Running the motor backward.\r\n");
nucleosam 0:36aa6787d4f9 143 motor->Run(StepperMotor::BWD);
nucleosam 0:36aa6787d4f9 144
nucleosam 0:36aa6787d4f9 145 while (motor->GetStatus()!=STEADY)
nucleosam 0:36aa6787d4f9 146 {
nucleosam 0:36aa6787d4f9 147 /* Print reached speed to the console in step/s or microsteps/s */
nucleosam 2:c5f455885df7 148 printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed());
nucleosam 2:c5f455885df7 149 wait_ms(50);
nucleosam 0:36aa6787d4f9 150 }
nucleosam 2:c5f455885df7 151 printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed());
nucleosam 0:36aa6787d4f9 152
nucleosam 0:36aa6787d4f9 153 /* Wait for 1 second */
nucleosam 0:36aa6787d4f9 154 wait_ms(1000);
nucleosam 0:36aa6787d4f9 155
nucleosam 0:36aa6787d4f9 156 //----- Decrease speed while running to one quarter of the previous speed
nucleosam 0:36aa6787d4f9 157 motor->SetMaxSpeed(motor->GetSpeed()>>2);
nucleosam 0:36aa6787d4f9 158
nucleosam 0:36aa6787d4f9 159 /* Wait until the motor starts decelerating */
nucleosam 0:36aa6787d4f9 160 while (motor->GetStatus()==STEADY);
nucleosam 0:36aa6787d4f9 161 /* Wait and print speed while the motor is not steady running */
nucleosam 0:36aa6787d4f9 162 while (motor->GetStatus()!=STEADY)
nucleosam 0:36aa6787d4f9 163 {
nucleosam 0:36aa6787d4f9 164 /* Print reached speed to the console in step/s or microsteps/s */
nucleosam 2:c5f455885df7 165 printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed());
nucleosam 2:c5f455885df7 166 wait_ms(50);
nucleosam 0:36aa6787d4f9 167 }
nucleosam 2:c5f455885df7 168 printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed());
nucleosam 0:36aa6787d4f9 169
nucleosam 0:36aa6787d4f9 170 /* Wait for 5 seconds */
nucleosam 0:36aa6787d4f9 171 wait_ms(5000);
nucleosam 0:36aa6787d4f9 172
nucleosam 0:36aa6787d4f9 173 //----- Soft stop required while running
nucleosam 0:36aa6787d4f9 174 printf("--> Soft stop requested.\r\n");
nucleosam 0:36aa6787d4f9 175 motor->SoftStop();
nucleosam 0:36aa6787d4f9 176
nucleosam 0:36aa6787d4f9 177 /* Wait for the motor of device ends moving */
nucleosam 0:36aa6787d4f9 178 motor->WaitWhileActive();
nucleosam 0:36aa6787d4f9 179
nucleosam 0:36aa6787d4f9 180 /* Wait for 2 seconds */
nucleosam 0:36aa6787d4f9 181 wait_ms(2000);
nucleosam 0:36aa6787d4f9 182
nucleosam 0:36aa6787d4f9 183 //----- Change step mode to full step mode
nucleosam 0:36aa6787d4f9 184 motor->SetStepMode(StepperMotor::STEP_MODE_FULL);
nucleosam 0:36aa6787d4f9 185 printf(" Motor step mode: %d (0:FS, 1:1/2, 2:1/4, 3:1/8, 4:1/16).\r\n", motor->GetStepMode());
nucleosam 0:36aa6787d4f9 186
nucleosam 0:36aa6787d4f9 187 /* Get current position of device and print to the console */
nucleosam 0:36aa6787d4f9 188 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:36aa6787d4f9 189
nucleosam 0:36aa6787d4f9 190 /* Set speed, acceleration and deceleration to scale with normal mode */
nucleosam 0:36aa6787d4f9 191 motor->SetMaxSpeed(initDeviceParameters.maxSpeedSps>>4);
nucleosam 0:36aa6787d4f9 192 motor->SetAcceleration(motor->GetAcceleration()>>4);
nucleosam 0:36aa6787d4f9 193 motor->SetDeceleration(motor->GetDeceleration()>>4);
nucleosam 0:36aa6787d4f9 194 /* Print parameters to the console */
nucleosam 0:36aa6787d4f9 195 printf(" Motor Max Speed: %d step/s.\r\n", motor->GetMaxSpeed());
nucleosam 0:36aa6787d4f9 196 printf(" Motor Min Speed: %d step/s.\r\n", motor->GetMinSpeed());
nucleosam 0:36aa6787d4f9 197 printf(" Motor Acceleration: %d step/s.\r\n", motor->GetAcceleration());
nucleosam 0:36aa6787d4f9 198 printf(" Motor Deceleration: %d step/s.\r\n", motor->GetDeceleration());
nucleosam 0:36aa6787d4f9 199
nucleosam 0:36aa6787d4f9 200 //----- Move of 200 steps in the FW direction
nucleosam 0:36aa6787d4f9 201 printf("--> Moving forward 200 steps.\r\n");
nucleosam 0:36aa6787d4f9 202 motor->Move(StepperMotor::FWD, 200);
nucleosam 0:36aa6787d4f9 203
nucleosam 0:36aa6787d4f9 204 /* Waiting while the motor is active. */
nucleosam 0:36aa6787d4f9 205 motor->WaitWhileActive();
nucleosam 0:36aa6787d4f9 206
nucleosam 0:36aa6787d4f9 207 /* Get current position of device and print to the console */
nucleosam 0:36aa6787d4f9 208 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:36aa6787d4f9 209
nucleosam 0:36aa6787d4f9 210 /* Disable the power bridges */
nucleosam 0:36aa6787d4f9 211 motor->Disable();
nucleosam 0:36aa6787d4f9 212
nucleosam 0:36aa6787d4f9 213 /* Check that the power bridges are actually disabled */
nucleosam 0:36aa6787d4f9 214 if (motor->CheckStatusHw()!=0) printf(" Motor driver disabled.\r\n");
nucleosam 0:36aa6787d4f9 215 else printf(" Failed to disable the motor driver.\r\n");
nucleosam 0:36aa6787d4f9 216
nucleosam 0:36aa6787d4f9 217 /* Wait for 2 seconds */
nucleosam 0:36aa6787d4f9 218 wait_ms(2000);
nucleosam 0:36aa6787d4f9 219
nucleosam 0:36aa6787d4f9 220 //----- Change step mode to 1/4 microstepping mode
nucleosam 0:36aa6787d4f9 221 motor->SetStepMode(StepperMotor::STEP_MODE_1_4);
nucleosam 0:36aa6787d4f9 222 printf(" Motor step mode: %d (0:FS, 1:1/2, 2:1/4, 3:1/8, 4:1/16).\r\n", motor->GetStepMode());
nucleosam 0:36aa6787d4f9 223
nucleosam 0:36aa6787d4f9 224 /* Get current position of device and print to the console */
nucleosam 0:36aa6787d4f9 225 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:36aa6787d4f9 226
nucleosam 0:36aa6787d4f9 227 /* Set speed, acceleration and deceleration to scale with microstep mode */
nucleosam 0:36aa6787d4f9 228 motor->SetMaxSpeed(motor->GetMaxSpeed()<<4);
nucleosam 0:36aa6787d4f9 229 motor->SetAcceleration(motor->GetAcceleration()<<4);
nucleosam 0:36aa6787d4f9 230 motor->SetDeceleration(motor->GetDeceleration()<<4);
nucleosam 0:36aa6787d4f9 231 /* Print parameters to the console */
nucleosam 0:36aa6787d4f9 232 printf(" Motor Max Speed: %d step/s.\r\n", motor->GetMaxSpeed());
nucleosam 0:36aa6787d4f9 233 printf(" Motor Min Speed: %d step/s.\r\n", motor->GetMinSpeed());
nucleosam 0:36aa6787d4f9 234 printf(" Motor Acceleration: %d step/s.\r\n", motor->GetAcceleration());
nucleosam 0:36aa6787d4f9 235 printf(" Motor Deceleration: %d step/s.\r\n", motor->GetDeceleration());
nucleosam 0:36aa6787d4f9 236
nucleosam 0:36aa6787d4f9 237 /* Request to go position 800 (quarter steps) */
nucleosam 0:36aa6787d4f9 238 motor->GoTo(800);
nucleosam 0:36aa6787d4f9 239
nucleosam 0:36aa6787d4f9 240 /* Wait for the motor ends moving */
nucleosam 0:36aa6787d4f9 241 motor->WaitWhileActive();
nucleosam 0:36aa6787d4f9 242
nucleosam 0:36aa6787d4f9 243 /* Get current position of device and print to the console */
nucleosam 0:36aa6787d4f9 244 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:36aa6787d4f9 245
nucleosam 0:36aa6787d4f9 246 /* Wait for 2 seconds */
nucleosam 0:36aa6787d4f9 247 wait_ms(2000);
nucleosam 0:36aa6787d4f9 248
nucleosam 0:36aa6787d4f9 249 //----- Restore step mode to its initialization value
nucleosam 0:36aa6787d4f9 250 motor->SetStepMode((StepperMotor::step_mode_t)initDeviceParameters.stepMode);
nucleosam 0:36aa6787d4f9 251 printf(" Motor step mode: %d (0:FS, 1:1/2, 2:1/4, 3:1/8, 4:1/16).\r\n", motor->GetStepMode());
nucleosam 0:36aa6787d4f9 252
nucleosam 0:36aa6787d4f9 253 /* Get current position of device and print to the console */
nucleosam 0:36aa6787d4f9 254 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:36aa6787d4f9 255
nucleosam 0:36aa6787d4f9 256 //----- Change decay mode
nucleosam 0:36aa6787d4f9 257 motor->SetDecayMode(SLOW_DECAY);
nucleosam 0:36aa6787d4f9 258 printf(" Motor decay mode: %d (0:slow decay, 1:fast decay).\r\n", motor->GetDecayMode());
nucleosam 0:36aa6787d4f9 259
nucleosam 0:36aa6787d4f9 260 //----- Go to position -6400
nucleosam 0:36aa6787d4f9 261 printf("--> Go to position -6400 steps.\r\n");
nucleosam 0:36aa6787d4f9 262 motor->GoTo(-6400);
nucleosam 0:36aa6787d4f9 263
nucleosam 0:36aa6787d4f9 264 /* Wait for the motor ends moving */
nucleosam 0:36aa6787d4f9 265 motor->WaitWhileActive();
nucleosam 0:36aa6787d4f9 266
nucleosam 0:36aa6787d4f9 267 /* Get current position of device and print to the console */
nucleosam 0:36aa6787d4f9 268 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:36aa6787d4f9 269
nucleosam 0:36aa6787d4f9 270 /* Wait for 2 seconds */
nucleosam 0:36aa6787d4f9 271 wait_ms(2000);
nucleosam 0:36aa6787d4f9 272
nucleosam 0:36aa6787d4f9 273 //----- Restore decay mode to its initialization value
nucleosam 0:36aa6787d4f9 274 motor->SetDecayMode(initDeviceParameters.decayMode);
nucleosam 0:36aa6787d4f9 275 printf(" Motor decay mode: %d (0:slow decay, 1:fast decay).\r\n", motor->GetDecayMode());
nucleosam 0:36aa6787d4f9 276
nucleosam 0:36aa6787d4f9 277 //----- Go Home
nucleosam 0:36aa6787d4f9 278 printf("--> Go to home position.\r\n");
nucleosam 0:36aa6787d4f9 279 motor->GoHome();
nucleosam 0:36aa6787d4f9 280
nucleosam 0:36aa6787d4f9 281 /* Wait for the motor ends moving */
nucleosam 0:36aa6787d4f9 282 motor->WaitWhileActive();
nucleosam 0:36aa6787d4f9 283
nucleosam 0:36aa6787d4f9 284 /* Wait for 1 second */
nucleosam 0:36aa6787d4f9 285 wait_ms(1000);
nucleosam 0:36aa6787d4f9 286
nucleosam 0:36aa6787d4f9 287 /* Infinite Loop. */
nucleosam 0:36aa6787d4f9 288 printf("--> Infinite Loop...\r\n");
nucleosam 0:36aa6787d4f9 289 while (1)
nucleosam 0:36aa6787d4f9 290 {
nucleosam 0:36aa6787d4f9 291 /* Request device to go position -3200 */
nucleosam 0:36aa6787d4f9 292 motor->GoTo(-3200);
nucleosam 0:36aa6787d4f9 293
nucleosam 0:36aa6787d4f9 294 /* Waiting while the motor is active. */
nucleosam 0:36aa6787d4f9 295 motor->WaitWhileActive();
nucleosam 0:36aa6787d4f9 296
nucleosam 0:36aa6787d4f9 297 /* Request device to go position 3200 */
nucleosam 0:36aa6787d4f9 298 motor->GoTo(3200);
nucleosam 0:36aa6787d4f9 299
nucleosam 0:36aa6787d4f9 300 /* Waiting while the motor is active. */
nucleosam 0:36aa6787d4f9 301 motor->WaitWhileActive();
nucleosam 0:36aa6787d4f9 302 }
nucleosam 0:36aa6787d4f9 303 }
nucleosam 0:36aa6787d4f9 304 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/