Test application for the STMicroelectronics X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board.

Dependencies:   X_NUCLEO_IHM01A1 mbed

Fork of MotorControl_IHM01A1 by ST Expansion SW Team

Motor Control with the X-NUCLEO-IHM01A1 Expansion Board

This application provides a more complex example of usage of the X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board.
It shows how to use one stepper motor connected to the board, with an example of ISR and error handler, as well as an almost complete coverage of the available APIs, e.g.:

  • moving the rotor to a specific position;
  • moving the rotor for a certain amount of time;
  • setting the speed value;
  • setting the direction of rotation;
  • changing the stepper motor mode;
  • soft/hard stopping the rotor;
  • powering off the power bridge.
Revision:
26:7a58cede28f7
Parent:
25:205b3d09e64e
--- a/main.cpp	Wed Mar 01 15:55:18 2017 +0000
+++ b/main.cpp	Fri Mar 10 14:50:46 2017 +0000
@@ -47,13 +47,13 @@
 #include "DevSPI.h"
 
 /* Component specific header files. */
-#include "l6474_class.h"
+#include "L6474.h"
 
 
 /* Variables -----------------------------------------------------------------*/
 
 /* Initialization parameters. */
-L6474_Init_t init = {
+L6474_init_t init = {
     160,                              /* Acceleration rate in pps^2. Range: (0..+inf). */
     160,                              /* Deceleration rate in pps^2. Range: (0..+inf). */
     1600,                             /* Maximum speed in pps. Range: (30..10000]. */
@@ -102,7 +102,7 @@
     motor->isr_flag = TRUE;
 
     /* Get the value of the status register. */
-    unsigned int status = motor->GetStatus();
+    unsigned int status = motor->get_status();
     
     /* Check HIZ flag: if set, power brigdes are disabled. */
     if ((status & L6474_STATUS_HIZ) == L6474_STATUS_HIZ)
@@ -171,13 +171,13 @@
 
     /* Initializing Motor Control Component. */
     motor = new L6474(D2, D8, D7, D9, D10, dev_spi);
-    if (motor->Init(&init) != COMPONENT_OK) {
+    if (motor->init(&init) != COMPONENT_OK) {
         exit(EXIT_FAILURE);
     }
 
     /* Attaching and enabling the user handler for the flag interrupt. */
-    motor->AttachFlagIRQ(&FlagIRQHandler);
-    motor->EnableFlagIRQ();
+    motor->attach_flag_irq(&FlagIRQHandler);
+    motor->enable_flag_irq();
 
     /* Printing to the console. */
     printf("Motor Control Application Example for 1 Motor\r\n\n");
@@ -189,10 +189,10 @@
     printf("--> Moving forward 16000 steps.\r\n");
 
     /* Moving 16000 steps in the forward direction. */
-    motor->Move(StepperMotor::FWD, 16000);
+    motor->move(StepperMotor::FWD, 16000);
     
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Waiting 2 seconds. */
     wait_ms(2000);
@@ -204,16 +204,16 @@
     printf("--> Moving backward 16000 steps.\r\n");
     
     /* Moving 16000 steps in the backward direction. */
-    motor->Move(StepperMotor::BWD, 16000);
+    motor->move(StepperMotor::BWD, 16000);
 
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Printing to the console. */
     printf("--> Setting Home.\r\n");
 
     /* Setting the current position to be the home position. */
-    motor->SetHome();
+    motor->set_home();
 
     /* Waiting 2 seconds. */
     wait_ms(2000);
@@ -225,13 +225,13 @@
     printf("--> Going to position -6400.\r\n");
     
     /* Requesting to go to a specified position. */
-    motor->GoTo(-6400);
+    motor->go_to(-6400);
     
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Getting current position. */
-    int position = motor->GetPosition();
+    int position = motor->get_position();
     
     /* Printing to the console. */
     printf("    Position: %d.\r\n", position);
@@ -240,7 +240,7 @@
     printf("--> Setting a mark.\r\n");
 
     /* Setting the current position to be the mark position. */
-    motor->SetMark();
+    motor->set_mark();
 
     /* Waiting 2 seconds. */
     wait_ms(2000);
@@ -252,13 +252,13 @@
     printf("--> Going Home.\r\n");
     
     /* Requesting to go to home */
-    motor->GoHome();  
+    motor->go_home();  
     
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Getting current position. */
-    position = motor->GetPosition();
+    position = motor->get_position();
 
     /* Printing to the console. */
     printf("    Position: %d.\r\n", position);
@@ -273,13 +273,13 @@
     printf("--> Going to position 6400.\r\n");
     
     /* Requesting to go to a specified position. */
-    motor->GoTo(6400);
+    motor->go_to(6400);
     
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Getting current position. */
-    position = motor->GetPosition();
+    position = motor->get_position();
 
     /* Printing to the console. */
     printf("    Position: %d.\r\n", position);
@@ -294,13 +294,13 @@
     printf("--> Going to the mark set previously.\r\n");
     
     /* Requesting to go to mark position. */
-    motor->GoMark();  
+    motor->go_mark();  
     
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Getting current position. */
-    position = motor->GetPosition();
+    position = motor->get_position();
 
     /* Printing to the console. */
     printf("    Position: %d.\r\n", position);
@@ -315,13 +315,13 @@
     printf("--> Running backward.\r\n");
 
     /* Requesting to run backward. */
-    motor->Run(StepperMotor::BWD);
+    motor->run(StepperMotor::BWD);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
 
     /* Getting current speed. */
-    int speed = motor->GetSpeed();
+    int speed = motor->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: %d.\r\n", speed);
@@ -333,13 +333,13 @@
     printf("--> Increasing the speed while running.\r\n");
 
     /* Increasing the speed. */
-    motor->SetMaxSpeed(2400);
+    motor->set_max_speed(2400);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
 
     /* Getting current speed. */
-    speed = motor->GetSpeed();
+    speed = motor->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: %d.\r\n", speed);
@@ -351,13 +351,13 @@
     printf("--> Decreasing the speed while running.\r\n");
 
     /* Decreasing the speed. */
-    motor->SetMaxSpeed(1200);
+    motor->set_max_speed(1200);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
 
     /* Getting current speed. */
-    speed = motor->GetSpeed();
+    speed = motor->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: %d.\r\n", speed);
@@ -369,19 +369,19 @@
     printf("--> Increasing acceleration while running.\r\n");
 
     /* Increasing the acceleration. */
-    motor->SetAcceleration(480);
+    motor->set_acceleration(480);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
 
     /* Increasing the speed. */
-    motor->SetMaxSpeed(2400);
+    motor->set_max_speed(2400);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
 
     /* Getting current speed. */
-    speed = motor->GetSpeed();
+    speed = motor->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: %d.\r\n", speed);
@@ -393,19 +393,19 @@
     printf("--> Increasing deceleration while running.\r\n");
 
     /* Increasing the deceleration. */
-    motor->SetDeceleration(480);
+    motor->set_deceleration(480);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
 
     /* Decreasing the speed. */
-    motor->SetMaxSpeed(1200);
+    motor->set_max_speed(1200);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
 
     /* Getting current speed. */
-    speed = motor->GetSpeed();
+    speed = motor->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: %d.\r\n", speed);
@@ -417,10 +417,10 @@
     printf("--> Requesting soft-stop while running.\r\n");
 
     /* Requesting soft stop. */
-    motor->SoftStop();
+    motor->soft_stop();
 
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Waiting 2 seconds. */
     wait_ms(2000);
@@ -432,7 +432,7 @@
     printf("--> Running forward.\r\n");
     
     /* Requesting to run in forward direction. */
-    motor->Run(StepperMotor::FWD);
+    motor->run(StepperMotor::FWD);
 
     /* Waiting until delay has expired. */
     wait_ms(5000);
@@ -441,10 +441,10 @@
     printf("--> Requesting hard-stop while running.\r\n");
 
     /* Requesting to immediatly stop. */
-    motor->HardStop();
+    motor->hard_stop();
 
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Waiting 2 seconds. */
     wait_ms(2000);
@@ -456,7 +456,7 @@
     printf("--> Going to position 20000.\r\n");
     
     /* Requesting to go to a specified position. */
-    motor->GoTo(20000);  
+    motor->go_to(20000);  
     
     /* Waiting while the motor is active. */
     wait_ms(5000);
@@ -465,10 +465,10 @@
     printf("--> Requiring soft-stop while running.\r\n");
 
     /* Requesting to perform a soft stop */
-    motor->SoftStop();
+    motor->soft_stop();
 
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Waiting 2 seconds. */
     wait_ms(2000);
@@ -484,7 +484,7 @@
      * The flag interrupt should be raised and the "MyFlagInterruptHandler"
      * function called.
      */
-    motor->GetParameter(0x1F);
+    motor->get_parameter(0x1F);
 
     /* Waiting 0.5 seconds. */
     wait_ms(500);
@@ -496,24 +496,24 @@
     printf("--> Changing step mode to full step mode.\r\n");
 
     /* Selecting full step mode. */
-    if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_FULL)) {
+    if (!motor->set_step_mode((StepperMotor::step_mode_t) STEP_MODE_FULL)) {
         printf("    Step Mode not allowed.\r\n");
     }
 
     /* Setting speed and acceleration to be consistent with full step mode. */
-    motor->SetMaxSpeed(100);
-    motor->SetMinSpeed(50);
-    motor->SetAcceleration(10);
-    motor->SetDeceleration(10);
+    motor->set_max_speed(100);
+    motor->set_min_speed(50);
+    motor->set_acceleration(10);
+    motor->set_deceleration(10);
 
     /* Requesting to go to a specified position. */
-    motor->GoTo(200);
+    motor->go_to(200);
 
     /* Waiting while the motor is active. */
-    motor->WaitWhileActive();
+    motor->wait_while_active();
 
     /* Getting current position */
-    position = motor->GetPosition();
+    position = motor->get_position();
 
     /* Printing to the console. */
     printf("    Position: %d.\r\n", position);
@@ -528,15 +528,15 @@
     printf("--> Restoring 1/16 microstepping mode.\r\n");
 
     /* Resetting to 1/16 microstepping mode */
-    if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_1_16)) {
+    if (!motor->set_step_mode((StepperMotor::step_mode_t) STEP_MODE_1_16)) {
         printf("    Step Mode not allowed.\r\n");
     }
 
     /* Update speed, acceleration, deceleration for 1/16 microstepping mode*/
-    motor->SetMaxSpeed(1600);
-    motor->SetMinSpeed(800);
-    motor->SetAcceleration(160);
-    motor->SetDeceleration(160);  
+    motor->set_max_speed(1600);
+    motor->set_min_speed(800);
+    motor->set_acceleration(160);
+    motor->set_deceleration(160);  
 
 
     /*----- Infinite Loop. -----*/
@@ -547,15 +547,15 @@
     /* Infinite Loop. */
     while (true) {
         /* Requesting to go to a specified position. */
-        motor->GoTo(-6400);
+        motor->go_to(-6400);
 
         /* Waiting while the motor is active. */
-        motor->WaitWhileActive();
+        motor->wait_while_active();
 
         /* Requesting to go to a specified position. */
-        motor->GoTo(6400);
+        motor->go_to(6400);
 
         /* Waiting while the motor is active. */
-        motor->WaitWhileActive();
+        motor->wait_while_active();
     }
 }