From 610bff5e471e3a1b17606d5e2b5ba8fd9d498d25 Mon Sep 17 00:00:00 2001 From: bmy <2583236812@qq.com> Date: Tue, 9 Jul 2024 02:13:32 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E9=80=82=E5=BD=93=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/by_stepper.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/by_stepper.c b/app/by_stepper.c index 35fabc0..58a6497 100644 --- a/app/by_stepper.c +++ b/app/by_stepper.c @@ -76,6 +76,10 @@ void by_stepper_set_position_millimeter(float distance) return; } + if (distance > 170) { + distance = 170; + } + gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN position_aim = (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER); position_offset = position_aim - position; @@ -87,7 +91,10 @@ void by_stepper_add_position_millimeter(float distance) { if (!running_flag) { 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; running_flag = 1; } @@ -121,7 +128,7 @@ void by_stepper_init(void) 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(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; // 位置归零