Simple program featuring a few API functions usage of the X_NUCLEO_IHM06A1 library.

Dependencies:   X_NUCLEO_IHM06A1 mbed

Fork of HelloWorld_IHM06A1 by ST Expansion SW Team

This application provides a simple example of usage of the X-NUCLEO-IHM06A1 Bipolar Stepper Motor Control Expansion Board.

It shows how to use a stepper motor connected to the board by:

  • Running the motor;
  • Monitoring the speed and the motor state;
  • Setting/Getting the speed;
  • Setting/Getting the step mode;
  • Setting/Getting the acceleration and deceleration;
  • Moving a defined number of steps or microsteps;
  • Disabling the power bridges;
  • Setting/Getting the torque;
  • Going to home position

It also shows how to monitor the step clock handler duration in order to evaluate the maximum achievable motor speed for a given MCU.

For the hardware configuration of the expansion board, please refer to the X_NUCLEO_IHM06A1 library web page.

Committer:
Davidroid
Date:
Fri Jul 28 13:28:52 2017 +0000
Revision:
6:a67d7d9f5528
Parent:
5:8c0802d9a345
Updating with new libraries.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucleosam 0:9ebe3081c641 1 /**
nucleosam 0:9ebe3081c641 2 ******************************************************************************
nucleosam 0:9ebe3081c641 3 * @file main.cpp
nucleosam 0:9ebe3081c641 4 * @author IPC Rennes
nucleosam 0:9ebe3081c641 5 * @version V1.0.0
nucleosam 0:9ebe3081c641 6 * @date May 26th, 2016
nucleosam 0:9ebe3081c641 7 * @brief mbed simple application for the STMicroelectronics X-NUCLEO-IHM06A1
nucleosam 0:9ebe3081c641 8 * Motor Control Expansion Board: control of 1 motor.
nucleosam 0:9ebe3081c641 9 ******************************************************************************
nucleosam 0:9ebe3081c641 10 * @attention
nucleosam 0:9ebe3081c641 11 *
nucleosam 0:9ebe3081c641 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nucleosam 0:9ebe3081c641 13 *
nucleosam 0:9ebe3081c641 14 * Redistribution and use in source and binary forms, with or without modification,
nucleosam 0:9ebe3081c641 15 * are permitted provided that the following conditions are met:
nucleosam 0:9ebe3081c641 16 * 1. Redistributions of source code must retain the above copyright notice,
nucleosam 0:9ebe3081c641 17 * this list of conditions and the following disclaimer.
nucleosam 0:9ebe3081c641 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nucleosam 0:9ebe3081c641 19 * this list of conditions and the following disclaimer in the documentation
nucleosam 0:9ebe3081c641 20 * and/or other materials provided with the distribution.
nucleosam 0:9ebe3081c641 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nucleosam 0:9ebe3081c641 22 * may be used to endorse or promote products derived from this software
nucleosam 0:9ebe3081c641 23 * without specific prior written permission.
nucleosam 0:9ebe3081c641 24 *
nucleosam 0:9ebe3081c641 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nucleosam 0:9ebe3081c641 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nucleosam 0:9ebe3081c641 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nucleosam 0:9ebe3081c641 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nucleosam 0:9ebe3081c641 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nucleosam 0:9ebe3081c641 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nucleosam 0:9ebe3081c641 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nucleosam 0:9ebe3081c641 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nucleosam 0:9ebe3081c641 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nucleosam 0:9ebe3081c641 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nucleosam 0:9ebe3081c641 35 *
nucleosam 0:9ebe3081c641 36 ******************************************************************************
nucleosam 0:9ebe3081c641 37 */
nucleosam 0:9ebe3081c641 38
nucleosam 0:9ebe3081c641 39 /* Includes ------------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 40
nucleosam 0:9ebe3081c641 41 /* mbed specific header files. */
nucleosam 0:9ebe3081c641 42 #include "mbed.h"
nucleosam 0:9ebe3081c641 43
nucleosam 0:9ebe3081c641 44 /* Component specific header files. */
davide.aliprandi@st.com 4:0e50964ff610 45 #include "STSpin220.h"
nucleosam 0:9ebe3081c641 46
nucleosam 0:9ebe3081c641 47 /* Definitions ---------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 48 #ifdef TARGET_NUCLEO_F302R8
nucleosam 0:9ebe3081c641 49 #define PWM_REF_PIN D11 /* HW mandatory patch: bridge manually D9 with D10 */
nucleosam 0:9ebe3081c641 50 #else
nucleosam 0:9ebe3081c641 51 #define PWM_REF_PIN D9
nucleosam 0:9ebe3081c641 52 #endif
nucleosam 0:9ebe3081c641 53 /* Uncomment the line below to enable the step clock monitoring duration */
nucleosam 0:9ebe3081c641 54 //#define STEP_CLOCK_HANDLER_DURATION_MONITORING
nucleosam 0:9ebe3081c641 55 #ifdef STEP_CLOCK_HANDLER_DURATION_MONITORING
nucleosam 0:9ebe3081c641 56 #define MONITORING_PIN D15
nucleosam 0:9ebe3081c641 57 #endif
nucleosam 0:9ebe3081c641 58
nucleosam 0:9ebe3081c641 59 /* Variables -----------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 60
nucleosam 0:9ebe3081c641 61 /* Initialization parameters of the motor connected to the expansion board. */
Davidroid 5:8c0802d9a345 62 STSpin220_init_t init =
nucleosam 0:9ebe3081c641 63 {
nucleosam 0:9ebe3081c641 64 10000, //Acceleration rate in pulse/s2 (must be greater than 0)
nucleosam 0:9ebe3081c641 65 10000, //Deceleration rate in pulse/s2 (must be greater than 0)
nucleosam 0:9ebe3081c641 66 10000, //Running speed in pulse/s (8 pulse/s < Maximum speed <= 10 000 pulse/s )
nucleosam 0:9ebe3081c641 67 400, //Minimum speed in pulse/s (8 pulse/s <= Minimum speed < 10 000 pulse/s)
nucleosam 0:9ebe3081c641 68 20, //Acceleration current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 69 15, //Deceleration current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 70 10, //Running current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 71 25, //Holding current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 72 TRUE, //Torque boost speed enable
nucleosam 0:9ebe3081c641 73 200, //Torque boost speed threshold in fullstep/s
nucleosam 0:9ebe3081c641 74 STEP_MODE_1_32, //Step mode via enum motorStepMode_t
nucleosam 0:9ebe3081c641 75 HIZ_MODE, //Automatic HIZ STOP
nucleosam 0:9ebe3081c641 76 100000 //REF frequency (Hz)
nucleosam 0:9ebe3081c641 77 };
nucleosam 0:9ebe3081c641 78
nucleosam 0:9ebe3081c641 79 /* Motor Control Component. */
davide.aliprandi@st.com 4:0e50964ff610 80 STSpin220 *motor;
nucleosam 0:9ebe3081c641 81
nucleosam 0:9ebe3081c641 82 /* Functions -----------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 83
nucleosam 0:9ebe3081c641 84 /**
nucleosam 0:9ebe3081c641 85 * @brief This is an example of user handler for the flag interrupt.
nucleosam 0:9ebe3081c641 86 * @param None
nucleosam 0:9ebe3081c641 87 * @retval None
nucleosam 0:9ebe3081c641 88 * @note If needed, implement it, and then attach and enable it:
davide.aliprandi@st.com 4:0e50964ff610 89 * + motor->attach_flag_irq(&my_flag_irq_handler);
davide.aliprandi@st.com 4:0e50964ff610 90 * + motor->enable_flag_irq();
nucleosam 0:9ebe3081c641 91 * To disable it:
nucleosam 0:9ebe3081c641 92 * + motor->DisbleFlagIRQ();
nucleosam 0:9ebe3081c641 93 */
davide.aliprandi@st.com 4:0e50964ff610 94 void my_flag_irq_handler(void)
nucleosam 0:9ebe3081c641 95 {
nucleosam 0:9ebe3081c641 96 printf(" WARNING: \"FLAG\" interrupt triggered:\r\n");
Davidroid 5:8c0802d9a345 97 motor->disable();
nucleosam 0:9ebe3081c641 98 printf(" Motor disabled.\r\n\n");
nucleosam 0:9ebe3081c641 99 }
nucleosam 0:9ebe3081c641 100
nucleosam 0:9ebe3081c641 101 /**
nucleosam 0:9ebe3081c641 102 * @brief This is an example of error handler.
nucleosam 0:9ebe3081c641 103 * @param[in] error Number of the error
nucleosam 0:9ebe3081c641 104 * @retval None
nucleosam 0:9ebe3081c641 105 * @note If needed, implement it, and then attach it:
davide.aliprandi@st.com 4:0e50964ff610 106 * + motor->attach_error_handler(&my_error_handler);
nucleosam 0:9ebe3081c641 107 */
davide.aliprandi@st.com 4:0e50964ff610 108 void my_error_handler(uint16_t error)
nucleosam 0:9ebe3081c641 109 {
nucleosam 0:9ebe3081c641 110 /* Printing to the console. */
nucleosam 0:9ebe3081c641 111 printf("Error %d detected\r\n\n", error);
nucleosam 0:9ebe3081c641 112
nucleosam 0:9ebe3081c641 113 /* Infinite loop */
davide.aliprandi@st.com 4:0e50964ff610 114 while (true) {
nucleosam 0:9ebe3081c641 115 }
nucleosam 0:9ebe3081c641 116 }
nucleosam 0:9ebe3081c641 117
nucleosam 0:9ebe3081c641 118 /* Main ----------------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 119
nucleosam 0:9ebe3081c641 120 int main()
nucleosam 0:9ebe3081c641 121 {
nucleosam 0:9ebe3081c641 122 /* Printing to the console. */
nucleosam 0:9ebe3081c641 123 printf("STARTING MAIN PROGRAM\r\n");
nucleosam 0:9ebe3081c641 124 printf(" Reminder:\r\n");
nucleosam 0:9ebe3081c641 125 printf(" The position, speed, acceleration and deceleration units\r\n");
nucleosam 0:9ebe3081c641 126 printf(" are in agreement to the step mode.\r\n");
nucleosam 0:9ebe3081c641 127 printf(" In example if the step mode is 1/32th,\r\n");
nucleosam 0:9ebe3081c641 128 printf(" the position is in 1/32th step,\r\n");
nucleosam 0:9ebe3081c641 129 printf(" the speed is in 1/32th step/s,\r\n");
nucleosam 0:9ebe3081c641 130 printf(" the acceleration and the deceleration are in 1/32th step/s^2.\r\n");
nucleosam 0:9ebe3081c641 131
nucleosam 0:9ebe3081c641 132 //----- Initialization
nucleosam 0:9ebe3081c641 133 /* Initializing Motor Control Component. */
nucleosam 0:9ebe3081c641 134 #ifdef STEP_CLOCK_HANDLER_DURATION_MONITORING
davide.aliprandi@st.com 4:0e50964ff610 135 motor = new STSpin220(D2, D8, D7, D5, D10, D3, PWM_REF_PIN, MONITORING_PIN);
nucleosam 0:9ebe3081c641 136 #else
davide.aliprandi@st.com 4:0e50964ff610 137 motor = new STSpin220(D2, D8, D7, D5, D10, D3, PWM_REF_PIN);
nucleosam 0:9ebe3081c641 138 #endif
nucleosam 0:9ebe3081c641 139
davide.aliprandi@st.com 4:0e50964ff610 140 if (motor->init(&init) != COMPONENT_OK) {
davide.aliprandi@st.com 4:0e50964ff610 141 exit(EXIT_FAILURE);
davide.aliprandi@st.com 4:0e50964ff610 142 }
nucleosam 0:9ebe3081c641 143
nucleosam 0:9ebe3081c641 144 /* Attaching and enabling an interrupt handler. */
davide.aliprandi@st.com 4:0e50964ff610 145 motor->attach_flag_irq(&my_flag_irq_handler);
davide.aliprandi@st.com 4:0e50964ff610 146 motor->enable_flag_irq();
nucleosam 0:9ebe3081c641 147
nucleosam 0:9ebe3081c641 148 /* Attaching an error handler */
davide.aliprandi@st.com 4:0e50964ff610 149 motor->attach_error_handler(&my_error_handler);
nucleosam 0:9ebe3081c641 150
nucleosam 0:9ebe3081c641 151 /* Printing to the console. */
nucleosam 0:9ebe3081c641 152 printf("Motor Control Application Example for 1 Motor\r\n");
nucleosam 0:9ebe3081c641 153
nucleosam 0:9ebe3081c641 154 //----- Get the step mode after initialization
davide.aliprandi@st.com 4:0e50964ff610 155 StepperMotor::step_mode_t myStepMode = motor->get_step_mode();
nucleosam 0:9ebe3081c641 156
davide.aliprandi@st.com 4:0e50964ff610 157 //----- run the motor BACKWARD
nucleosam 0:9ebe3081c641 158 printf("--> Running the motor backward.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 159 motor->run(StepperMotor::BWD);
nucleosam 0:9ebe3081c641 160
davide.aliprandi@st.com 4:0e50964ff610 161 while (motor->get_status()!=STEADY)
nucleosam 0:9ebe3081c641 162 {
nucleosam 0:9ebe3081c641 163 /* Print reached speed to the console in step/s or microsteps/s */
davide.aliprandi@st.com 4:0e50964ff610 164 printf(" Reached Speed: %d step/s.\r\n", motor->get_speed());
nucleosam 0:9ebe3081c641 165 wait_ms(50);
nucleosam 0:9ebe3081c641 166 }
davide.aliprandi@st.com 4:0e50964ff610 167 printf(" Reached Speed: %d step/s.\r\n", motor->get_speed());
nucleosam 0:9ebe3081c641 168
nucleosam 0:9ebe3081c641 169 /* Wait for 1 second */
nucleosam 0:9ebe3081c641 170 wait_ms(1000);
nucleosam 0:9ebe3081c641 171
nucleosam 0:9ebe3081c641 172 //----- Decrease speed while running to one quarter of the previous speed
nucleosam 0:9ebe3081c641 173 printf(" Motor init step mode: %d\r\n", myStepMode);
davide.aliprandi@st.com 4:0e50964ff610 174 int currentStepMode = motor->get_step_mode();
nucleosam 0:9ebe3081c641 175 printf(" Motor current step mode: %d\r\n", currentStepMode);
davide.aliprandi@st.com 4:0e50964ff610 176 int newSpeed = (motor->get_speed()<<(myStepMode-currentStepMode))>>2;
nucleosam 0:9ebe3081c641 177 printf(" Set motor max speed to: %d step/s.\r\n", newSpeed);
davide.aliprandi@st.com 4:0e50964ff610 178 if (!motor->set_max_speed(newSpeed)) {
nucleosam 0:9ebe3081c641 179 printf(" Failed: target speed below min speed.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 180 if (motor->set_max_speed(motor->get_min_speed())) {
davide.aliprandi@st.com 4:0e50964ff610 181 printf(" Motor max speed set to min speed: %d step/s.\r\n", motor->get_min_speed());
davide.aliprandi@st.com 4:0e50964ff610 182 } else {
nucleosam 0:9ebe3081c641 183 printf(" Failed: check all speed and boost setting.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 184 }
nucleosam 0:9ebe3081c641 185 }
nucleosam 0:9ebe3081c641 186
nucleosam 0:9ebe3081c641 187 /* Wait until the motor starts decelerating */
davide.aliprandi@st.com 4:0e50964ff610 188 while (motor->get_status()==STEADY);
nucleosam 0:9ebe3081c641 189 /* Wait and print speed while the motor is not steady running */
davide.aliprandi@st.com 4:0e50964ff610 190 while (motor->get_status()!=STEADY) {
nucleosam 0:9ebe3081c641 191 /* Print reached speed to the console in step/s or microsteps/s */
davide.aliprandi@st.com 4:0e50964ff610 192 printf(" Reached Speed: %d step/s.\r\n", motor->get_speed());
nucleosam 0:9ebe3081c641 193 wait_ms(50);
nucleosam 0:9ebe3081c641 194 }
davide.aliprandi@st.com 4:0e50964ff610 195 printf(" Reached Speed: %d step/s.\r\n", motor->get_speed());
nucleosam 0:9ebe3081c641 196
nucleosam 0:9ebe3081c641 197 /* Wait for 5 seconds */
nucleosam 0:9ebe3081c641 198 wait_ms(5000);
nucleosam 0:9ebe3081c641 199
nucleosam 0:9ebe3081c641 200 //----- Soft stop required while running
nucleosam 0:9ebe3081c641 201 printf("--> Soft stop requested.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 202 motor->soft_stop();
nucleosam 0:9ebe3081c641 203
nucleosam 0:9ebe3081c641 204 /* Wait for the motor of device ends moving */
davide.aliprandi@st.com 4:0e50964ff610 205 motor->wait_while_active();
nucleosam 0:9ebe3081c641 206
nucleosam 0:9ebe3081c641 207 /* Wait for 2 seconds */
nucleosam 0:9ebe3081c641 208 wait_ms(2000);
nucleosam 0:9ebe3081c641 209
nucleosam 0:9ebe3081c641 210 //----- Change step mode to full step mode
davide.aliprandi@st.com 4:0e50964ff610 211 motor->set_step_mode(StepperMotor::STEP_MODE_FULL);
davide.aliprandi@st.com 4:0e50964ff610 212 printf(" Motor step mode: %d\r\n", motor->get_step_mode());
nucleosam 0:9ebe3081c641 213 printf(" 0:FS 1:1/2 2:1/4\r\n 3:1/8 4:1/16 5:1/32\r\n");
nucleosam 0:9ebe3081c641 214 printf(" 6:1/64 7:1/128 8:1/256\r\n");
nucleosam 0:9ebe3081c641 215
nucleosam 0:9ebe3081c641 216 /* Get current position of device and print to the console */
davide.aliprandi@st.com 4:0e50964ff610 217 printf(" Position: %d.\r\n", motor->get_position());
nucleosam 0:9ebe3081c641 218
nucleosam 0:9ebe3081c641 219 /* Set speed, acceleration and deceleration to scale with full step mode */
davide.aliprandi@st.com 4:0e50964ff610 220 motor->set_min_speed(init.minSpeed>>myStepMode);
davide.aliprandi@st.com 4:0e50964ff610 221 motor->set_max_speed(init.maxSpeed>>myStepMode);
davide.aliprandi@st.com 4:0e50964ff610 222 motor->set_acceleration(motor->get_acceleration()>>myStepMode);
davide.aliprandi@st.com 4:0e50964ff610 223 motor->set_deceleration(motor->get_deceleration()>>myStepMode);
nucleosam 0:9ebe3081c641 224 /* Print parameters to the console */
davide.aliprandi@st.com 4:0e50964ff610 225 printf(" Motor Min Speed: %d step/s.\r\n", motor->get_min_speed());
davide.aliprandi@st.com 4:0e50964ff610 226 printf(" Motor Max Speed: %d step/s.\r\n", motor->get_max_speed());
davide.aliprandi@st.com 4:0e50964ff610 227 printf(" Motor Acceleration: %d step/s.\r\n", motor->get_acceleration());
davide.aliprandi@st.com 4:0e50964ff610 228 printf(" Motor Deceleration: %d step/s.\r\n", motor->get_deceleration());
nucleosam 0:9ebe3081c641 229
davide.aliprandi@st.com 4:0e50964ff610 230 //----- move of 200 steps in the FW direction
nucleosam 0:9ebe3081c641 231 printf("--> Moving forward 200 steps.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 232 motor->move(StepperMotor::FWD, 200);
nucleosam 0:9ebe3081c641 233
nucleosam 0:9ebe3081c641 234 /* Waiting while the motor is active. */
davide.aliprandi@st.com 4:0e50964ff610 235 motor->wait_while_active();
nucleosam 0:9ebe3081c641 236
nucleosam 0:9ebe3081c641 237 /* Get current position of device and print to the console */
davide.aliprandi@st.com 4:0e50964ff610 238 printf(" Position: %d.\r\n", motor->get_position());
nucleosam 0:9ebe3081c641 239
nucleosam 0:9ebe3081c641 240 /* Disable the power bridges */
Davidroid 5:8c0802d9a345 241 motor->disable();
nucleosam 0:9ebe3081c641 242
nucleosam 0:9ebe3081c641 243 /* Check that the power bridges are actually disabled */
davide.aliprandi@st.com 4:0e50964ff610 244 if (motor->check_status_hw()!=0) {
davide.aliprandi@st.com 4:0e50964ff610 245 printf(" Motor driver disabled.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 246 } else {
davide.aliprandi@st.com 4:0e50964ff610 247 printf(" Failed to disable the motor driver.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 248 }
nucleosam 0:9ebe3081c641 249
nucleosam 0:9ebe3081c641 250 /* Wait for 2 seconds */
nucleosam 0:9ebe3081c641 251 wait_ms(2000);
nucleosam 0:9ebe3081c641 252
nucleosam 0:9ebe3081c641 253 //----- Restore step mode to its initialization value
davide.aliprandi@st.com 4:0e50964ff610 254 motor->set_step_mode((StepperMotor::step_mode_t)init.stepMode);
davide.aliprandi@st.com 4:0e50964ff610 255 printf(" Motor step mode: %d\r\n", motor->get_step_mode());
nucleosam 0:9ebe3081c641 256 printf(" 0:FS 1:1/2 2:1/4\r\n 3:1/8 4:1/16 5:1/32\r\n");
nucleosam 0:9ebe3081c641 257 printf(" 6:1/64 7:1/128 8:1/256\r\n");
nucleosam 0:9ebe3081c641 258
nucleosam 0:9ebe3081c641 259 /* Set speed, acceleration and deceleration to scale with microstep mode */
davide.aliprandi@st.com 4:0e50964ff610 260 motor->set_max_speed(motor->get_max_speed()<<myStepMode);
davide.aliprandi@st.com 4:0e50964ff610 261 motor->set_min_speed(motor->get_min_speed()<<myStepMode);
davide.aliprandi@st.com 4:0e50964ff610 262 motor->set_acceleration(motor->get_acceleration()<<myStepMode);
davide.aliprandi@st.com 4:0e50964ff610 263 motor->set_deceleration(motor->get_deceleration()<<myStepMode);
nucleosam 0:9ebe3081c641 264 /* Print parameters to the console */
davide.aliprandi@st.com 4:0e50964ff610 265 printf(" Motor Max Speed: %d step/s.\r\n", motor->get_max_speed());
davide.aliprandi@st.com 4:0e50964ff610 266 printf(" Motor Min Speed: %d step/s.\r\n", motor->get_min_speed());
davide.aliprandi@st.com 4:0e50964ff610 267 printf(" Motor Acceleration: %d step/s.\r\n", motor->get_acceleration());
davide.aliprandi@st.com 4:0e50964ff610 268 printf(" Motor Deceleration: %d step/s.\r\n", motor->get_deceleration());
nucleosam 0:9ebe3081c641 269
nucleosam 0:9ebe3081c641 270 /* Get current position of device and print to the console */
davide.aliprandi@st.com 4:0e50964ff610 271 printf(" Position: %d.\r\n", motor->get_position());
nucleosam 0:9ebe3081c641 272
nucleosam 0:9ebe3081c641 273 //----- Change torque
davide.aliprandi@st.com 4:0e50964ff610 274 motor->set_torque(ACC_TORQUE,30);
davide.aliprandi@st.com 4:0e50964ff610 275 motor->set_torque(DEC_TORQUE,20);
davide.aliprandi@st.com 4:0e50964ff610 276 printf(" Motor acceleration and deceleration torque changed to: %d and %d.\r\n", motor->get_torque(ACC_TORQUE), motor->get_torque(DEC_TORQUE));
nucleosam 0:9ebe3081c641 277
nucleosam 0:9ebe3081c641 278 //----- Go to position -6400
nucleosam 0:9ebe3081c641 279 printf("--> Go to position -6400 steps.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 280 motor->go_to(-6400);
nucleosam 0:9ebe3081c641 281
nucleosam 0:9ebe3081c641 282 /* Wait for the motor ends moving */
davide.aliprandi@st.com 4:0e50964ff610 283 motor->wait_while_active();
nucleosam 0:9ebe3081c641 284
nucleosam 0:9ebe3081c641 285 /* Get current position of device and print to the console */
davide.aliprandi@st.com 4:0e50964ff610 286 printf(" Position: %d.\r\n", motor->get_position());
nucleosam 0:9ebe3081c641 287
nucleosam 0:9ebe3081c641 288 /* Wait for 2 seconds */
nucleosam 0:9ebe3081c641 289 wait_ms(2000);
nucleosam 0:9ebe3081c641 290
nucleosam 0:9ebe3081c641 291 //----- Go Home
nucleosam 0:9ebe3081c641 292 printf("--> Go to home position.\r\n");
davide.aliprandi@st.com 4:0e50964ff610 293 motor->go_home();
nucleosam 0:9ebe3081c641 294
nucleosam 0:9ebe3081c641 295 /* Wait for the motor ends moving */
davide.aliprandi@st.com 4:0e50964ff610 296 motor->wait_while_active();
nucleosam 0:9ebe3081c641 297
nucleosam 0:9ebe3081c641 298 /* Wait for 1 second */
nucleosam 0:9ebe3081c641 299 wait_ms(1000);
nucleosam 0:9ebe3081c641 300
nucleosam 0:9ebe3081c641 301 /* Infinite Loop. */
nucleosam 0:9ebe3081c641 302 printf("--> Infinite Loop...\r\n");
davide.aliprandi@st.com 4:0e50964ff610 303 while (true) {
nucleosam 0:9ebe3081c641 304 /* Request device to go position -3200 */
davide.aliprandi@st.com 4:0e50964ff610 305 motor->go_to(-3200);
nucleosam 0:9ebe3081c641 306 /* Waiting while the motor is active. */
davide.aliprandi@st.com 4:0e50964ff610 307 motor->wait_while_active();
nucleosam 0:9ebe3081c641 308 /* Request device to go position 3200 */
davide.aliprandi@st.com 4:0e50964ff610 309 motor->go_to(3200);
nucleosam 0:9ebe3081c641 310 /* Waiting while the motor is active. */
davide.aliprandi@st.com 4:0e50964ff610 311 motor->wait_while_active();
nucleosam 0:9ebe3081c641 312 wait_ms(500);
nucleosam 0:9ebe3081c641 313 }
nucleosam 0:9ebe3081c641 314 }
nucleosam 0:9ebe3081c641 315 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/