Simple test application for the STMicroelectronics X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board, built against mbed OS.

Dependencies:   X_NUCLEO_IHM01A1

Fork of HelloWorld_IHM01A1_2Motors by ST

Motor Control with the X-NUCLEO-IHM01A1 Expansion Board

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

Revision:
29:526970c1d998
Parent:
28:3f17a4152bcf
--- a/main.cpp	Wed Mar 01 13:32:24 2017 +0000
+++ b/main.cpp	Fri Mar 10 14:23:19 2017 +0000
@@ -46,7 +46,7 @@
 #include "DevSPI.h"
 
 /* Component specific header files. */
-#include "l6474_class.h"
+#include "L6474.h"
 
 
 /* Definitions ---------------------------------------------------------------*/
@@ -85,10 +85,10 @@
     /* Initializing Motor Control Components. */
     motor1 = new L6474(D2, D8, D7, D9, D10, dev_spi);
     motor2 = new L6474(D2, D8, D4, D3, D10, dev_spi);
-    if (motor1->Init() != COMPONENT_OK) {
+    if (motor1->init() != COMPONENT_OK) {
         exit(EXIT_FAILURE);
     }
-    if (motor2->Init() != COMPONENT_OK) {
+    if (motor2->init() != COMPONENT_OK) {
         exit(EXIT_FAILURE);
     }
 
@@ -102,16 +102,16 @@
     printf("--> Moving forward: M1 %d steps, M2 %d steps.\r\n", STEPS >> 1, STEPS);
 
     /* Moving N steps in the forward direction. */
-    motor1->Move(StepperMotor::FWD, STEPS >> 1);
-    motor2->Move(StepperMotor::FWD, STEPS);
+    motor1->move(StepperMotor::FWD, STEPS >> 1);
+    motor2->move(StepperMotor::FWD, STEPS);
 
     /* Waiting while the motor is active. */
-    motor1->WaitWhileActive();
-    motor2->WaitWhileActive();
+    motor1->wait_while_active();
+    motor2->wait_while_active();
 
     /* Getting current position. */
-    int position1 = motor1->GetPosition();
-    int position2 = motor2->GetPosition();
+    int position1 = motor1->get_position();
+    int position2 = motor2->get_position();
     
     /* Printing to the console. */
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
@@ -127,24 +127,24 @@
 
     
     /* Moving N steps in the backward direction. */
-    motor1->Move(StepperMotor::BWD, STEPS >> 1);
-    motor2->Move(StepperMotor::BWD, STEPS);
+    motor1->move(StepperMotor::BWD, STEPS >> 1);
+    motor2->move(StepperMotor::BWD, STEPS);
     
     /* Waiting while the motor is active. */
-    motor1->WaitWhileActive();
-    motor2->WaitWhileActive();
+    motor1->wait_while_active();
+    motor2->wait_while_active();
 
     /* Getting current position. */
-    position1 = motor1->GetPosition();
-    position2 = motor2->GetPosition();
+    position1 = motor1->get_position();
+    position2 = motor2->get_position();
     
     /* Printing to the console. */
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
     printf("--> Setting Home.\r\n");
 
     /* Setting the current position to be the home position. */
-    motor1->SetHome();
-    motor2->SetHome();
+    motor1->set_home();
+    motor2->set_home();
 
     /* Waiting 2 seconds. */
     wait_ms(DELAY_1);
@@ -156,16 +156,16 @@
     printf("--> Going to position: M1 %d, M2 %d.\r\n", STEPS, STEPS >> 1);
     
     /* Requesting to go to a specified position. */
-    motor1->GoTo(STEPS);
-    motor2->GoTo(STEPS >> 1);
+    motor1->go_to(STEPS);
+    motor2->go_to(STEPS >> 1);
     
     /* Waiting while the motor is active. */
-    motor1->WaitWhileActive();
-    motor2->WaitWhileActive();
+    motor1->wait_while_active();
+    motor2->wait_while_active();
 
     /* Getting current position. */
-    position1 = motor1->GetPosition();
-    position2 = motor2->GetPosition();
+    position1 = motor1->get_position();
+    position2 = motor2->get_position();
     
     /* Printing to the console. */
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
@@ -180,16 +180,16 @@
     printf("--> Going Home.\r\n");
     
     /* Requesting to go to home. */
-    motor1->GoHome();
-    motor2->GoHome();
+    motor1->go_home();
+    motor2->go_home();
     
     /* Waiting while the motor is active. */
-    motor1->WaitWhileActive();
-    motor2->WaitWhileActive();
+    motor1->wait_while_active();
+    motor2->wait_while_active();
 
     /* Getting current position. */
-    position1 = motor1->GetPosition();
-    position2 = motor2->GetPosition();
+    position1 = motor1->get_position();
+    position2 = motor2->get_position();
 
     /* Printing to the console. */
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
@@ -204,15 +204,15 @@
     printf("--> M1 running backward, M2 running forward.\r\n");
 
     /* Requesting to run backward. */
-    motor1->Run(StepperMotor::BWD);
-    motor2->Run(StepperMotor::FWD);
+    motor1->run(StepperMotor::BWD);
+    motor2->run(StepperMotor::FWD);
 
     /* Waiting until delay has expired. */
     wait_ms(DELAY_2);
 
     /* Getting current speed. */
-    int speed1 = motor1->GetSpeed();
-    int speed2 = motor2->GetSpeed();
+    int speed1 = motor1->get_speed();
+    int speed2 = motor2->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: M1 %d, M2 %d.\r\n", speed1, speed2);
@@ -223,15 +223,15 @@
     printf("--> Increasing the speed while running.\r\n");
 
     /* Increasing the speed. */
-    motor1->SetMaxSpeed(SPEED_1);
-    motor2->SetMaxSpeed(SPEED_1);
+    motor1->set_max_speed(SPEED_1);
+    motor2->set_max_speed(SPEED_1);
 
     /* Waiting until delay has expired. */
     wait_ms(DELAY_2);
 
     /* Getting current speed. */
-    speed1 = motor1->GetSpeed();
-    speed2 = motor2->GetSpeed();
+    speed1 = motor1->get_speed();
+    speed2 = motor2->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: M1 %d, M2 %d.\r\n", speed1, speed2);
@@ -243,15 +243,15 @@
     printf("--> Decreasing the speed while running.\r\n");
 
     /* Decreasing the speed. */
-    motor1->SetMaxSpeed(SPEED_2);
-    motor2->SetMaxSpeed(SPEED_2);
+    motor1->set_max_speed(SPEED_2);
+    motor2->set_max_speed(SPEED_2);
 
     /* Waiting until delay has expired. */
     wait_ms(DELAY_3);
 
     /* Getting current speed. */
-    speed1 = motor1->GetSpeed();
-    speed2 = motor2->GetSpeed();
+    speed1 = motor1->get_speed();
+    speed2 = motor2->get_speed();
 
     /* Printing to the console. */
     printf("    Speed: M1 %d, M2 %d.\r\n", speed1, speed2);
@@ -263,12 +263,12 @@
     printf("--> Requiring hard-stop while running.\r\n");
 
     /* Requesting to immediatly stop. */
-    motor1->HardStop();
-    motor2->HardStop();
+    motor1->hard_stop();
+    motor2->hard_stop();
 
     /* Waiting while the motor is active. */
-    motor1->WaitWhileActive();
-    motor2->WaitWhileActive();
+    motor1->wait_while_active();
+    motor2->wait_while_active();
 
     /* Waiting 2 seconds. */
     wait_ms(DELAY_1);
@@ -280,25 +280,25 @@
     printf("--> Infinite Loop...\r\n");
 
     /* Setting the current position to be the home position. */
-    motor1->SetHome();
-    motor2->SetHome();
+    motor1->set_home();
+    motor2->set_home();
 
     /* Infinite Loop. */
     while(true) {
         /* Requesting to go to a specified position. */
-        motor1->GoTo(STEPS >> 1);
-        motor2->GoTo(- (STEPS >> 1));
+        motor1->go_to(STEPS >> 1);
+        motor2->go_to(- (STEPS >> 1));
 
         /* Waiting while the motor is active. */
-        motor1->WaitWhileActive();
-        motor2->WaitWhileActive();
+        motor1->wait_while_active();
+        motor2->wait_while_active();
 
         /* Requesting to go to a specified position. */
-        motor1->GoTo(- (STEPS >> 1));
-        motor2->GoTo(STEPS >> 1);
+        motor1->go_to(- (STEPS >> 1));
+        motor2->go_to(STEPS >> 1);
 
         /* Waiting while the motor is active. */
-        motor1->WaitWhileActive();
-        motor2->WaitWhileActive();
+        motor1->wait_while_active();
+        motor2->wait_while_active();
     }
 }