my 2axes stepper
Dependencies: mbed X_NUCLEO_IHM02A1
Revision 27:46b2cf25a11a, committed 2020-01-16
- Comitter:
- Kiskovce
- Date:
- Thu Jan 16 12:23:31 2020 +0000
- Parent:
- 26:caec5f51abe8
- Child:
- 28:f6b184e44cc6
- Commit message:
- aa
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Mar 13 17:53:12 2017 +0000
+++ b/main.cpp Thu Jan 16 12:23:31 2020 +0000
@@ -55,7 +55,7 @@
#define MPR_1 4
/* Number of steps. */
-#define STEPS_1 (400 * 128) /* 1 revolution given a 400 steps motor configured at 1/128 microstep mode. */
+#define STEPS_1 (200 * 128) /* 1 revolution given a 400 steps motor configured at 1/128 microstep mode. */
#define STEPS_2 (STEPS_1 * 2)
/* Delay in milliseconds. */
@@ -73,9 +73,9 @@
L6470_init_t init[L6470DAISYCHAINSIZE] = {
/* First Motor. */
{
- 9.0, /* Motor supply voltage in V. */
+ 12.0, /* Motor supply voltage in V. */
400, /* Min number of steps per revolution for the motor. */
- 1.7, /* Max motor phase voltage in A. */
+ 1.0, /* Max motor phase voltage in A. */
3.06, /* Max motor phase voltage in V. */
300.0, /* Motor initial speed [step/s]. */
500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
@@ -101,9 +101,9 @@
/* Second Motor. */
{
- 9.0, /* Motor supply voltage in V. */
+ 12.0, /* Motor supply voltage in V. */
400, /* Min number of steps per revolution for the motor. */
- 1.7, /* Max motor phase voltage in A. */
+ 1.0, /* Max motor phase voltage in A. */
3.06, /* Max motor phase voltage in V. */
300.0, /* Motor initial speed [step/s]. */
500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
@@ -142,47 +142,30 @@
DevSPI dev_spi(D11, D12, D3);
#endif
- /* Initializing Motor Control Expansion Board. */
x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);
-
- /* Building a list of motor control components. */
L6470 **motors = x_nucleo_ihm02a1->get_components();
-
- /* Printing to the console. */
- printf("Motor Control Application Example for 2 Motors\r\n\n");
-
-
- /*----- Setting home and marke positions, getting positions, and going to positions. -----*/
-
- /* Printing to the console. */
- printf("--> Setting home position.\r\n");
-
- /* Setting the home position. */
- motors[0]->set_home();
-
- /* Waiting. */
+
+ motors[1]->set_home(); /* Setting the home position. */
+ wait_ms(DELAY_1);
+ int position = motors[1]->get_position(); /* Getting the current position. */
+ printf("--> Getting the current position: %d\r\n", position); /* Printing to the console. */
wait_ms(DELAY_1);
- /* Getting the current position. */
- int position = motors[0]->get_position();
+ printf("--> Moving forward %d steps.\r\n", STEPS_1); /* Printing to the console. */
+ motors[1]->move(StepperMotor::FWD, STEPS_1); /* Moving. */
- /* Printing to the console. */
- printf("--> Getting the current position: %d\r\n", position);
- /* Waiting. */
- wait_ms(DELAY_1);
+ motors[1]->wait_while_active(); /* Waiting while active. */
- /* Printing to the console. */
- printf("--> Moving forward %d steps.\r\n", STEPS_1);
- /* Moving. */
- motors[0]->move(StepperMotor::FWD, STEPS_1);
-
- /* Waiting while active. */
- motors[0]->wait_while_active();
+ wait(1);
+ motors[1]->move(StepperMotor::BWD, STEPS_1); /* Moving. */
+ motors[1]->wait_while_active(); /* Waiting while active. */
+
+ wait(10);
/* Getting the current position. */
- position = motors[0]->get_position();
+ position = motors[1]->get_position();
/* Printing to the console. */
printf("--> Getting the current position: %d\r\n", position);
@@ -191,7 +174,7 @@
printf("--> Marking the current position.\r\n");
/* Marking the current position. */
- motors[0]->set_mark();
+ motors[1]->set_mark();
/* Waiting. */
wait_ms(DELAY_1);
@@ -200,10 +183,10 @@
printf("--> Moving backward %d steps.\r\n", STEPS_2);
/* Moving. */
- motors[0]->move(StepperMotor::BWD, STEPS_2);
+ motors[1]->move(StepperMotor::BWD, STEPS_2);
/* Waiting while active. */
- motors[0]->wait_while_active();
+ motors[1]->wait_while_active();
/* Waiting. */
wait_ms(DELAY_1);
@@ -221,16 +204,16 @@
printf("--> Going to marked position.\r\n");
/* Going to marked position. */
- motors[0]->go_mark();
+ motors[1]->go_mark();
/* Waiting while active. */
- motors[0]->wait_while_active();
+ motors[1]->wait_while_active();
/* Waiting. */
wait_ms(DELAY_1);
/* Getting the current position. */
- position = motors[0]->get_position();
+ position = motors[1]->get_position();
/* Printing to the console. */
printf("--> Getting the current position: %d\r\n", position);
@@ -242,16 +225,16 @@
printf("--> Going to home position.\r\n");
/* Going to home position. */
- motors[0]->go_home();
+ motors[1]->go_home();
/* Waiting while active. */
- motors[0]->wait_while_active();
+ motors[1]->wait_while_active();
/* Waiting. */
wait_ms(DELAY_1);
/* Getting the current position. */
- position = motors[0]->get_position();
+ position = motors[1]->get_position();
/* Printing to the console. */
printf("--> Getting the current position: %d\r\n", position);