Stepper motor control for KYPHOS rig
Dependencies: mbed X_NUCLEO_IHM03A1 HX711
Diff: main.cpp
- Revision:
- 2:ad3a480d3376
- Parent:
- 1:5822a95491d3
--- a/main.cpp Tue Feb 11 16:59:03 2020 +0000
+++ b/main.cpp Mon Mar 16 15:27:39 2020 +0000
@@ -8,7 +8,7 @@
.cm.cp.cmVmSelection = POWERSTEP01_CM_VM_CURRENT, // enum powerstep01_CmVm_t
582, // Acceleration rate in step/s2, range 14.55 to 59590 steps/s^2
582, // Deceleration rate in step/s2, range 14.55 to 59590 steps/s^2
- 200, // Maximum speed in step/s, range 15.25 to 15610 steps/s
+ 48, // Maximum speed in step/s, range 15.25 to 15610 steps/s
0, // Minimum speed in step/s, range 0 to 976.3 steps/s
POWERSTEP01_LSPD_OPT_OFF, // Low speed optimization bit, enum powerstep01_LspdOpt_t
244.16, // Full step speed in step/s, range 7.63 to 15625 steps/s
@@ -127,60 +127,33 @@
printf("Press button to start motor control.\r\n");
while(button);
-
- printf("--> Moving forward 480 steps.\r\n");
- motor->move(StepperMotor::BWD, 10*16*48);
-
- /* Waiting while the motor is active. */
+
+ printf("--> Going to start position.\r\n");
+ motor->move(StepperMotor::FWD, 2000);
motor->wait_while_active();
- /* Wait for 2 seconds */
- wait(2);
- //----- Go to position -480
- printf("--> Go to position -480 steps.\r\n");
-
- /* Request device to go to position -480 */
- motor->go_to(10*16*48);
-
- /* Wait for the motor ends moving */
- motor->wait_while_active();
-
- /* Get current position of device and print to the console */
- printf(" Position: %d.\r\n", motor->get_position());
-
- /* Wait for 2 seconds */
- wait(2);
-
+ while(button) {
+ //----- Go to position 7680
+ printf("--> Go to position -2000 steps.\r\n");
+ /* Request device to go to position 7680 */
+ motor->go_to(-2000);
+ /* Wait for the motor ends moving */
+ motor->wait_while_active();
+ printf("--> Go to position 2000 steps.\r\n");
+ motor->go_to(2000);
+ /* Wait for the motor ends moving */
+ motor->wait_while_active();
+ }
+
//----- Go Home
/* Printing to the console. */
printf("--> Go to home position.\r\n");
/* Request device to go to Home */
motor->go_home();
-
- /* Wait for the motor ends moving */
motor->wait_while_active();
-
-// /* Wait for 2 seconds */
-// wait(2*1000);
-//
-// //----- run the motor BACKWARD at 120 step/s
-// printf("--> run the motor backward at 120 step/s.\r\n");
-// motor->run(StepperMotor::BWD, 120);
-//
-// //----- Get parameter example
-// /* Wait for device reaches the targeted speed */
-// while ((motor->read_status_register() & POWERSTEP01_STATUS_MOT_STATUS) != POWERSTEP01_STATUS_MOT_STATUS_CONST_SPD);
-//
-// /* Record the reached speed in step/s and print to the console */
-// printf(" Reached Speed: %f step/s.\r\n", motor->get_analog_value(POWERSTEP01_SPEED));
-
- //----- Soft stopped required while running
- printf("--> Soft stop requested.\r\n");
-
/* Request a soft stop of device and keep the power bridges enabled */
motor->soft_hiz();
-
/* Wait for the motor of device ends moving */
motor->wait_while_active();
}
\ No newline at end of file