Share this

Application of multi-servo motor control in humanoid robots

2026-04-06 04:46:38 · · #1
Liang Feng, Wang Zhiliang, Xie Lun, and Xu Wenxue from the School of Information Engineering, Beijing University of Science and Technology

Servo controllers are crucial components of robots. A novel method for generating multiple PWM outputs for servo motor control using a microcontroller was developed. Utilizing the microcontroller's internal timer and time-division multiplexing technology, up to 24 PWM outputs were achieved without adding any hardware circuitry. This method replaces the traditional method of generating PWM waves using discrete components, significantly reducing the number of discrete components and circuit wiring, improving system reliability, and enhancing control accuracy. It has been successfully applied to the control system of a 17-DOF humanoid robot.

1. Introduction

Small humanoid robots are gaining widespread attention and application in humanoid robot research and other fields due to their simple control structure and good scalability. Servo motors are commonly used output actuators in small humanoid robots. They receive certain control signals and output corresponding angles.

2. Construction and control methods of servo motors

As shown in Figure 1, the servo motor mainly consists of a housing, a small DC motor, a set of reduction gears, a potentiometer for detecting the rotational position, and a control circuit board. The high-speed rotating DC motor provides the initial power, which is reduced in speed by the reduction gears and then outputs torque through the output shaft. The higher the reduction ratio of the gear set, the greater the output torque of the servo motor. A standard servo motor has three wires: a power wire, a ground wire, and a control wire, as shown in Figure 2. The power and ground wires provide the energy required by the DC motor and control circuitry inside the servo motor; the voltage is typically between 4 and 7.2 V. The input to the control wire is a periodic square wave pulse signal with adjustable width. When the pulse width of the square wave changes, the angle of the servo motor changes, and the angle change is proportional to the pulse width change. The servo motor used in the robot is model GM995, and the relationship between its output shaft rotation angle and the pulse width of the input signal can be represented by Figure 3.

The servo motor's nominal square wave pulse signal has a period of 20ms. In fact, the servo motor's angle control has a very lenient requirement for the signal period, which can be 18 to 20ms. In the experiment, it was found that the servo motor can still work stably when the period is 40ms.

Figure 1 Internal structure of the servo motor Figure 2 Servo motor interface Figure 3 Relationship between the output angle and input signal pulse width of the GM995 servo motor Figure 4 Servo motor control principle

3. Design of the servo controller

The control signal for a servo motor is essentially a pulse width modulation (PWM) signal. It can be generated by an FPGA, analog circuits, or a microcontroller. Using FPGAs or CPLDs to generate PWM waves has been applied in many important applications. Relying on the parallel processing capabilities and numerous I/O interfaces unique to FPGAs or CPLDs, dozens or even hundreds of servos can be controlled simultaneously. This method is reliable and offers high control precision. However, FPGAs/CPLDs lack transaction processing capabilities when generating PWM waves, requiring the cooperation of an MCU in practice, thus increasing costs and making it suitable for critical applications. Implementing PWM using analog circuits is more complex, unsuitable for multi-output, and the generated pulse frequency and width are often inaccurate, making precise servo control difficult. Due to their stable performance, flexible programming, high precision, and low cost, microcontrollers are generally used as servo motor controllers.

The most direct method is to use the PWM port built into the microcontroller to generate waveforms. However, this method is limited by the internal resources of the MCU and can only achieve 2 to 6 PWM outputs, making it unsuitable for applications requiring the control of multiple servos. The paper "Creative Design and Practice of Robots" presents a method for generating PWM signals using pulse signals generated by a 555 oscillator for counting. The paper "Design of a Multi-Channel Servo Controller Based on AT89C2051" presents a method for generating PWM wave signals using timer interrupts. The paper "Method for Generating 7-Channel Servo Control PWM Waves Using a Microcontroller" uses the concept of time-division multiplexing, generating 7 servo control PWM signals with a control pulse period of 14590 and a control pulse width of 1200-1800. One cycle is evenly divided into 7 parts, and one output is controlled in each time period. The disadvantage is that it consumes a significant amount of MCU computation time, but the advantage is the high precision of the control.

3.1 Hardware Circuit Design of Servo Controller

This paper combines the above schemes and adopts time-division multiplexing technology to divide a PWM signal cycle (20ms) into 8 time periods. Each time period generates 3 PWM signals in parallel, so a total of 24 PWM signals can be generated. Under the condition of using PIC16F877A microcontroller as the core controller and crystal oscillator frequency of 20M, the maximum error of the generated PWM signal controlling the servo motor is <1°.

Figure 4 shows the schematic diagram of the servo controller. This system is a typical centralized control method, with the microcontroller as the core of the control system. It communicates with the host computer to achieve intelligent control of the robot; it reads and writes the humanoid robot's behavior data by performing data access operations with the EEPROM (24C512) through the IIC bus; it generates 24 PWM signals to control the servo motors; it detects the robot's battery voltage and displays the robot's working status through LEDs.

It should be noted that servos draw in a large current when they are working. When multiple servos are working at the same time, the power supply voltage fluctuates greatly. The signal level of the servos should ideally not jitter. Therefore, a voltage regulator circuit is used in Figure 4 to regulate the power supply Vs. Otherwise, it was found in the experiment that some servos occasionally oscillate.

3.2 Implementation Principle of Multi-channel PWM Signal and Servo Speed ​​Control

This paper uses the PIC16F877A, a high-performance 8-bit microcontroller with enhanced RISC onboard Flash, manufactured by Microchip Technology, as the main control chip. With a crystal oscillator frequency of 20MHz, the execution time of each instruction is 200ns. As shown in Figure 3, when the servo angle changes by one degree, the pulse width changes by 2000/180° = 11.1/°. The microcontroller can execute approximately 11.1/0.2/instruction ≈ 55 instructions. However, it is difficult to implement the comparison and judgment of the PWM signals of 24 servos in a single operation within 55 instructions using C language.

The mechanism for generating multiple PWM signals is shown in Figure 5. To generate precise timing signals, a 16-bit hardware counter is used, with a counting base set to 200ns. Simultaneously, 24 16-bit matching registers store the matching value of each PWM signal, which is proportional to the desired angle of the servo motor. The 24 PWM signals are divided into 8 groups, with 3 signals in each group controlled in a time-division multiplexing manner. At the start of the program, all pins corresponding to the first group of PWM signals are set high, and the counter is cleared. Then, the counter value is continuously checked against the matching register value; if so, the pin of that PWM signal is set low. Each group of PWM signals occupies a time slot of 2.5ms (those less than 2.5ms are delayed to 2.5ms), thus ensuring the period of each PWM signal.

The biggest advantage of this time-sharing control method is that it ensures minimal time error for each PWM signal and prevents waveform jitter. Even microcontrollers with relatively low processing speeds, such as the MSC-51 series and mid-range PIC series microcontrollers, can generate accurate multi-channel PWM waveforms. The disadvantage is that it consumes more CPU resources and requires certain programming skills to handle other system tasks, enabling completion within 0.5ms to 1ms. In fact, the PIC16F877A microcontroller, with a 20MHz system clock, can execute 5000 single-cycle instructions within 1ms, which is sufficient to handle many system tasks. Furthermore, as demonstrated above, the PWM period can be greater than 20ms.

Figure 5. Mechanism of multi-channel PWM signal generation Figure 6. Program flowchart Figure 7. Schematic diagram of servo speed control

4. Software Design

Figure 6 shows the flowchart for generating multiple PWM signals. All 24 ports of PA, PB, PC, PD, and PE are PWM output ports. The 16-bit Timer 1 is used to compare with the matching registers of the three PWM signals in each group, with a reference of 200ns.

Let the system clock frequency of the PIC16F877A be f, the division ratio of the counter to the system clock be PS, the maximum high-level duration of the PWM signal be Th, and the corresponding maximum angle be Amax. Then the proportional coefficient can be calculated as follows:

For angle Ad, the value of the corresponding comparison register is:

A servo motor is a position servo system that can precisely control rotation angles. In fact, the angular velocity of the servo motor can also be controlled by generating a speed trapezoidal graph using software. The behavior data of this humanoid robot consists of a series of "keyframe" data, requiring the servos controlling each joint to reach the angle set by the behavior data at the same time. Therefore, it places high demands on the speed control of the servos.

Since the value T of the comparator register is proportional to the high-level time of the PWM wave, i.e., the pulse width, the value of T should also increase as the servo angle changes from 0 degrees to 180 degrees. Therefore, changing the step size of T can change the speed of the servo rotation.

Assuming the target angle of the servo changes from Ad to Ad', the corresponding value in the comparator register also changes from T to T'. The program uses the PWM period, i.e., 20ms, as a control cycle and increments or decrements the value of the comparator register by a step size Inc, thereby controlling the pulse width of the PWM wave. Therefore, changing the size of the step size Inc changes the speed of the servo's rotation.

(3) In the formula, Inc is the step size, which ranges from 1 to 255, meaning that the speed of the servo motor has 1 to 255 levels. The larger the step size, the smaller the required control cycle N, and the less time it takes for the servo motor to turn to the desired angle.

5. Conclusion

This paper successfully generated PWM waves for 24 servo motors, achieving not only high control precision but also control over servo motor speed. The controller was applied to a 17-DOF small humanoid robot, achieving good control performance and demonstrating excellent versatility.

Read next

CATDOLL 136CM Miho (Customer Photos)

Height: 136cm Weight: 23.3kg Shoulder Width: 31cm Bust/Waist/Hip: 60/54/68cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22