a version to test
Dependencies: X-NUCLEO-IHM05A1
main.cpp@3:a6e155687c6a, 2016-04-29 (annotated)
- Committer:
- nucleosam
- Date:
- Fri Apr 29 15:58:05 2016 +0000
- Revision:
- 3:a6e155687c6a
- Parent:
- 2:c5f455885df7
- Child:
- 5:bc710d77d801
Addition for compatibiltiy with NUCLEO-F302R8
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 | 3:a6e155687c6a | 51 | #define VREFB_PWM_PIN D9 |
nucleosam | 3:a6e155687c6a | 52 | #elif TARGET_NUCLEO_F302R8 |
nucleosam | 3:a6e155687c6a | 53 | #define VREFA_PWM_PIN D11 |
nucleosam | 3:a6e155687c6a | 54 | #define VREFB_PWM_PIN D15 /* HW mandatory patch: bridge manually D9 with D15 */ |
nucleosam | 0:36aa6787d4f9 | 55 | #else |
nucleosam | 0:36aa6787d4f9 | 56 | #define VREFA_PWM_PIN D3 |
nucleosam | 3:a6e155687c6a | 57 | #define VREFB_PWM_PIN D9 |
nucleosam | 0:36aa6787d4f9 | 58 | #endif |
nucleosam | 0:36aa6787d4f9 | 59 | |
nucleosam | 0:36aa6787d4f9 | 60 | /* Variables -----------------------------------------------------------------*/ |
nucleosam | 0:36aa6787d4f9 | 61 | |
nucleosam | 0:36aa6787d4f9 | 62 | /* Initialization parameters of the motor connected to the expansion board. */ |
nucleosam | 0:36aa6787d4f9 | 63 | l6208_Init_t initDeviceParameters = |
nucleosam | 0:36aa6787d4f9 | 64 | { |
nucleosam | 0:36aa6787d4f9 | 65 | 1500, //Acceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes |
nucleosam | 0:36aa6787d4f9 | 66 | 40, //Acceleration current torque in % (from 0 to 100) |
nucleosam | 0:36aa6787d4f9 | 67 | 1500, //Deceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes |
nucleosam | 0:36aa6787d4f9 | 68 | 30, //Deceleration current torque in % (from 0 to 100) |
nucleosam | 0:36aa6787d4f9 | 69 | 1500, //Running speed in step/s or (1/16)th step/s for microstep modes |
nucleosam | 0:36aa6787d4f9 | 70 | 50, //Running current torque in % (from 0 to 100) |
nucleosam | 0:36aa6787d4f9 | 71 | 20, //Holding current torque in % (from 0 to 100) |
nucleosam | 0:36aa6787d4f9 | 72 | STEP_MODE_1_16, //Step mode via enum motorStepMode_t |
nucleosam | 0:36aa6787d4f9 | 73 | FAST_DECAY, //Decay mode via enum motorDecayMode_t |
nucleosam | 0:36aa6787d4f9 | 74 | 0, //Dwelling time in ms |
nucleosam | 0:36aa6787d4f9 | 75 | FALSE, //Automatic HIZ STOP |
nucleosam | 0:36aa6787d4f9 | 76 | 100000 //VREFA and VREFB PWM frequency (Hz) |
nucleosam | 0:36aa6787d4f9 | 77 | }; |
nucleosam | 0:36aa6787d4f9 | 78 | |
nucleosam | 0:36aa6787d4f9 | 79 | /* Motor Control Component. */ |
nucleosam | 0:36aa6787d4f9 | 80 | L6208 *motor; |
nucleosam | 0:36aa6787d4f9 | 81 | |
nucleosam | 0:36aa6787d4f9 | 82 | /* Functions -----------------------------------------------------------------*/ |
nucleosam | 0:36aa6787d4f9 | 83 | |
nucleosam | 0:36aa6787d4f9 | 84 | /** |
nucleosam | 0:36aa6787d4f9 | 85 | * @brief This is an example of user handler for the flag interrupt. |
nucleosam | 0:36aa6787d4f9 | 86 | * @param None |
nucleosam | 0:36aa6787d4f9 | 87 | * @retval None |
nucleosam | 0:36aa6787d4f9 | 88 | * @note If needed, implement it, and then attach and enable it: |
nucleosam | 0:36aa6787d4f9 | 89 | * + motor->AttachFlagIRQ(&myFlagIRQHandler); |
nucleosam | 0:36aa6787d4f9 | 90 | * + motor->EnableFlagIRQ(); |
nucleosam | 0:36aa6787d4f9 | 91 | * To disable it: |
nucleosam | 0:36aa6787d4f9 | 92 | * + motor->DisbleFlagIRQ(); |
nucleosam | 0:36aa6787d4f9 | 93 | */ |
nucleosam | 0:36aa6787d4f9 | 94 | void myFlagIRQHandler(void) |
nucleosam | 0:36aa6787d4f9 | 95 | { |
nucleosam | 0:36aa6787d4f9 | 96 | printf(" WARNING: \"FLAG\" interrupt triggered:\r\n"); |
nucleosam | 0:36aa6787d4f9 | 97 | motor->Disable(); |
nucleosam | 0:36aa6787d4f9 | 98 | printf(" Motor disabled.\r\n\n"); |
nucleosam | 0:36aa6787d4f9 | 99 | } |
nucleosam | 0:36aa6787d4f9 | 100 | |
nucleosam | 0:36aa6787d4f9 | 101 | /** |
nucleosam | 0:36aa6787d4f9 | 102 | * @brief This is an example of error handler. |
nucleosam | 0:36aa6787d4f9 | 103 | * @param[in] error Number of the error |
nucleosam | 0:36aa6787d4f9 | 104 | * @retval None |
nucleosam | 0:36aa6787d4f9 | 105 | * @note If needed, implement it, and then attach it: |
nucleosam | 0:36aa6787d4f9 | 106 | * + motor->AttachErrorHandler(&myErrorHandler); |
nucleosam | 0:36aa6787d4f9 | 107 | */ |
nucleosam | 0:36aa6787d4f9 | 108 | void myErrorHandler(uint16_t error) |
nucleosam | 0:36aa6787d4f9 | 109 | { |
nucleosam | 0:36aa6787d4f9 | 110 | /* Printing to the console. */ |
nucleosam | 0:36aa6787d4f9 | 111 | printf("Error %d detected\r\n\n", error); |
nucleosam | 0:36aa6787d4f9 | 112 | |
nucleosam | 0:36aa6787d4f9 | 113 | /* Infinite loop */ |
nucleosam | 0:36aa6787d4f9 | 114 | while(1) |
nucleosam | 0:36aa6787d4f9 | 115 | { |
nucleosam | 0:36aa6787d4f9 | 116 | } |
nucleosam | 0:36aa6787d4f9 | 117 | } |
nucleosam | 0:36aa6787d4f9 | 118 | |
nucleosam | 0:36aa6787d4f9 | 119 | /* Main ----------------------------------------------------------------------*/ |
nucleosam | 0:36aa6787d4f9 | 120 | |
nucleosam | 0:36aa6787d4f9 | 121 | int main() |
nucleosam | 0:36aa6787d4f9 | 122 | { |
nucleosam | 0:36aa6787d4f9 | 123 | /* Printing to the console. */ |
nucleosam | 0:36aa6787d4f9 | 124 | printf("STARTING MAIN PROGRAM\r\n"); |
nucleosam | 0:36aa6787d4f9 | 125 | printf(" Reminder:\r\n"); |
nucleosam | 0:36aa6787d4f9 | 126 | printf(" The position unit is in agreement to the step mode.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 127 | printf(" The speed, acceleration or deceleration unit depend on the step mode:\r\n"); |
nucleosam | 0:36aa6787d4f9 | 128 | printf(" - For normal mode and half step mode, the unit is steps/s or /s^2.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 129 | printf(" - For microstep modes, the unit is (1/16)steps/s or /s^2.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 130 | |
nucleosam | 0:36aa6787d4f9 | 131 | //----- Initialization |
nucleosam | 0:36aa6787d4f9 | 132 | /* Initializing Motor Control Component. */ |
nucleosam | 3:a6e155687c6a | 133 | motor = new L6208(D2, D8, D7, D4, D5, D6, VREFA_PWM_PIN, VREFB_PWM_PIN); |
nucleosam | 0:36aa6787d4f9 | 134 | if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE); |
nucleosam | 0:36aa6787d4f9 | 135 | |
nucleosam | 0:36aa6787d4f9 | 136 | /* Attaching and enabling an interrupt handler. */ |
nucleosam | 0:36aa6787d4f9 | 137 | motor->AttachFlagIRQ(&myFlagIRQHandler); |
nucleosam | 0:36aa6787d4f9 | 138 | motor->EnableFlagIRQ(); |
nucleosam | 0:36aa6787d4f9 | 139 | |
nucleosam | 0:36aa6787d4f9 | 140 | /* Attaching an error handler */ |
nucleosam | 0:36aa6787d4f9 | 141 | motor->AttachErrorHandler(&myErrorHandler); |
nucleosam | 0:36aa6787d4f9 | 142 | |
nucleosam | 0:36aa6787d4f9 | 143 | /* Printing to the console. */ |
nucleosam | 0:36aa6787d4f9 | 144 | printf("Motor Control Application Example for 1 Motor\r\n"); |
nucleosam | 0:36aa6787d4f9 | 145 | |
nucleosam | 0:36aa6787d4f9 | 146 | //----- Run the motor BACKWARD |
nucleosam | 0:36aa6787d4f9 | 147 | printf("--> Running the motor backward.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 148 | motor->Run(StepperMotor::BWD); |
nucleosam | 0:36aa6787d4f9 | 149 | |
nucleosam | 0:36aa6787d4f9 | 150 | while (motor->GetStatus()!=STEADY) |
nucleosam | 0:36aa6787d4f9 | 151 | { |
nucleosam | 0:36aa6787d4f9 | 152 | /* Print reached speed to the console in step/s or microsteps/s */ |
nucleosam | 2:c5f455885df7 | 153 | printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed()); |
nucleosam | 2:c5f455885df7 | 154 | wait_ms(50); |
nucleosam | 0:36aa6787d4f9 | 155 | } |
nucleosam | 2:c5f455885df7 | 156 | printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed()); |
nucleosam | 0:36aa6787d4f9 | 157 | |
nucleosam | 0:36aa6787d4f9 | 158 | /* Wait for 1 second */ |
nucleosam | 0:36aa6787d4f9 | 159 | wait_ms(1000); |
nucleosam | 0:36aa6787d4f9 | 160 | |
nucleosam | 0:36aa6787d4f9 | 161 | //----- Decrease speed while running to one quarter of the previous speed |
nucleosam | 0:36aa6787d4f9 | 162 | motor->SetMaxSpeed(motor->GetSpeed()>>2); |
nucleosam | 0:36aa6787d4f9 | 163 | |
nucleosam | 0:36aa6787d4f9 | 164 | /* Wait until the motor starts decelerating */ |
nucleosam | 0:36aa6787d4f9 | 165 | while (motor->GetStatus()==STEADY); |
nucleosam | 0:36aa6787d4f9 | 166 | /* Wait and print speed while the motor is not steady running */ |
nucleosam | 0:36aa6787d4f9 | 167 | while (motor->GetStatus()!=STEADY) |
nucleosam | 0:36aa6787d4f9 | 168 | { |
nucleosam | 0:36aa6787d4f9 | 169 | /* Print reached speed to the console in step/s or microsteps/s */ |
nucleosam | 2:c5f455885df7 | 170 | printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed()); |
nucleosam | 2:c5f455885df7 | 171 | wait_ms(50); |
nucleosam | 0:36aa6787d4f9 | 172 | } |
nucleosam | 2:c5f455885df7 | 173 | printf(" Reached Speed: %d microstep/s.\r\n", motor->GetSpeed()); |
nucleosam | 0:36aa6787d4f9 | 174 | |
nucleosam | 0:36aa6787d4f9 | 175 | /* Wait for 5 seconds */ |
nucleosam | 0:36aa6787d4f9 | 176 | wait_ms(5000); |
nucleosam | 0:36aa6787d4f9 | 177 | |
nucleosam | 0:36aa6787d4f9 | 178 | //----- Soft stop required while running |
nucleosam | 0:36aa6787d4f9 | 179 | printf("--> Soft stop requested.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 180 | motor->SoftStop(); |
nucleosam | 0:36aa6787d4f9 | 181 | |
nucleosam | 0:36aa6787d4f9 | 182 | /* Wait for the motor of device ends moving */ |
nucleosam | 0:36aa6787d4f9 | 183 | motor->WaitWhileActive(); |
nucleosam | 0:36aa6787d4f9 | 184 | |
nucleosam | 0:36aa6787d4f9 | 185 | /* Wait for 2 seconds */ |
nucleosam | 0:36aa6787d4f9 | 186 | wait_ms(2000); |
nucleosam | 0:36aa6787d4f9 | 187 | |
nucleosam | 0:36aa6787d4f9 | 188 | //----- Change step mode to full step mode |
nucleosam | 0:36aa6787d4f9 | 189 | motor->SetStepMode(StepperMotor::STEP_MODE_FULL); |
nucleosam | 0:36aa6787d4f9 | 190 | 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 | 191 | |
nucleosam | 0:36aa6787d4f9 | 192 | /* Get current position of device and print to the console */ |
nucleosam | 0:36aa6787d4f9 | 193 | printf(" Position: %d.\r\n", motor->GetPosition()); |
nucleosam | 0:36aa6787d4f9 | 194 | |
nucleosam | 0:36aa6787d4f9 | 195 | /* Set speed, acceleration and deceleration to scale with normal mode */ |
nucleosam | 0:36aa6787d4f9 | 196 | motor->SetMaxSpeed(initDeviceParameters.maxSpeedSps>>4); |
nucleosam | 0:36aa6787d4f9 | 197 | motor->SetAcceleration(motor->GetAcceleration()>>4); |
nucleosam | 0:36aa6787d4f9 | 198 | motor->SetDeceleration(motor->GetDeceleration()>>4); |
nucleosam | 0:36aa6787d4f9 | 199 | /* Print parameters to the console */ |
nucleosam | 0:36aa6787d4f9 | 200 | printf(" Motor Max Speed: %d step/s.\r\n", motor->GetMaxSpeed()); |
nucleosam | 0:36aa6787d4f9 | 201 | printf(" Motor Min Speed: %d step/s.\r\n", motor->GetMinSpeed()); |
nucleosam | 0:36aa6787d4f9 | 202 | printf(" Motor Acceleration: %d step/s.\r\n", motor->GetAcceleration()); |
nucleosam | 0:36aa6787d4f9 | 203 | printf(" Motor Deceleration: %d step/s.\r\n", motor->GetDeceleration()); |
nucleosam | 0:36aa6787d4f9 | 204 | |
nucleosam | 0:36aa6787d4f9 | 205 | //----- Move of 200 steps in the FW direction |
nucleosam | 0:36aa6787d4f9 | 206 | printf("--> Moving forward 200 steps.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 207 | motor->Move(StepperMotor::FWD, 200); |
nucleosam | 0:36aa6787d4f9 | 208 | |
nucleosam | 0:36aa6787d4f9 | 209 | /* Waiting while the motor is active. */ |
nucleosam | 0:36aa6787d4f9 | 210 | motor->WaitWhileActive(); |
nucleosam | 0:36aa6787d4f9 | 211 | |
nucleosam | 0:36aa6787d4f9 | 212 | /* Get current position of device and print to the console */ |
nucleosam | 0:36aa6787d4f9 | 213 | printf(" Position: %d.\r\n", motor->GetPosition()); |
nucleosam | 0:36aa6787d4f9 | 214 | |
nucleosam | 0:36aa6787d4f9 | 215 | /* Disable the power bridges */ |
nucleosam | 0:36aa6787d4f9 | 216 | motor->Disable(); |
nucleosam | 0:36aa6787d4f9 | 217 | |
nucleosam | 0:36aa6787d4f9 | 218 | /* Check that the power bridges are actually disabled */ |
nucleosam | 0:36aa6787d4f9 | 219 | if (motor->CheckStatusHw()!=0) printf(" Motor driver disabled.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 220 | else printf(" Failed to disable the motor driver.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 221 | |
nucleosam | 0:36aa6787d4f9 | 222 | /* Wait for 2 seconds */ |
nucleosam | 0:36aa6787d4f9 | 223 | wait_ms(2000); |
nucleosam | 0:36aa6787d4f9 | 224 | |
nucleosam | 0:36aa6787d4f9 | 225 | //----- Change step mode to 1/4 microstepping mode |
nucleosam | 0:36aa6787d4f9 | 226 | motor->SetStepMode(StepperMotor::STEP_MODE_1_4); |
nucleosam | 0:36aa6787d4f9 | 227 | 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 | 228 | |
nucleosam | 0:36aa6787d4f9 | 229 | /* Get current position of device and print to the console */ |
nucleosam | 0:36aa6787d4f9 | 230 | printf(" Position: %d.\r\n", motor->GetPosition()); |
nucleosam | 0:36aa6787d4f9 | 231 | |
nucleosam | 0:36aa6787d4f9 | 232 | /* Set speed, acceleration and deceleration to scale with microstep mode */ |
nucleosam | 0:36aa6787d4f9 | 233 | motor->SetMaxSpeed(motor->GetMaxSpeed()<<4); |
nucleosam | 0:36aa6787d4f9 | 234 | motor->SetAcceleration(motor->GetAcceleration()<<4); |
nucleosam | 0:36aa6787d4f9 | 235 | motor->SetDeceleration(motor->GetDeceleration()<<4); |
nucleosam | 0:36aa6787d4f9 | 236 | /* Print parameters to the console */ |
nucleosam | 0:36aa6787d4f9 | 237 | printf(" Motor Max Speed: %d step/s.\r\n", motor->GetMaxSpeed()); |
nucleosam | 0:36aa6787d4f9 | 238 | printf(" Motor Min Speed: %d step/s.\r\n", motor->GetMinSpeed()); |
nucleosam | 0:36aa6787d4f9 | 239 | printf(" Motor Acceleration: %d step/s.\r\n", motor->GetAcceleration()); |
nucleosam | 0:36aa6787d4f9 | 240 | printf(" Motor Deceleration: %d step/s.\r\n", motor->GetDeceleration()); |
nucleosam | 0:36aa6787d4f9 | 241 | |
nucleosam | 0:36aa6787d4f9 | 242 | /* Request to go position 800 (quarter steps) */ |
nucleosam | 0:36aa6787d4f9 | 243 | motor->GoTo(800); |
nucleosam | 0:36aa6787d4f9 | 244 | |
nucleosam | 0:36aa6787d4f9 | 245 | /* Wait for the motor ends moving */ |
nucleosam | 0:36aa6787d4f9 | 246 | motor->WaitWhileActive(); |
nucleosam | 0:36aa6787d4f9 | 247 | |
nucleosam | 0:36aa6787d4f9 | 248 | /* Get current position of device and print to the console */ |
nucleosam | 0:36aa6787d4f9 | 249 | printf(" Position: %d.\r\n", motor->GetPosition()); |
nucleosam | 0:36aa6787d4f9 | 250 | |
nucleosam | 0:36aa6787d4f9 | 251 | /* Wait for 2 seconds */ |
nucleosam | 0:36aa6787d4f9 | 252 | wait_ms(2000); |
nucleosam | 0:36aa6787d4f9 | 253 | |
nucleosam | 0:36aa6787d4f9 | 254 | //----- Restore step mode to its initialization value |
nucleosam | 0:36aa6787d4f9 | 255 | motor->SetStepMode((StepperMotor::step_mode_t)initDeviceParameters.stepMode); |
nucleosam | 0:36aa6787d4f9 | 256 | 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 | 257 | |
nucleosam | 0:36aa6787d4f9 | 258 | /* Get current position of device and print to the console */ |
nucleosam | 0:36aa6787d4f9 | 259 | printf(" Position: %d.\r\n", motor->GetPosition()); |
nucleosam | 0:36aa6787d4f9 | 260 | |
nucleosam | 0:36aa6787d4f9 | 261 | //----- Change decay mode |
nucleosam | 0:36aa6787d4f9 | 262 | motor->SetDecayMode(SLOW_DECAY); |
nucleosam | 0:36aa6787d4f9 | 263 | printf(" Motor decay mode: %d (0:slow decay, 1:fast decay).\r\n", motor->GetDecayMode()); |
nucleosam | 0:36aa6787d4f9 | 264 | |
nucleosam | 0:36aa6787d4f9 | 265 | //----- Go to position -6400 |
nucleosam | 0:36aa6787d4f9 | 266 | printf("--> Go to position -6400 steps.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 267 | motor->GoTo(-6400); |
nucleosam | 0:36aa6787d4f9 | 268 | |
nucleosam | 0:36aa6787d4f9 | 269 | /* Wait for the motor ends moving */ |
nucleosam | 0:36aa6787d4f9 | 270 | motor->WaitWhileActive(); |
nucleosam | 0:36aa6787d4f9 | 271 | |
nucleosam | 0:36aa6787d4f9 | 272 | /* Get current position of device and print to the console */ |
nucleosam | 0:36aa6787d4f9 | 273 | printf(" Position: %d.\r\n", motor->GetPosition()); |
nucleosam | 0:36aa6787d4f9 | 274 | |
nucleosam | 0:36aa6787d4f9 | 275 | /* Wait for 2 seconds */ |
nucleosam | 0:36aa6787d4f9 | 276 | wait_ms(2000); |
nucleosam | 0:36aa6787d4f9 | 277 | |
nucleosam | 0:36aa6787d4f9 | 278 | //----- Restore decay mode to its initialization value |
nucleosam | 0:36aa6787d4f9 | 279 | motor->SetDecayMode(initDeviceParameters.decayMode); |
nucleosam | 0:36aa6787d4f9 | 280 | printf(" Motor decay mode: %d (0:slow decay, 1:fast decay).\r\n", motor->GetDecayMode()); |
nucleosam | 0:36aa6787d4f9 | 281 | |
nucleosam | 0:36aa6787d4f9 | 282 | //----- Go Home |
nucleosam | 0:36aa6787d4f9 | 283 | printf("--> Go to home position.\r\n"); |
nucleosam | 0:36aa6787d4f9 | 284 | motor->GoHome(); |
nucleosam | 0:36aa6787d4f9 | 285 | |
nucleosam | 0:36aa6787d4f9 | 286 | /* Wait for the motor ends moving */ |
nucleosam | 0:36aa6787d4f9 | 287 | motor->WaitWhileActive(); |
nucleosam | 0:36aa6787d4f9 | 288 | |
nucleosam | 0:36aa6787d4f9 | 289 | /* Wait for 1 second */ |
nucleosam | 0:36aa6787d4f9 | 290 | wait_ms(1000); |
nucleosam | 0:36aa6787d4f9 | 291 | |
nucleosam | 0:36aa6787d4f9 | 292 | /* Infinite Loop. */ |
nucleosam | 0:36aa6787d4f9 | 293 | printf("--> Infinite Loop...\r\n"); |
nucleosam | 0:36aa6787d4f9 | 294 | while (1) |
nucleosam | 0:36aa6787d4f9 | 295 | { |
nucleosam | 0:36aa6787d4f9 | 296 | /* Request device to go position -3200 */ |
nucleosam | 0:36aa6787d4f9 | 297 | motor->GoTo(-3200); |
nucleosam | 0:36aa6787d4f9 | 298 | |
nucleosam | 0:36aa6787d4f9 | 299 | /* Waiting while the motor is active. */ |
nucleosam | 0:36aa6787d4f9 | 300 | motor->WaitWhileActive(); |
nucleosam | 0:36aa6787d4f9 | 301 | |
nucleosam | 0:36aa6787d4f9 | 302 | /* Request device to go position 3200 */ |
nucleosam | 0:36aa6787d4f9 | 303 | motor->GoTo(3200); |
nucleosam | 0:36aa6787d4f9 | 304 | |
nucleosam | 0:36aa6787d4f9 | 305 | /* Waiting while the motor is active. */ |
nucleosam | 0:36aa6787d4f9 | 306 | motor->WaitWhileActive(); |
nucleosam | 0:36aa6787d4f9 | 307 | } |
nucleosam | 0:36aa6787d4f9 | 308 | } |
nucleosam | 0:36aa6787d4f9 | 309 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |