Compare commits
2 Commits
7523e7096e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 610bff5e47 | |||
| c286c90928 |
@@ -76,6 +76,10 @@ void by_stepper_set_position_millimeter(float distance)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (distance > 170) {
|
||||||
|
distance = 170;
|
||||||
|
}
|
||||||
|
|
||||||
gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN
|
gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN
|
||||||
position_aim = (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER);
|
position_aim = (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER);
|
||||||
position_offset = position_aim - position;
|
position_offset = position_aim - position;
|
||||||
@@ -88,6 +92,9 @@ void by_stepper_add_position_millimeter(float distance)
|
|||||||
if (!running_flag) {
|
if (!running_flag) {
|
||||||
gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN
|
gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN
|
||||||
position_aim = position + (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER);
|
position_aim = position + (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER);
|
||||||
|
if (position_aim > 170 * ENCODER_PULSE_PER_MILLIMETER) {
|
||||||
|
position_aim = 170 * ENCODER_PULSE_PER_MILLIMETER;
|
||||||
|
}
|
||||||
position_offset = position_aim - position;
|
position_offset = position_aim - position;
|
||||||
running_flag = 1;
|
running_flag = 1;
|
||||||
}
|
}
|
||||||
@@ -116,12 +123,12 @@ void by_stepper_init(void)
|
|||||||
// DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
// DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
by_stepper_set_speed(STEPPER_SPEED_DIV4);
|
by_stepper_set_speed(STEPPER_SPEED_DIV1);
|
||||||
|
|
||||||
while (gpio_input_data_bit_read(GPIOB, GPIO_PINS_10) == SET) {
|
while (gpio_input_data_bit_read(GPIOB, GPIO_PINS_10) == SET) {
|
||||||
gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR
|
gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR
|
||||||
gpio_bits_write(GPIOB, GPIO_PINS_15, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_15)); // CLK
|
gpio_bits_write(GPIOB, GPIO_PINS_15, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_15)); // CLK
|
||||||
DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
DWT_Delay(30U * (uint16_t)by_stepper.speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
position = 0; // 位置归零
|
position = 0; // 位置归零
|
||||||
@@ -131,8 +138,7 @@ void by_stepper_init(void)
|
|||||||
|
|
||||||
LOGD("by_stepper init ok");
|
LOGD("by_stepper init ok");
|
||||||
|
|
||||||
by_stepper_set_dir(1);
|
by_stepper_set_position_millimeter(160.0f);
|
||||||
by_stepper_set_position_millimeter(-160.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void by_stepper_loop(void)
|
void by_stepper_loop(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user