Posture regulating device and method for leek cutting tool facing convex-concave varied terrain

CN122804609APending Publication Date: 2026-09-25ANHUI AGRICULTURAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611166162.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-09-25

AI Technical Summary

Technical Problem

土坡对于韭菜切割质量及刀具的耐久性具有重要影响,但是从目前已发表的文献、授权的专利以及市场上现有的韭菜收割机来看,尚未有针对韭菜收割机在凸凹多变地形下实现切割刀具的姿态调控的装置设计

Benefits of technology

[0049]1)通过温度传感器补偿超声波声速误差,相较于部分只采用超声波传感器的现有调高机构,弥补韭菜跨季节收割温差大导致超声波声速变化的情况,提升地形适应精度,实现韭菜收割机全季节稳定作业,以及不同环境温度下刀具对土坡跨越的精准调控。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122804609A_ABST
    Figure CN122804609A_ABST
Patent Text Reader

Abstract

The application discloses a posture control device and method of leek cutting tools for convex-concave variable terrains, and the method comprises the following steps: S1, writing a code of a single-chip microcomputer for controlling sensors and actuators; S2, controlling an ultrasonic sensor to detect the height of a soil slope, and calculating the current sound velocity by means of the environment temperature collected by a temperature sensor in real time, so as to compensate for the measurement error of the ultrasonic sensor; S3, calculating the number of steps of a stepping motor required for lifting the tool, and sequentially calling the stepping motor drive to execute the posture by the single-chip microcomputer, so as to complete the smooth crossing of the tool to the soil slope. The application can not only provide a theoretical basis for the posture control of the leek cutting tools for the convex-concave variable terrains, but also provide a reference and a train of thought for the intelligent detection of the soil slope height by the leek cutting tools and the realization of the smooth crossing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of agricultural machinery and automation control technology, specifically to a posture control device and method for leek cutting tools oriented towards uneven and varied terrain. Background Technology

[0002] In current leek harvesting, the terrain of leek-growing areas is often uneven, and harvesting requires speed, flatness, and evenness. Traditional leek cutters often lack intelligent response when facing protruding slopes, leading to accelerated blade wear and inconsistent cutting quality. With the development of intelligent agricultural machinery, the operating precision and terrain adaptability of leek harvesters are receiving increasing attention. Slopes have a significant impact on the cutting quality and blade durability, but based on currently published literature, authorized patents, and existing leek harvesters on the market, there is still no design for a device to control the cutting blade posture in leek harvesters with varying terrain.

[0003] Research on the attitude control of chive cutting blades for smooth and even cutting in undulating terrain not only helps to improve blade life and chive harvesting quality, but also provides theoretical basis and technical support for attitude control of agricultural machinery for other crops in complex terrain. Summary of the Invention

[0004] The purpose of this invention is to provide a posture control device and method for leek cutting blades facing uneven terrain, aiming to improve the adaptability of leek harvesters in uneven terrain, ensure the stability and uniformity of cutting, and provide theoretical and technical support for the slope crossing control of agricultural machinery for other crops in the future.

[0005] In one aspect of the invention, a posture control device for a chive cutting tool oriented towards uneven terrain is provided, wherein the tool is mounted on the output shaft of a drive motor. According to an embodiment of the invention, the device includes:

[0006] Actuators, sensors, and microcontrollers;

[0007] The actuator is used to move the tool vertically, and the actuator includes a stepper motor, which is used to drive the tool to move.

[0008] The sensors include a temperature sensor and an ultrasonic sensor. The ultrasonic sensor is fixedly installed on the crossbeam at the front of the leek harvester from a top-down angle. The temperature sensor is installed on the microcontroller, specifically via DuPont wires.

[0009] The microcontroller is electrically connected to the actuator and the sensor respectively.

[0010] In addition, the posture control device for a chive cutting knife facing uneven terrain according to the above embodiments of the present invention may also have the following additional technical features:

[0011] In some embodiments of the present invention, the actuator further includes an upper slide rail, a lower slide rail, a first inclined rod, and a second inclined rod;

[0012] An upper slider is slidably mounted on the upper slide rail, and a lead screw is rotatably mounted on the upper slide rail. One end of the lead screw is connected to the output shaft of the stepper motor, and the lead screw passes through the upper slider and is connected to the upper slider by a thread.

[0013] A lower slider is slidably mounted on the lower slide, the drive motor is fixed on the lower slide, and the output shaft of the drive motor is fixed to the cutter.

[0014] The two ends of the first inclined rod are respectively hinged to the upper slider and the lower slide, and the two ends of the second inclined rod are respectively hinged to the upper slide and the lower slider. The first inclined rod and the second inclined rod are hinged together.

[0015] In another aspect, the present invention proposes a method for posture control of a chive cutting tool accommodating varied terrain. According to an embodiment of the present invention, the method includes the following steps:

[0016] S1. Write code for a microcontroller to control sensors and actuators;

[0017] S2. Control the ultrasonic sensor to detect the height of the slope, and at the same time calculate the current sound velocity by collecting the ambient temperature in real time through the temperature sensor to compensate for the measurement error of the ultrasonic sensor.

[0018] S3. Calculate the number of stepper motor revolutions required for the actuator to lift the tool. The microcontroller sequentially calls the stepper motor to drive the execution posture, completing the tool's smooth crossing of the slope.

[0019] In addition, the posture control method for a chive cutting tool oriented towards uneven terrain according to the above embodiments of the present invention may also have the following additional technical features:

[0020] In some embodiments of the present invention, step S1, which involves writing the code for the microcontroller to control the sensor and actuator, includes the following steps:

[0021] S101, Set program initialization parameters;

[0022] S102, Set the code for temperature sensor to compensate for ultrasonic sensor measurement error;

[0023] S103. Set the execution state switching code, which is achieved by calling the motor drive function in the main function in the order of forward, lift, obstacle crossing, and descent. After each function is executed, it will automatically return, and the program will sequentially enter the next posture.

[0024] S104. Set the loop code.

[0025] In some embodiments of the present invention, the method for setting program initialization parameters in step S101 is as follows:

[0026] a. Set the installation height of the ultrasonic sensor;

[0027] b. Set the K value for PID control p K i K d Three parameters, among which, K p The proportionality coefficient, K, is the response to the current error. p A larger value indicates a faster response, but also more oscillations. K p A smaller value results in a slower response, but greater stability; K i The integral coefficient refers to the summation of past errors to eliminate steady-state errors; K i A large value accelerates error elimination but may lead to integral saturation; K d The differential coefficient. Predicting future errors;

[0028] c. Set the installation angle of the ultrasonic sensor to 45°;

[0029] d. Set attitude switching parameters, including motor running speed, attitude delay, and stabilization delay after lifting;

[0030] e. Set the initial running state to 0.

[0031] In some embodiments of the present invention, the method for establishing the temperature sensor compensation for the measurement error of the ultrasonic sensor in step S102 is as follows:

[0032] a. Read the current ambient temperature using a temperature sensor;

[0033] b. Calculate the ultrasonic velocity at the current temperature.

[0034] In some embodiments of the present invention, the execution state switching code is set in step S103 as follows:

[0035] a. Attitude 1: The tool moves forward normally, corresponding to the forward rotation of the front drive motor in the function Motor2_Run(1,MOTOR2_PULSE_PER_REV, SPEED2). Here, MOTOR2_PULSE_PER_REV refers to the number of pulses per revolution of the front drive motor, SPEED2 refers to the speed of the front drive motor, and the front drive motor refers to the motor that drives the leek cutter forward. This function uses a blocking loop to output pulses. The function returns, indicating that attitude 1 has been executed.

[0036] b. Posture 2: Tool lifting, corresponding to the stepper motor forward rotation function Motor_Run(dir,steps,Speed1), where dir refers to the rotation direction of the stepper motor, Speed1 refers to the speed of the stepper motor, steps is the number of pulses per revolution of the stepper motor, and steps is calculated by the ultrasonic sensor ranging result and the sound speed after temperature compensation through a geometric model. This function uses PID control to achieve smooth lifting, and the function returns to indicate that the lifting action is completed;

[0037] c. Attitude 3: Tool crossing obstacle, corresponding to the forward rotation of the front drive motor in the function Motor2_Run(1, MOTOR2_PULSE_PER_REV, SPEED2), where MOTOR2_PULSE_PER_REV refers to the number of pulses per revolution of the front drive motor and SPEED2 refers to the speed of the front drive motor. The tool moves forward and crosses the slope in the raised attitude. The function returns to indicate that the obstacle crossing is completed.

[0038] d. Attitude 4: The tool descends, corresponding to the stepper motor reversal descent function Motor_Run(rev_dir,steps,Speed1), where rev_dir is the reverse of the stepper motor rotation direction in attitude 2, the number of steps is the same as in attitude 2, the tool descends to the initial height, and the function returns, indicating that the action is complete.

[0039] In some embodiments of the present invention, the steps for writing state switching code for each posture are as follows:

[0040] a. First, write the enable code GPIO_SetBits (GPIOB, GPIO_Pin_5) for state 1; then write the function call Motor2_Run (1, MOTOR2_PULSE_PER_REV, SPEED2); next, write the disable code GPIO_ResetBits (GPIOB, GPIO_Pin_5), where GPIOB and GPIO_Pin_5 refer to the P5 pin in area B of the microcontroller; then write the delay function Delay_ms (STEP_DELAY_MS), where STEP_DELAY_MS refers to the inter-attitude delay;

[0041] b. Next, write the enable code GPIO_SetBits(GPIOA, GPIO_Pin_5) for state 2, where GPIOA and GPIO_Pin_5 refer to pin P5 in area A of the microcontroller; then write the function call Motor_Run(dir, steps, SPEED1); next, write the disable code GPIO_ResetBits(GPIOA, GPIO_Pin_5); then write the delay function Delay_ms(DELAY_AFTER_LIFT_MS), where DELAY_AFTER_LIFT_MS refers to the delay after the lift-off.

[0042] c. Write the enable code GPIO_SetBits(GPIOB, GPIO_Pin_5) for state 3; then write the function call Motor2_Run(1, MOTOR2_PULSE_PER_REV, SPEED2), where MOTOR2_PULSE_PER_REV refers to the number of pulses per revolution of the front drive motor, and SPEED2 refers to the speed of the front drive motor; next, write the disable code GPIO_ResetBits(GPIOB, GPIO_Pin_5); and then write the delay function Delay_ms(STEP_DELAY_MS);

[0043] d. Finally, write the direction inversion code for state 4: rev_dir = (dir == 1), and the enable code: GPIO_SetBits (GPIOA, GPIO_Pin_5); then write the function call: Motor_Run (rev_dir, steps, SPEED1), where rev_dir indicates that the stepper motor is reversed, steps indicates the number of pulses per revolution of the stepper motor, and SPEED1 indicates the speed of the stepper motor; then write the disable code: GPIO_ResetBits (GPIOA, GPIO_Pin_5).

[0044] In some embodiments of the present invention, step S2, in which the ultrasonic sensor detects the height of the slope, includes the following steps:

[0045] S201. Mount the ultrasonic sensor onto the frame at a 45° downward angle;

[0046] S202. After the ultrasonic sensor measures the oblique distance between itself and the slope, it sends the data to the microcontroller.

[0047] S203. The microcontroller calculates the slope height based on the installation height, installation angle, and oblique distance of the ultrasonic sensor.

[0048] Compared with the prior art, the beneficial effects of the present invention are:

[0049] 1) By compensating for ultrasonic velocity errors through temperature sensors, compared to some existing height adjustment mechanisms that only use ultrasonic sensors, this compensates for the large temperature differences during the seasonal harvesting of leeks that cause changes in ultrasonic velocity, improves terrain adaptability, enables stable operation of the leek harvester throughout the season, and allows for precise control of the blades' crossing of slopes under different ambient temperatures.

[0050] 2) The STM32 microcontroller is used as the main control unit of the entire control system. Its cost is lower than that of similar control chips. At the same time, it has powerful complex instruction processing capabilities and can efficiently complete the multi-step control task of cutting the leeks neatly across the slope. This reduces the overall cost while improving the system performance.

[0051] 3) A stepper motor combined with a lead screw converts the motor's rotational motion into the linear motion of the cutting tool. Combined with forward and reverse control, this achieves precise lifting and lowering of the tool. Compared to the hydraulic valves used in existing leek cutters, it offers advantages such as smaller size, higher precision, and more stable control, enabling flexible and smooth adjustment of the leek harvester's cutting tool. The structure of fixing the tool at both ends of the lead screw improves the tool's stability compared to the single-end direct control of the tool by a hydraulic valve, ensuring the tool remains level and the cut surface is neat during the cutting process.

[0052] 4) The ultrasonic sensor and blade combination scheme, compared with the commonly used contact-type contour plate leek harvester blade crossing the slope, realizes intelligent control of the blade posture according to the ground slope height, and has excellent flexibility and maneuverability. The ultrasonic sensor can detect the slope height in advance and reserve enough time for the blade to rise, effectively avoiding the blade from colliding with the slope, extending the service life of the cutting blade, and reducing the maintenance costs caused by frequent blade replacement. Attached Figure Description

[0053] Figure 1 This is a schematic diagram of the posture control device for a chive cutting tool that is oriented towards uneven terrain in Embodiment 1 of the present invention.

[0054] Figure 2 This is a wiring diagram of the posture control device for a chive cutting tool that is oriented towards uneven terrain in Embodiment 1 of the present invention.

[0055] Figure 3 This is a schematic diagram of the tool height adjustment structure in Embodiment 2 of the present invention;

[0056] Figure 4 This is a schematic diagram of the Simulink simulation in Embodiment 2 of the present invention;

[0057] Figure 5This is the PID control graph output in the Simulink simulation of Embodiment 2 of the present invention;

[0058] In the diagram, 1. Cutting tool, 2. Stepper motor, 3. Lead screw, 4. Upper slider, 5. Diagonal bar one, 6. Lower slide rail, 7. Lower slider, 8. Ultrasonic sensor, 9. Temperature sensor, 10. Microcontroller, 11. Motor driver, 12. Power adapter, 13. Upper slide rail, 14. Diagonal bar two, 15. Drive motor. Detailed Implementation

[0059] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0060] Example 1

[0061] like Figure 1-2 As shown, a posture control device for a chive cutting knife designed for uneven terrain includes an actuator, a sensor, a microcontroller 10, and a power adapter 12.

[0062] The actuator is used to move the cutter 1 vertically. The actuator includes an upper slide rail 13, a lower slide rail 6, a first inclined rod 5, and a second inclined rod 14. The upper slide rail 13 is fixed to the rear end of the front crossbeam of the leek cutter. An upper slider 4 is slidably mounted on the upper slide rail 13, and a lead screw 3 is rotatably mounted on the upper slide rail 13. One end of the lead screw 3 is connected to the output shaft of the stepper motor 2. The lead screw 3 passes through the upper slider 4 and is threadedly connected to the upper slider 4. A lower slider 7 is slidably mounted on the lower slide rail 6. A drive motor 15 is fixedly mounted on the lower slide rail 6, and the cutter 1 is fixed to the output shaft of the drive motor 15. The two ends of the first inclined rod 5 are hinged to the upper slider 4 and the lower slide rail 6, respectively. The two ends of the second inclined rod 14 are hinged to the upper slide rail 13 and the lower slider 7, respectively. The first inclined rod 5 and the second inclined rod 14 are arranged crosswise and are movably connected by a pin. The first inclined rod 5 and the second inclined rod 14 constitute a scissor linkage mechanism. Stepper motor 2 can drive lead screw 3 to rotate, and lead screw 3 in turn drives upper slider 4 to move along upper slide rail 13. Since one end of inclined rod 1 5 and inclined rod 2 14 are in a state of immobility, the distance between inclined rod 1 5 and inclined rod 2 14 will change during the sliding process of upper slider 4, thereby achieving the purpose of lowering slide rail 6 and tool 1 height.

[0063] The sensors include a temperature sensor 9 and an ultrasonic sensor 8. The ultrasonic sensor is fixedly mounted on the front crossbeam of the leek cutter at a top-down angle. The temperature sensor is mounted on the STM32 microcontroller 10 via DuPont wires. Specifically, the VCC pin of the ultrasonic sensor 8 is connected to the 5V of the STM32 microcontroller 10, the GND pin is connected to the negative terminal of the STM32 microcontroller 10, the Trig pin is connected to the A0 pin of the STM32 microcontroller 10, and the Echo pin is connected to the A1 pin of the STM32 microcontroller 10. The VCC pin of the temperature sensor 9 is connected to the positive terminal of the STM32 microcontroller 10, the GND pin is connected to the negative terminal of the STM32 microcontroller 10, and the DAT pin is connected to the B9 pin of the STM32 microcontroller 10.

[0064] The stepper motor 2, motor driver 11, power adapter 12, and STM32 microcontroller 10 can be connected using either a common anode or common cathode connection, corresponding to active low and active high levels, respectively. This embodiment uses the common cathode connection. The specific steps are as follows: Connect the motor driver 11 to the power adapter 12, connecting the positive terminal of the power adapter 12 to VCC and the negative terminal to GND. The adapter converts AC power into the required DC power. The motor driver 11's A... + A - B + B - The interface is connected to phases A and B of stepper motor 2 respectively. The PUL of motor driver 11... + and PUL - It is responsible for receiving pulse signals to control the stepping of stepper motor 2. In this embodiment, the PUL of motor driver 11... + Connect to the STM32's PWM output pin B0, PUL - Grounding. DIR + and DIR - Controls the motor's direction of rotation. DIR + Connect to STM32's GPIO output pin B1, DIR - Grounding.

[0065] Working principle: When the leek harvester is working, the temperature sensor 9 collects the current temperature information and feeds it back to the STM32 microcontroller 10 to calculate the current sound speed. The ultrasonic sensor 8 collects the time it takes for the sound speed to travel from the detected slope to the return point and feeds it back to the STM32 microcontroller 10. The STM32 microcontroller 10 combines the sound speed and time to calculate the change in ground height and outputs a PWM waveform with a corresponding idle ratio, thereby controlling the direction and speed of the stepper motor 2, so that the leek harvester can raise the slope to the appropriate height according to the different slope heights.

[0066] Example 2

[0067] A method for controlling the posture of a chive cutting tool accommodating uneven terrain, using the control device described in Example 1, specifically includes the following steps:

[0068] 1. STM32 microcontroller control sensor code structure and actuator code process

[0069] (1.1) Write the following files into the STM32 microcontroller 10 using Keil5 software: dht22.h / dht22.c, hc_sr04.h / hc_sr04.c, delay.h / delay.c, motor.h / motor.c, motor2.h / motor2.c, and main control file main.c.

[0070] The code structure adopts a modular design, with each sensor corresponding to an independent driver file. The functions of each file are as follows:

[0071] dht22.h / dht22.c: Responsible for the initialization and data reading of the DHT22 temperature sensor 9, including three core functions: DHT22_Init(void), DHT22_Read (void), and DHT22_GetSoundSpeed ​​(void). Here, void indicates that no external input parameters are required.

[0072] hc_sr04.h / hc_sr04.c: Responsible for the initialization and ranging of the HC-SR04 ultrasonic sensor 8, including three core functions: HC-SR04_Iint (void), HCSR04_GetDistance (void), and HCSR04_GetDistanceWithTemp (sound_speed). Among them, sound_speed refers to the speed of sound of the ultrasonic sensor after temperature correction.

[0073] delay.h / delay.c: This file is responsible for providing microsecond and millisecond-level delay functions, including Delay_us (xus) and Delay_ms (xms), which provide precise delays for sensor timing control and main loop measurement intervals. Here, xus refers to the microsecond-level delay parameter, which is the motor speed, and xms refers to the millisecond-level delay parameter, which is the mechanical waiting in the process state.

[0074] motor.h / motor.c: Responsible for the drive control of the stepper motor, containing two core functions: Motor_Init (void) and Motor_Run (dir, steps, speed);

[0075] motor2.h / motor2.c: Responsible for the drive control of the front drive motor, containing two core functions: Motor2_Init (void) and Motor2_Run (dir, steps, speed);

[0076] main.c: The program's entry point file, responsible for calling the initialization functions of each module and executing the main logic of terrain detection, height calculation, and state switching.

[0077] (1.2) The program initialization parameters are set uniformly at the beginning of the main function, and the method for setting them is as follows:

[0078] a. Set the sensor's installation height in the code. The installation height of the ultrasonic sensor is set at the beginning of the code using the macro definition `INSTALL_HEIGHT`. In this example, it is set to 27.5cm. This value represents the vertical installation height of the sensor relative to the initial position of the tool, and is used as a reference parameter in subsequent slope height calculations. Specifically, add the macro definition `#define INSTALL_HEIGHT 27.5f` at the beginning of `main.c`.

[0079] b. Set the three parameters Kp, Ki, and Kd for PID control in the code. In this example, they are set to 1.5, 0.01, and 0.2 respectively. Reserve the PID parameter interface in the form of macro definitions: #define KP 1.5f, #define KI 0.01f, #define KD 0.2f.

[0080] c. Set the ultrasonic sensor installation angle in the code. Set the ultrasonic sensor's tilt angle at the beginning of the code using the macro definition ULTRASONIC_ANGLE. In this embodiment, it is set to 45°. Specifically, add the macro definition #define ULTRASONIC_ANGLE 45.0f at the beginning of main.c.

[0081] d. All attitude switching related parameters are declared in the code header through macro definitions, including pulses per revolution (PULSE_PER_REV), which is set to 3200 pulses / revolution for the front drive motor in this embodiment; motor speed (SPEED_US), which is set to 600μs for the stepper motor driver pulse signal and 450μs for the front drive motor driver pulse signal in this embodiment; attitude delay (STEP_DELAY_M), which is set to 500ms in this embodiment for mechanical stability waiting during adjacent attitude switching; and stability delay after lifting (DELAY_AFTER_LIFT_MS), which is set to 800ms in this embodiment for additional stability waiting after lifting into position.

[0082] e. Define a global variable `current_state` in the `main` function and initialize it to 0, indicating that the system is in an initial idle state. During attitude switching, this variable records the current execution stage, facilitating program flow control and state tracking.

[0083] (1.3) Temperature sensor code establishment: The DHT22 temperature sensor 9 adopts a single-bus communication protocol, and the STM32 microcontroller 10 communicates bidirectionally with the temperature sensor 9 through a GPIO pin, which in this embodiment uses PB8. The implementation logic of the driver code is as follows:

[0084] The DHT22_Init (void) function configures the data pin to open-drain output mode and pulls it high to put the bus in an idle state.

[0085] The DHT22_Read (void) function performs a complete temperature data read, which includes the following steps:

[0086] a. Start signal: The STM32 microcontroller pulls the data pin low for 18ms, then pulls it high for 40μs, and then waits for the DHT22 to respond;

[0087] b. Response detection: After receiving the start signal, the DHT22 will pull the data pin low for 80μs as a response signal, and then pull it high for 80μs to prepare for data transmission;

[0088] c. Data reading: The DHT22 continuously outputs 40 bits of data. Each data bit is represented by a 50μs low level duration plus a high level duration. A high level lasting 26-28μs represents "0", and a high level lasting 70μs represents "1".

[0089] d. Verification: The STM32 microcontroller sums the first 32 bits of the received data and compares it with the checksum of bits 33-40. If they are equal, the data is valid; otherwise, the result of this reading is discarded.

[0090] e. Data conversion: Convert 16-bit temperature data to floating-point numbers. Temperature value = high-order temperature digit × 256 + low-order temperature digit, then divide by 10 to get the actual temperature value.

[0091] The DHT22_GetSoundSpeed ​​(void) function calls DHT22_Read (void) to obtain the current ambient temperature and calculates the speed of sound at the current temperature based on the relationship between the speed of sound in the air v and the temperature T: v = 331.4 + 0.607×T (m / s).

[0092] (1.4) The HC-SR04 ultrasonic sensor 8 is triggered for ranging via the Trig pin and outputs an echo signal via the Echo pin. The STM32 microcontroller 10 controls Trig via one GPIO pin (PB6 in this embodiment) and reads the Echo signal via another GPIO pin (PB7 in this embodiment), and uses the TIM2 timer to accurately measure the high-level duration of the echo signal. The implementation logic of the driver code is as follows:

[0093] The HCSR04_Init (void) function configures the Trig pin to push-pull output mode, the Echo pin to floating input mode, initializes the TIM2 timer, sets the prescaler to 71, the counting frequency to 1MHz, the auto-reload value to 65535, and enables the timer update interrupt.

[0094] The HCSR04_GetDistanceWithTemp(sound_speed) function performs a complete ultrasonic ranging operation, including the following steps:

[0095] a. Trigger ranging: The STM32 microcontroller sends a high-level pulse lasting more than 10μs to the Trig pin, triggering the ultrasonic sensor 8 to emit 8 cycles of 40kHz ultrasonic signals;

[0096] b. Waiting for an echo: The STM32 microcontroller detects the level change of the Echo pin. When the Echo pin changes from low to high, it indicates that the ultrasonic wave has been emitted. At this time, the TIM2 timer is started to start counting.

[0097] c. End of timing: When the Echo pin changes from high to low, it indicates that the ultrasound has returned. At this time, stop the TIM2 timer and read the timer count value.

[0098] d. Distance calculation: Based on the timing value t and the incoming sound speed v, calculate the distance L from the sensor to the target object = v × t / 2.

[0099] (1.5) Following the sensor code, write the calling code for the four motor drive functions in the order of forward, lift, obstacle crossing, and descent. The specific steps are as follows:

[0100] a. First, write the enable code GPIO_SetBits (GPIOB, GPIO_Pin_5) for state 1; then write the function call Motor2_Run (1, MOTOR2_PULSE_PER_REV, SPEED2); next, write the disable code GPIO_ResetBits (GPIOB, GPIO_Pin_5), where GPIOB and GPIO_Pin_5 refer to the P5 pin in area B of the microcontroller; then write the delay function Delay_ms (STEP_DELAY_MS), where STEP_DELAY_MS refers to the inter-attitude delay;

[0101] b. Next, write the enable code GPIO_SetBits(GPIOA, GPIO_Pin_5) for state 2, where GPIOA and GPIO_Pin_5 refer to pin P5 in area A of the microcontroller; then write the function call Motor_Run(dir, steps, SPEED1); next, write the disable code GPIO_ResetBits(GPIOA, GPIO_Pin_5); then write the delay function Delay_ms(DELAY_AFTER_LIFT_MS), where DELAY_AFTER_LIFT_MS refers to the delay after the lift-off.

[0102] c. Write the enable code GPIO_SetBits(GPIOB, GPIO_Pin_5) for state 3; then write the function call Motor2_Run(1, MOTOR2_PULSE_PER_REV, SPEED2), where MOTOR2_PULSE_PER_REV refers to the number of pulses per revolution of the front drive motor, and SPEED2 refers to the speed of the front drive motor; next, write the disable code GPIO_ResetBits(GPIOB, GPIO_Pin_5); and then write the delay function Delay_ms(STEP_DELAY_MS);

[0103] d. Finally, write the direction inversion code for state 4: rev_dir = (dir == 1), and the enable code: GPIO_SetBits (GPIOA, GPIO_Pin_5); then write the function call: Motor_Run (rev_dir, steps, SPEED1), where rev_dir indicates that the stepper motor is reversed, steps indicates the number of pulses per revolution of the stepper motor, and SPEED1 indicates the speed of the stepper motor; then write the disable code: GPIO_ResetBits (GPIOA, GPIO_Pin_5).

[0104] (1.6) After all the code is executed, set all motor enable pins to low level, so that the whole system is in the completed state of disabling protection. Write an infinite loop while(1) at the end of the main function.

[0105] 2. Control the ultrasonic sensor to detect the slope height

[0106] (2.1) The ultrasonic sensor is fixedly mounted on the frame at a 45° downward angle, with a mounting height of H. The sound beam emitted by the ultrasonic sensor forms a 45° angle with the horizontal plane. The current sound velocity is calculated by real-time acquisition of the ambient temperature by the temperature sensor to compensate for the measurement error of the ultrasonic sensor. Then, the distance L from the ultrasonic sensor to the slope is calculated using the sound velocity (see steps 1.3 and 1.4 for details). Therefore, the required lifting height of the cutter 1 is ∆H = HL × sin45°.

[0107] (2.2) As Figure 3 As shown, the initial vertical distance between the lead screw 3 and the slide rail 6 is... 1. After the cutter 1 is raised by ∆H, the vertical distance between the lead screw 3 and the slide rail 6 is... 2. The distance from the center point O of diagonal bar one and diagonal bar two to any end of the diagonal bar is... 0, This embodiment 0 is 0.1m. Initially, the angle between the sliding track 6 and the inclined bar 1 is θ1. After the tool is lifted, the angle between the sliding track 6 and the inclined bar 1 is θ2.

[0108] (2.3) As can be seen from step (2.2), 2= 1-∆H, 2 = 2 × 0sinθ2, 1 = 2 × 0sinθ1, simplifying, we can obtain the tool head lifting ∆H, and the distance the upper slider 4 moves is... .

[0109] (2.4) The formula for calculating the movement distance of the upper slider 4 is as follows: In the formula, N is the number of revolutions of the lead screw, and P is the lead of the lead screw. Combining with step (2.3), it can be seen that for the tool 1 to lift ∆H, the stepper motor 2 needs to control the lead screw 3 to rotate a certain number of revolutions. .

[0110] 3. Actuator control and attitude switching

[0111] (3.1) The STM32 microcontroller 10 is connected to the motor driver 11, and the stepper motor 2 is connected to the motor driver 11.

[0112] (3.2) The driving code for stepper motor 2 adopts a modular design, including initialization functions and running functions. Its structure and implementation logic are as follows:

[0113] (3.2.1) The motor initialization function is responsible for configuring the microcontroller's GPIO pins to adapt to the control requirements of the stepper motor driver. First, the clock of the corresponding GPIO port is enabled, and then the pulse pin PUL, the direction pin DIR, and the enable pin ENA are all configured as push-pull output mode, with the output speed set to 50MHz.

[0114] Since the JTAG debugging function is occupied by default, the JTAG function needs to be disabled during initialization by calling GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE), thus freeing up these two pins for use as ordinary GPIOs. After initialization, the pulse pin is set to low level, and the direction pin and enable pin are set to high level, putting the stepper motor and front drive motor in a disabled state.

[0115] (3.2.2) The STM32 microcontroller 10 sends different levels to the DIR pin of the motor driver 11 through the GPIO pin to control the rotation direction of the motor. The STM32 microcontroller 10 sends a high level for forward rotation and a low level for reverse rotation. The motor driver 11 used in this embodiment is DM542. The specific steps are as follows:

[0116] First, set the direction pin level according to the direction parameters: low for forward rotation and high for reverse rotation. Then, set the enable pin high to enable the motor driver, preparing for pulse output. Pulse output is implemented using a for loop, with the loop count equal to the total number of pulses. Within each pulse cycle, the following steps are executed sequentially: pull the pulse pin high, delay for a few microseconds, pull the pulse pin low, and delay for a few microseconds again, completing the output of one full pulse. After all pulses have been sent, set the enable pin low to disable the motor driver.

[0117] (3.3) The STM32 microcontroller controls the attitude switching, specifically including the following steps:

[0118] (3.3.1) When the state is at state == 1, the enable pin of the front drive motor is configured to high level to enable the motor driver; then the Motor2_Run(1, MOTOR2_PULSE_PER_REV, SPEED2) function is called to drive the front drive motor to rotate forward at a preset speed. The function uses a for loop to output a specified number of pulses, and the pulse period is controlled by the SPEED2 parameter. After all pulses are sent, the function returns, the program sets the enable pin of the front drive motor to low level, and then calls Delay_ms(STEP_DELAY_MS) to enter the stable waiting between attitudes, so that the tool pauses briefly after the forward motion ends, and enters the next attitude after the inertial vibration of the mechanical system decays.

[0119] (3.3.2) When the attitude state == 2, the enable pin of the stepper motor is set to high level to enable the motor driver; then the Motor_Run(dir, steps, SPEED1) function is called to drive the stepper motor to rotate according to the number of steps calculated in (3.3.1). This function also uses a for loop to output pulses, and controls the lifting action smoothly throughout according to PID parameters. After all pulses are sent, the function returns, the program sets the enable pin of the stepper motor to low level, and then calls Delay_ms(DELAY_AFTER_LIFT_MS) to enter the stabilization waiting state after lifting.

[0120] (3.3.3) When the state is at state == 3, the front drive motor driver is re-enabled, and the Motor2_Run() function is called to drive the front drive motor to continue rotating forward while the tool maintains its raised posture. The tool travels forward at the raised height to complete the crossing of the slope. After the function returns, the front drive motor is disabled, and Delay_ms (STEP_DELAY_MS) is called to enter a stable waiting state.

[0121] (3.3.4) When the attitude state == 4, the direction parameter is reversed, causing the stepper motor to rotate in the opposite direction; the stepper motor driver is enabled; the Motor_Run(rev_dir, steps, SPEED1) function is called to drive the stepper motor to rotate in the opposite direction with the same number of steps as during lifting. The scissor linkage retracts, and the cutter smoothly descends from the lifting height to the initial height. After all pulses have been sent, the function returns, and the program sets the stepper motor enable pin to low level.

[0122] 4. Establish a PID control simulation in Simulink software.

[0123] (4.1) The Simulink simulation of the leek cutting tool for cutting the slope across the control device includes the SignalEditor simulation input height signal module, the PID Controller control module, the Transfer Fcn motor transfer function module, and the Scope waveform viewer module.

[0124] (4.2) such as Figure 4 As shown, the Signal Editor simulation input height signal module is connected to the PID Controller control module through the extract module, and the Transfer Fcn motor transfer function module is connected to the scope waveform viewer module and serves as feedback to the extract module through the Integrator module.

[0125] (4.3) The PID controller module includes K p K i K d Three parameters, K p K determines the system's response to the current error; too small a K p Slow response speed, excessively large K p This leads to overshooting of the control output, exceeding the target value; K i This determines the system's ability to make large corrections to long-term errors; an excessively large K... i Integral saturation occurs; K d The K value determines the system's response to the rate of change of error; an excessively large K value... d This leads to an excessive decrease in system response speed. The specific parameter determination steps are as follows:

[0126] First adjust K p , will K i and K d Set K to 0 and gradually increase it. i Adjust K only after the system responds quickly without excessive overshoot or oscillation. i Ki will increase the impact of error accumulation, until it does not exceed the expected value by too much, and finally K is adjusted. d This makes the system response smoother. For example... Figure 5 As shown, the optimal PID control parameter obtained in this embodiment is K. p =1.5, K i =0.01, K d =0.2, which conforms to the common stepper motor PID control K. p : 0.1-10.0, K d The parameter range is 0.01-1.0.

[0127] In this embodiment, the parameter settings for a method of adjusting the posture of a chive cutting tool for uneven terrain are shown in Tables 1 to 4.

[0128] Table 1. Stepper motor models and parameters used in this embodiment.

[0129] name 57HS64-3004 Step angle <![CDATA[1.8 ° ]]> Lead screw 5mm Screw length 165mm motor driver DM542

[0130] Table 2. Microcontroller models and parameters used in this embodiment.

[0131] model STM32F103C8T6 kernel ARM Cortex-M3 clock speed 72MHz RAM 20K ROM 64K powered by 2.0~3.6V Packaging LQFP48

[0132] Table 3. Model and parameters of the ultrasonic sensor used in this embodiment.

[0133] model HC-SR04 Operating voltage DC 5V Operating temperature -40~85℃ Detection range 2~600cm accuracy 3mm

[0134] Table 4. Temperature sensor models and parameters used in this embodiment.

[0135] model DHT22 Operating voltage DC 3.3~5.5V Operating temperature -40~80℃ accuracy 0.5℃

[0136] The above description is merely an example and illustration of the present invention. Those skilled in the art can make various modifications or additions to the specific embodiments described, or use similar methods to replace them, as long as they do not deviate from the structure of the present invention or exceed the scope defined in the claims, all of which should fall within the protection scope of the present invention.

Claims

1. A posture control device for a leek cutting tool oriented towards uneven terrain, wherein the tool is mounted on the output shaft of a drive motor, characterized in that: The device includes an actuator, a sensor, and a microcontroller; The actuator is used to move the tool vertically, and the actuator includes a stepper motor, which is used to drive the tool to move. The sensors include a temperature sensor and an ultrasonic sensor. The ultrasonic sensor is fixedly installed on the crossbeam at the front of the leek harvester from a top-down angle, and the temperature sensor is installed on the microcontroller. The microcontroller is electrically connected to the actuator and the sensor respectively.

2. The attitude control device for a chive cutting tool oriented towards uneven terrain as described in claim 1, characterized in that: The actuator also includes an upper slide rail, a lower slide rail, a first inclined rod, and a second inclined rod. An upper slider is slidably mounted on the upper slide rail, and a lead screw is rotatably mounted on the upper slide rail. One end of the lead screw is connected to the output shaft of the stepper motor, and the lead screw passes through the upper slider and is connected to the upper slider by a thread. A lower slider is slidably mounted on the lower slide, the drive motor is fixed on the lower slide, and the output shaft of the drive motor is fixed to the cutter. The two ends of the first inclined rod are respectively hinged to the upper slider and the lower slide, and the two ends of the second inclined rod are respectively hinged to the upper slide and the lower slider. The first inclined rod and the second inclined rod are hinged together.

3. The posture control method for a chive cutting tool oriented towards uneven terrain as described in claim 1 or 2, characterized in that, Includes the following steps: S1. Write code for a microcontroller to control sensors and actuators; S2. Control the ultrasonic sensor to detect the height of the slope, and at the same time calculate the current sound velocity by collecting the ambient temperature in real time through the temperature sensor to compensate for the measurement error of the ultrasonic sensor. S3. Calculate the number of stepper motor revolutions required for the actuator to lift the tool. The microcontroller sequentially calls the stepper motor to drive the execution posture, completing the tool's smooth crossing of the slope.

4. The posture control method for a chive cutting tool oriented towards uneven terrain as described in claim 3, characterized in that, In step S1, writing the code for the microcontroller to control the sensor and actuator includes the following steps: S101, Set program initialization parameters; S102, Set the code for temperature sensor to compensate for ultrasonic sensor measurement error; S103. Set the execution state switching code, which is achieved by calling the motor drive function in the main function in the order of forward, lift, obstacle crossing, and descent. After each function is executed, it will automatically return, and the program will sequentially enter the next posture. S104. Set the loop code.

5. The posture control method for a leek cutting tool oriented towards uneven terrain according to claim 4, characterized in that, In step S101, the program initialization parameters are set as follows: a. Set the installation height of the ultrasonic sensor; b. Set the K value for PID control p K i K d Three parameters, among which, K p K is the proportionality coefficient. i K is the integral coefficient. d These are the differential coefficients; c. Set the installation angle of the ultrasonic sensor to 45°; d. Set attitude switching parameters, including motor running speed, attitude delay, and stabilization delay after lifting; e. Set the initial running state to 0.

6. The posture control method for a chive cutting tool oriented towards uneven terrain according to claim 4, characterized in that, In step S102, the method for establishing the temperature sensor to compensate for the measurement error of the ultrasonic sensor is as follows: a. Read the current ambient temperature using a temperature sensor; b. Calculate the ultrasonic velocity at the current temperature.

7. The posture control method for a chive cutting tool oriented towards uneven terrain as described in claim 4, characterized in that, In step S103, the execution state switching code is set as follows: a. Attitude 1: The tool moves forward normally, corresponding to the forward rotation of the front drive motor in the function Motor2_Run(1,MOTOR2_PULSE_PER_REV, SPEED2). Here, MOTOR2_PULSE_PER_REV refers to the number of pulses per revolution of the front drive motor, SPEED2 refers to the speed of the front drive motor, and the front drive motor refers to the motor that drives the leek cutter forward. This function uses a blocking loop to output pulses. The function returns, indicating that attitude 1 has been executed. b. Posture 2: Tool lifting, corresponding to the stepper motor forward rotation function Motor_Run(dir,steps,Speed1), where dir refers to the rotation direction of the stepper motor, Speed1 refers to the speed of the stepper motor, steps is the number of pulses per revolution of the stepper motor, and steps is calculated by the ultrasonic sensor ranging result and the sound speed after temperature compensation through a geometric model. This function uses PID control to achieve smooth lifting, and the function returns to indicate that the lifting action is completed; c. Attitude 3: Tool crossing obstacle, corresponding to the forward rotation of the front drive motor in the function Motor2_Run(1, MOTOR2_PULSE_PER_REV, SPEED2), where MOTOR2_PULSE_PER_REV refers to the number of pulses per revolution of the front drive motor and SPEED2 refers to the speed of the front drive motor. The tool moves forward and crosses the slope in the raised attitude. The function returns to indicate that the obstacle crossing is completed. d. Attitude 4: The tool descends, corresponding to the stepper motor reversal descent function Motor_Run(rev_dir,steps,Speed1), where rev_dir is the reverse of the stepper motor rotation direction in attitude 2, the number of steps is the same as in attitude 2, the tool descends to the initial height, and the function returns, indicating that the action is complete.

8. The posture control method for a chive cutting tool oriented towards uneven terrain according to claim 7, characterized in that, The steps for writing code to switch states in each posture are as follows: a. First, write the enable code GPIO_SetBits(GPIOB, GPIO_Pin_5) for state 1; then write the function call Motor2_Run(1, MOTOR2_PULSE_PER_REV, SPEED2); next, write the disable code GPIO_ResetBits(GPIOB, GPIO_Pin_5), where GPIOB and GPIO_Pin_5 refer to the P5 pin in area B of the microcontroller; then write the delay function Delay_ms(STEP_DELAY_MS), where STEP_DELAY_MS refers to the inter-attitude delay; b. Next, write the enable code GPIO_SetBits(GPIOA, GPIO_Pin_5) for state 2, where GPIOA and GPIO_Pin_5 refer to pin P5 in area A of the microcontroller; then write the function call Motor_Run(dir, steps, SPEED1); next, write the disable code GPIO_ResetBits(GPIOA, GPIO_Pin_5); then write the delay function Delay_ms(DELAY_AFTER_LIFT_MS), where DELAY_AFTER_LIFT_MS refers to the delay after the lift-off. c. Write the enable code GPIO_SetBits(GPIOB, GPIO_Pin_5) for state 3; then write the function call Motor2_Run(1, MOTOR2_PULSE_PER_REV, SPEED2), where MOTOR2_PULSE_PER_REV refers to the number of pulses per revolution of the front drive motor, and SPEED2 refers to the speed of the front drive motor; next, write the disable code GPIO_ResetBits(GPIOB, GPIO_Pin_5); and then write the delay function Delay_ms(STEP_DELAY_MS); d. Finally, write the direction inversion code for state 4: rev_dir = (dir == 1), and the enable code GPIO_SetBits(GPIOA, GPIO_Pin_5); then write the Motor_Run(rev_dir, steps, SPEED1) function call, where rev_dir indicates that the stepper motor is reversed, steps indicates the number of pulses per revolution of the stepper motor, and SPEED1 indicates the stepper motor speed; then write the disable code GPIO_ResetBits(GPIOA, GPIO_Pin_5).

9. The posture control method for a leek cutting tool oriented towards uneven terrain according to claim 3, characterized in that, In step S2, the ultrasonic sensor detects the slope height by including the following steps: S201. Mount the ultrasonic sensor onto the frame at a 45° downward angle; S202. After the ultrasonic sensor measures the oblique distance between itself and the slope, it sends the data to the microcontroller. S203. The microcontroller calculates the slope height based on the installation height, installation angle, and oblique distance of the ultrasonic sensor.