Mems Motor Control application example with X_NUCLEO_IHM01A1 and X_NUCLEO_IKS01A2 expansion boards.
Dependencies: X_NUCLEO_IHM01A1 X_NUCLEO_IKS01A2 mbed
Fork of MemsMotorControl by
MEMS-based Motor Control
This application provides an intuitive and natural way for controlling a stepper motor through an accelerometer. It makes use of the STMicroelectronics X-NUCLEO-IKS01A2 MEMS Inertial and Environmental Sensors Expansion Board to get accelerometer values and the X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board to directly control a stepper motor with:
- speed proportional to the angle measured by the MEMS board;
- direction driven by the direction of rotation captured by the MEMS board.
Diff: main.cpp
- Revision:
- 4:778a7effb013
- Parent:
- 3:112d46906bee
- Child:
- 5:d88c9c8df082
--- a/main.cpp Wed Oct 28 12:46:15 2015 +0000 +++ b/main.cpp Fri Nov 13 13:00:51 2015 +0000 @@ -55,10 +55,10 @@ /* Definitions ---------------------------------------------------------------*/ /* Absolute value of the threshold on the Y axis acceleration. */ -#define ACCELERATION_TH 30 +#define ACCELERATION_TH 50 /* Rotation gain. */ -#define ROTATION_SPEED_GAIN 10 +#define ROTATION_SPEED_GAIN 40 /* Variables -----------------------------------------------------------------*/ @@ -119,7 +119,7 @@ /* Requesting to run. */ if (status != sign) { - motor->Run(sign == -1 ? BACKWARD : FORWARD); + motor->Run(sign == -1 ? StepperMotor::CCW : StepperMotor::CW); status = sign; } @@ -127,7 +127,7 @@ motor->SetMaxSpeed(speed); /* Printing to the console. */ - printf("Speed: %c%d\r\n", sign == -1 ? '-' : '+', motor->GetCurrentSpeed()); + printf("Speed: %c%d\r\n", sign == -1 ? '-' : '+', motor->GetSpeed()); } else if (status != 0) {