Share this

Design of Motor Control System for Handling Robot Based on STM32F107

2026-04-06 06:05:49 · · #1

With the continuous rise in labor costs, replacing human labor with robots for repetitive and high-intensity tasks is an important direction in modern robotics research. In navigation and line-following, transport robots require the coordinated operation of the rear-wheel drive motor and the front-wheel servo motor. The motor drive of transport robots has specific application requirements, demanding high dynamic performance from the motor to ensure it can reach the designated position at any time and stop the servo motor at any angle. The motor drive also has a wide torque variation range, operating in both high-speed, low-torque environments on unloaded, flat roads and in full-load, hill-climbing conditions, while maintaining high operating efficiency. Based on these technical requirements, this paper selects a DC motor, with mature control technology and easy smooth speed adjustment, as the actuator of the transport robot.

1. System Hardware Design

1.1 Hardware Structure of Robot Motor Controller

The main controller uses an STM32F107 with a Cortex-M3 core. The controller has eight internal timers, of which TIM1_CH1 and TIM8_CH1 are high-level control timer pins. TIM1_CH1 is used for motor encoder counting, and TIM8_CH1 is used for servo control reference time. General-purpose timer pins TIM2_CH1, TIM3_CH1, TIM4_CH1, and TIM5_CH1 are used to generate PWM signals for the upper and lower bridge walls of the motor and servo drive circuits, respectively.

The PA0 and PB0 ports, which trigger the EXIT0 interrupt, are used for overcurrent interrupt protection of the motor and servo motor, respectively. The PA1 and PB1 ports, which trigger the EXIT1 interrupt, are used for limit protection on both sides of the servo motor. The motor drive circuit uses a bootstrap boost chip IR2103 and a MOSFET 75N75. The phase current of the rear wheel motor and servo motor is acquired and converted into voltage via constantan wire, amplified and filtered, and then sent to the A/D sampling pin ADC12_IN1 of the STM32F107 to achieve overcurrent protection. The forward and reverse rotation of the motor, speed, and direction of the servo motor are controlled by serial communication with the host computer or by speed setting in the STM32F107 internal program. (Hardware structure diagram of the motor control for the transport robot.)

1.2 Module Selection and Design

1.2.1 Design of Power Drive

The motor is powered by a 24V battery with a rated power of 240W, achieved through a bridge circuit composed of four 75N75 transistors. The 75N75 is a MOSFET power transistor with a maximum voltage rating of 75V and a maximum current rating of 75A, used in the motor drive circuit.

Q1 and Q4, and Q2 and Q3 form two bridge circuits, controlling the forward and reverse rotation of the motor respectively. When the high-side drive MOSFET is turned on, its source and drain voltages are the same and equal to the supply voltage VCC. Therefore, to achieve normal MOSFET driving, the gate voltage must be higher than VCC, requiring a dedicated boost converter chip, IR2103. The PWM signal generated by the controller is input to the HIN pin, and the controller I/O ports output EN1 and EN2 as enable signals. The output terminal HO receives a voltage higher than VCC, and this higher voltage is exactly the voltage across the capacitor. The diode improves the conduction speed, resulting in a lower on-resistance of the 75N75 transistor and reducing switching losses. Simultaneously, the two output ports HO and LO of the IR2103 have an interlock function to prevent short circuits caused by direct connection between the upper and lower bridge arms of the motor due to software or hardware errors.

1.2.2 Design of Overcurrent Protection

Installing overcurrent protection in a motor control system serves two purposes: firstly, it prevents overload or stalling of the motor during normal operation, which could lead to excessive armature winding current, damaging the motor or even causing a fire; secondly, because the starting current of a motor is very large during initial startup, it often cannot start directly. It requires waiting for the excitation winding to gradually establish a magnetic field before normal operation, while simultaneously aiming for the motor to start as quickly as possible. Overcurrent protection chopping the current allows for safe and rapid motor startup. The overcurrent protection principle diagram is shown in Figure 3.

The phase current of the motor is converted into a voltage signal Vtext through constantan wire. The analog signal AD1, after being amplified by an operational amplifier, is sent to the controller's A/D conversion module. At the same time, the digital signal EVA, after being compared by a voltage comparator, is sent to the controller's external interrupt port.

2. System Software Design

2.1 μC/OS-II Architecture

μC/OS-II is a portable, ROM-installable, customizable, preemptive real-time multitasking operating system kernel. It features high execution efficiency, small footprint, excellent real-time performance, and strong scalability; the smallest kernel can be compiled to 2KB. μC/OS-II is written in both C and assembly languages, with the vast majority of the code in C and only a small portion of processor-dependent code in assembly. μC/OS-II includes only basic functions such as task scheduling, task management, time management, memory management, and inter-task communication and synchronization.

2.2 Task allocation under μC/OS-II system

After successfully porting the μC/OS-II system to the STM32F107, μC/OS-II-based programming involves dividing a large application into multiple relatively independent tasks. The priority of each task is defined, and the μC/OS-II kernel schedules and manages these tasks.

The software design concept is that, based on the actual operational needs of the robot, the host computer provides the motor speed and servo motor rotation position via serial port. The motor speed is determined by comparing the set speed value with the value collected by the incremental encoder, and closed-loop control is achieved through a speed PID algorithm. The servo motor position is mainly fed back from the absolute encoder, and the servo motor rotation speed is adjusted according to the action time requirements. The functions to be implemented in the motor control system software of this handling robot are as follows:

◆The host computer provides the motor speed, servo rotation angle, and action time;

◆The motor speed is required to be continuously adjustable and have good static and dynamic performance. The speed is designed to be adjusted using a PI algorithm.

◆The servo motor is required to quickly reach the specified angle, with position feedback to adjust the given rotational speed of the servo motor;

◆ It has certain fault protection functions. When the motor stalls, the current is too high, or the servo motor triggers the limit switch, the drive module is required to stop working.

To achieve the above-mentioned functions, the application design can be divided into the following tasks:

① Start the task. Initialize the system, create the initial motor state, then delete itself and start the task to enter sleep mode.

② Motor and servo protection task. Used to respond to external interrupts when overcurrent or limit switch is activated. Entering interrupt state involves sending a task semaphore. The task program detects the validity of the semaphore and responds to the task, stopping output. Task priority is set to level 0.

③ Host computer-defined task. Used for host computer control of motors and servos, task priority is set to level 1. When the host computer inputs data to the register, an interrupt will be generated. This interrupt will send the received bytes into the buffer and release the semaphore of the host computer-defined task. When the semaphore is detected to be valid, the task will start execution, parse the corresponding byte information into the corresponding motor speed and servo angle position information, and assign values ​​to the corresponding variables.

④ Motor speed control task. Used for closed-loop speed regulation of the motor, with a task priority level of 2.

⑤ Servo control task. Used to control the servo to reach a designated position within a specified time. The task priority is set to level 3.

2.3 Start the task

In the main program, before calling other tasks of μC/OS-II, the system initialization function OSInit() is first called to initialize all variables and data structures of μC/OS-II; at the same time, the idle task OS_TaskIdle() is created, which is always in a ready state; the OSTaskCreate() function is called to create the startup task; and OSStart() is called to hand over control to the μC/OS-II kernel and start running multitasking.

The startup task is created in the main program and has three main functions:

① Used for system initialization (PWM output module, serial port, ADC module, input level interrupt function, timer).

② Establish the semaphores used by the system.

③ Other tasks related to establishing the system.

Finally, OSTaskDel(OS_PRIO_SELF) is called to self-delete, and the task starts and enters a sleep state. The main program task flow is shown in Figure 4.

2.4 Motor speed control task

Each time an incremental encoder generates an external interrupt, it issues a task semaphore in the interrupt state. The task program detects the validity of the semaphore and responds to the task. Closed-loop control is achieved by comparing the measured current motor speed with the given speed. The motor speed control task flow is shown in Figure 5.

2.5 Servo Control Task

The servo control uses a timer to generate a reference time and sends a semaphore at fixed intervals, executing the task once per interval. The servo control task compares the position measured by the absolute encoder with the given position and adjusts the servo's rotational speed based on the remaining time. The servo control task flow is shown in Figure 6.

3 System Electromechanical Interface

The robot's servo motor consists of a DC motor connected to a 30:1 reducer. An absolute position encoder is connected to the servo motor, sending the servo motor's angle signal to the driver control board. The two axles of the robot's front wheels are connected by a drive rod, and one of the axles is connected to the servo motor by a drive belt. When the servo motor rotates, the drive belt drives the drive rod, ensuring that the two front wheels rotate synchronously. The rear wheel drive motor is a DC motor, directly connected to an incremental encoder. After being reduced in speed by a 25:1 reducer, it drives the rear wheels to rotate via a mechanical differential. The signal from the incremental encoder is also sent to the driver control board. The electromechanical system structure is shown in Figure 7.

Conclusion

This paper presents the hardware design of the motor and servo controllers for a transport robot. The real-time operating system μC/OS-II was successfully embedded on an STM32F107 microcontroller, and closed-loop speed control experiments for the motors and servos were completed. Utilizing the multi-tasking and real-time capabilities of the Cortex-M3 core controller and the μC/OS-II system, a hardware and software foundation was provided for subsequent robot image and video acquisition and navigation tracking. If the existing PI algorithm is improved and dual closed-loop control of motor speed and current is achieved, the characteristics of the robot motor will be further enhanced, and the application prospects of the transport robot will be broadened.

Read next

CATDOLL 166CM Hanako TPE

Height: 166cm Weight: 37kg Shoulder Width: 36cm Bust/Waist/Hip: 76/63/85cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22