yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
DOFBOT SE📖
1.First Trial
  • 1.First Trial
  • 2.Analysis of common problems
  • 3.Calibration offset
  • 4.Precautions for DIY Robotic Arm
  • 5.Robotic arm gripping anomaly solutions
2.Assembly Course
  • 1.Installation video
  • 2.Calibrate the Robotic Arm
  • 3.Install the map
3.Remote Control Course
  • 1.Mobile APP control
  • 2.USB handle control
  • 3.PC software control
4.Preparation
  • 1.Manage APP control service
  • 2.Manage JupyterLab service
  • 3.Write STM32 firmware
  • 4.Introduction to expansion board
5.Basic Control Course
  • 1.Control RGB light
  • 2.Control buzzer
  • 3.Control single servo
  • 4.Read servo angle
  • 5.Control all servo
  • 6.DOFBOT up down left right
  • 7.DOFBOT dancing
  • 8.DOFBOT memory action
  • 9.DOFBOT grab block
  • 10.Porter
  • 11.Stack block
  • 12.USB camera display
  • 13.Synchronous action
6.AI Vision Basic Course
  • 1.Gesture Recognition
  • 2.Color threshold adjustment Color calibration
  • 3.Color recognition
  • 4.Face recognition
  • 5.Garbage recognition
  • 6.Yolo object recognition
  • 7.Real-time web view
7.2D Visual Tracking Course
  • 1.PID algorithm basics
  • 2.Color block positioning
  • 3.Color block tracking
  • 4.Face positioning
  • 5.Face tracking
  • 6.Gesture recognition fixed action
8.2D Visual Grasping Course
  • 0.Visual positioning
  • 1.Gesture recognition stack blocks
  • 2.Color recognition grab blocks
  • 3.Catch game
  • 4.Color sorting and stacking
  • 5.Garbage sorting
  • 6.Color interaction
9.2D Mediapipe Course
  • 1.Hand detection
  • 2.Posture detection
  • 3.Overall inspection
  • 4.Face detection
  • 5.Face recognition
  • 6.Face effects
  • 7.3D object recognition
  • 8.Paintbrush
  • 9.Finger control
  • 10.Gesture recognition
  • 11.Gesture control robotic arm action group
  • 12.Arm posture control robotic arm
  • 13.Palm Targeting
  • 14.Robotic arm tracks the palm
  • 15.Fingertip trajectory recognition
  • 16.Fingertip trajectory control robotic arm
  • 17.Gesture Grasp and Release Objects
  • 18.Finger Control Robot Arm
10.AI Large Model Voice Module (Must Read)
  • 1. Introduction to AI Large Model Voice Module
  • 2. Flash the firmware (Must read)
  • 3. Modify the wake-up word and command word
11.2D Voice Control Course
  • 1.Simple Voice Control
  • 2.Smart Voice Control
  • 3.Voice Action Control
  • 4.Memory Learning Mode
  • 5.Color Recognition with Voice Broadcast
  • 6.Color Recognition and Grasping with Voice Broadcast
  • 7.Color Recognition and Sorting with Voice Broadcast
  • 8.Voice Recognition Target Tracking
  • 9.Voice Control Stacking
  • 10.Voice Control Color Sorting
  • 11.Garbage Recognition with Voice Broadcast
  • 12.Garbage Sorting with Voice Broadcast
12.Robotic Arm Control and Inverse Kinematics
  • 1. Robotic arm ROS control
  • 2. Inverse solution
13.3D Sorting and Grasping Course
  • 1.AprilTag ID sorting
  • 2.MediaPipe Gesture-AprilTag ID sorting
  • 3.MediaPipe Gesture-AprilTag distance sorting
  • 4.Block color sorting
  • 5.Block different shape sorting
  • 6.Yolov11 garbage sorting
14.3D Tracking Course
  • 1.AprilTag Tracking
  • 2.Color Block Tracking
  • 3.KCF Object Tracking
15.3D Voice Control for Sorting & Tracking Course
  • 1.Voice Control AprilTag ID Sorting
  • 2.Voice Control Color Block Sorting
  • 3.Voice Control Yolov11 Garbage Recognition Sorting
  • 4.Voice Control AprilTag Tracking
  • 5.Voice Control Color Block Tracking
  • 6.Voice Control Object Tracking
16.AI Model Basics
  • 1.AI large model types and principles
  • 2.RAG retrieval enhancement and model training samples
  • 3.Embodied intelligent robot system architecture
  • 4.Embodied intelligent functions core source code
17.AI Model Development
  • 1. Register a model service provider account
  • 2. Configure API-KEY
  • 3. Introduction to Dify
  • 4. Basic Dify Features
  • 5. AI Large Model Development - chatbot
  • 6. Deploy the RAG knowledge base
  • 7. RAG knowledge base + chatbot
  • 8. AI agent workflow
18.AI Model – Text Version
  • 1.Semantic understand instruction following
  • 2.Multimodal visual understand
  • 3.Text Large Model + robotic arm control
  • 4.Multimodal Large Model+video understanding
  • 5.Multimodal Large Model+robotic arm gripping
  • 6.Multimodal Large Model+robotic arm tracking
  • 7.Multimodal Large Model+robotic arm sorting
  • 8.Multimodal Large Model+robotic arm handling
  • 9.Multimodal Large Model+Color Blocks Back In Place
  • 10.Multimodal Large Model + Intent Prediction + Robotic Arm Gripping
  • 11.Text Large Model + YOLOv11 + Intelligent Garbage Classification
19.AI Model – Voice Version
  • 1.Semantic understand instruction following
  • 2.Multimodal visual understand
  • 3.Text Large Model + robotic arm control
  • 4.Multimodal Large Model+video understanding
  • 5.Multimodal Large Model+robotic arm gripping
  • 6.Multimodal Large Model+robotic arm tracking
  • 7.Multimodal Large Model+robotic arm sorting
  • 8.Multimodal Large Model+robotic arm handling
  • 9.Multimodal Large Model+Color Blocks Back In Place
  • 10.Multimodal Large Model + Intent Prediction + Robotic Arm Gripping
  • 11.Text Large Model + YOLOv11 + Intelligent Garbage Classification
20.AI Model – Fun Applications
  • 1.AI Butler-Intent Inference
  • 2.AI Encyclopedia-Arithmetic Master
  • 3.AI Encyclopedia-You asked I Pointed
  • 4.AI Encyclopedia-Nutritional Analysis
  • 5.AI Encyclopedia-Problem Solving Expert
  • 6.AI Encyclopedia-English Spelling
  • 7.AI Butler-Garbage Sorting
  • 8.AI Top Chef
21.MoveIt2 Course
  • 1. MoveIt Configuration
  • 2. MoveIt Usage
  • 3. MoveIt Drive Real Robot
  • 4. MoveIt Random Movement
  • 5. MoveIt Forward Kinematics Design
  • 6. MoveIt Inverse Kinematics Design
  • 7. MoveIt Cartesian Path
  • 8. MoveIt Scene Design
  • 9. MoveIt Trajectory Planning
  • 10. MoveIt Collision Detection
22.YOLOv11 Development Course
  • 1. YOLO Environment Setup
  • 2. CLI Usage
  • 3. Object Detection
  • 4. Instance Segmentation
  • 5. Pose Estimation
  • 6. Image Classification
  • 7. Oriented Bounding Boxes Object Detection
  • 8. Model Conversion
  • 9. Model Prediction
23. Linux Operating System
  • 1.Introduction to Linux system
  • 2.Ubuntu file system
  • 3.Ubuntu common commands
  • 4.Ubuntu common editors
  • 5.Ubuntu software operation commands
  • 6.Virtual machine installation
  • 7.SSH remote control
  • 8.VNC remote control
  • 9.Transfer files remotely
  • 10.Driver library and communication
  • 11.Static IP and hotspot mode
  • 12.Bind device ID
  • 13.Capacity expansion and resource allocation
  • 14.Update system software sources
  • 15.Set root user password
  • 16.sudo free password
  • 17.Connect to WiFi network
  • 18.View system version
  • 19.Customized service management
  • 20.Back up system image
24.OpenCV Course
  • 1.Introduction to Open Source CV
  • 2.Image reading and display
  • 3.Picture writing
  • 4.Image Quality
  • 5.Pixel operations
  • 6.Image zoom
  • 7.Picture cut
  • 8.Picture pan
  • 9.Picture mirroring
  • 10.Affine transformation
  • 11.Picture rotation
  • 12.perspective transformation
  • 13.Grayscale processing
  • 14.Binary image
  • 15.Edge green detection
  • 16.Line segment drawing
  • 17.Rectangular circle drawing
  • 18.Text and picture drawing
25.Advanced Visuals Course
  • 1. QR Code
  • 2. Human Pose Estimation
  • 3. Object Detection
  • 4. AR Vision
  • 5. ROS + OpenCV Basics
26.ROS2 Basic Course
  • 1.Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
27.Jupyter Lab Usage Course
  • 0.Read the document before operation
  • 1.Jupyter Lab environment construction
  • 2.Basic use of Jupyter Widgets
  • 3.Launch JupyterLab
  • 4.How to Use JupyterLab
Download
  • APP(iOS/Android)
  • VM File
  • Instruction manual
  • Hardware_3DModelFile
  • PC_Software
  • Code
  • Communication Protocol-Python Library
  • Tools
Download ZIP

Welcome to DOFBOT SE repository

1.PID algorithm basics

PID Algorithm Basics

Introduction

PID, which stands for Proportional Integral Derivative, is a control algorithm that performs proportional, integral, and differential operations on the input deviation, and the superimposed result of these operations is used to control the actuator. The formula is as follows:

It consists of three parts:

  • P is proportion, which is the input deviation multiplied by a coefficient;
  • I is integral, which performs integral operations on the input deviation;
  • D is derivative, which performs derivative operations on the input deviation.

The following diagram shows a basic PID controller:

(1) Proportional Part

The mathematical expression for the proportional part is: Kp*e(t)

In an analog PID controller, the proportional action responds immediately to deviation. Once deviation occurs, the controller immediately generates control action to direct the control quantity toward reducing the deviation. The strength of the control action depends on the proportional coefficient - the larger the proportional coefficient, the stronger the control action, the faster the transition process, and the smaller the static deviation of the control process; however, if it is too large, it can easily cause oscillation and destroy system stability. Therefore, the proportional coefficient must be chosen appropriately to achieve minimal transition time, small static error, and stability.

Advantages: Adjusting the open-loop proportional coefficient of the system improves steady-state accuracy, reduces system inertia, and speeds up response.

Disadvantages: Using only the P controller, an overly large open-loop proportional coefficient not only increases the system overshoot but also reduces the system stability margin, or even causes instability.

(2) Integral Part

The mathematical expression for the integral part is:

The larger the integral constant, the weaker the accumulation effect of the integral; in this case, the system will not oscillate during transition; however, increasing the integral constant slows down the process of eliminating static error, and it takes longer to eliminate deviation, but it can reduce overshoot and improve system stability. When Ti is small, the integral action is stronger, and oscillation may occur during the system transition, though the time required to eliminate deviation is shorter. Therefore, Ti must be determined based on specific control requirements.

Advantages: Eliminates steady-state error.

Disadvantages: The addition of the integral controller affects system stability and reduces the stability margin.

(3) Derivative Part

The mathematical expression for the derivative part is:

The derivative action prevents deviation from changing. It performs control based on the trend of deviation (rate of change). The faster the deviation changes, the larger the output of the derivative controller, and it can make corrections before the deviation value increases. The introduction of derivative action helps reduce overshoot, overcome oscillation, and stabilize the system, especially beneficial for high-order systems, as it speeds up system tracking. However, derivative action is sensitive to noise in input signals, so for systems with significant noise, derivative is generally not used, or input signals are filtered before derivative takes effect. The derivative action is determined by the derivative time constant Td. The larger Td, the stronger its inhibition of deviation change; the smaller Td, the weaker its resistance to deviation change. The derivative part clearly plays a significant role in system stability. Appropriate selection of the derivative constant Td can optimize the derivative effect.

Advantages: Speeds up system response, reduces overshoot and oscillation, and has a "predictive" effect on dynamic processes.

Selection of PID Algorithm

Digital PID control algorithms can be classified into positional PID and incremental PID control algorithms. Before deciding which PID algorithm to use, we should first understand its principles:

  • Positional PID Algorithm:

e(k): User-set value (target value) - current state value of the controlled object

Proportional P: e(k)

Integral I: ∑e(i) - accumulation of error

Derivative D: e(k) - e(k-1) current error - previous error

In other words, positional PID is the deviation between the current actual position of the system and the desired target position, performing PID control.

Because there is error integration ∑e(i), which accumulates continuously, the current output u(k) is related to all past states, using the accumulated error value; (error e will have error accumulation), the output u(k) corresponds to the actual position of the actuator, and once the control output is incorrect (the current state value of the controlled object has a problem), significant changes in u(k) will cause significant changes in the system. Additionally, when the integral term of positional PID reaches saturation, the error will continue to accumulate under the integral action. Once the error begins to reverse, the system needs a certain time to exit the saturation zone. Therefore, when u(k) reaches maximum and minimum, integral action should be stopped, and there should be integral limiting and output limiting. So when using positional PID, we generally directly use PD control. Positional PID is suitable for control objects where the actuator does not have integral components, such as steering gear and balance car upright control and temperature control systems.

Advantages: Positional PID is a non-recursive algorithm that can directly control actuators (such as balance cars), and the u(k) value corresponds one-to-one with the actual position of the actuator (such as the current angle of the car), so it can be well applied in control objects where the actuator does not have integral components.

Disadvantages: Each output is related to past states, and during calculation, e(k) must be accumulated, which requires a large amount of computation.

  • Incremental PID:

Proportional P: e(k)-e(k-1) current error - previous error

Integral I: e(k) error

Derivative D: e(k)-2e(k-1)+e(k-2) current error - 2*previous error + error before previous

From the formula, incremental PID clearly shows that once KP, TI, and TD are determined, the control increment can be calculated using the deviation of the three consecutive measurement values before and after. The resulting control quantity Δu(k) corresponds to the increment of recent position errors, not the deviation from the actual position. There is no error accumulation, meaning incremental PID does not require accumulation. The determination of control increment Δu(k) is only related to the three most recent sampling values, making it easy to obtain good control effects through weighted processing, and when a problem occurs in the system, incremental PID will not seriously affect system operation.

Summary: Incremental PID takes the increment of positional PID. At this point, the controller output is the difference between the position values calculated at two consecutive sampling instants. The result is an increment, meaning on the basis of the previous control quantity, an increase is needed (a negative value means decrease).

Advantages: ① When a mistaken action occurs, the impact is small, and erroneous data can be removed through logical judgment when necessary.

② Low impact during manual/automatic switching, facilitating disturbance-free switching. When a computer fails, the original value can still be maintained.

③ No accumulation is required in the formula. The determination of control increment Δu(k) is only related to the three most recent sampling values.

Disadvantages: ① Large integral truncation effect, there is steady-state error;

② Significant impact of overflow. Some controlled objects do not work well with incremental;

  • Differences Between Incremental and Positional

① The incremental algorithm does not require accumulation, and the determination of control quantity increment is only related to several recent deviation sampling values, so the calculation error has a smaller effect on the control quantity calculation. The positional algorithm uses the accumulated value of past deviations, which easily generates larger accumulated errors.

② The incremental algorithm yields the increment of the control quantity. For example, in valve control, only the part of valve opening change is output, so the impact of mistaken action is small; when necessary, logical judgment can limit or prohibit this output, which will not seriously affect system operation. The output of positional directly corresponds to the object output, so it has a greater impact on the system.

③ Incremental PID control outputs the control quantity increment and has no integral action, so this method is suitable for actuators with integral components, such as stepper motors, while positional PID is suitable for actuators without integral components, such as electro-hydraulic servo valves.

④ When performing PID control, positional PID requires integral limiting and output limiting, while incremental PID only needs output limiting. Positional PID and incremental PID are just two implementation forms of digital PID control algorithms, with identical essence. The main difference is the different storage method of the integral term. Positional PID stores the integral term separately, while incremental PID stores the integral term as part of the output. Online various players also have their own unique insights and views on the use of positional and incremental. Specifically, it depends on which algorithm is suitable for our specific application scenario.

PID Parameter Tuning

There are many methods for selecting PID controller parameters, such as trial-and-error method, critical proportioning method, extended critical proportioning method, etc. However, for PID control, parameter selection is always a very tedious work, and requires continuous adjustment to obtain a satisfactory control effect. Based on experience, the general steps for determining PID parameters are as follows:

  • Determine proportional coefficient Kp

When determining the proportional coefficient Kp, first remove the integral and derivative terms of PID, set Ti=0, Td=0, making it

Pure proportional adjustment. Set the input to 60%~70% of the maximum output value allowed by the system, and gradually increase the proportional coefficient Kp from 0 until the system oscillates; then reverse, gradually decrease the proportional coefficient Kp until the oscillation disappears. Record the proportional coefficient Kp at this time, and set the PID proportional coefficient Kp to 60%~70% of the current value.

  • Determine integral time constant Ti

After determining the proportional coefficient Kp, set a larger integral time constant Ti, then gradually decrease Ti until the system oscillates, then reverse, gradually increase Ti until the oscillation disappears. Record Ti at this time, and set the PID integral time constant Ti to 150%~180% of the current value.

  • Determine derivative time constant Td

The derivative time constant Td is generally not set, just set it to 0, at this time PID adjustment becomes PI adjustment. If it needs to be set, it is the same method as determining Kp, taking 30% of the value when there is no oscillation.

  • System no-load and load joint debugging

Fine-tune PID parameters until performance requirements are met.

Of course, this is my personal debugging method, which may not be suitable for everyone and every environment, just for your reference; however, there is also a classic trial-and-error rhyme for debugging PID circulating online, which I will share for your reference:

Parameter tuning finds the best, from small to large in order.

First proportional then integral, finally add derivative.

Curve oscillates very frequently, increase proportional dial.

Curve drifts and makes a big bend, decrease proportional dial.

Curve deviates and recovers slowly, lower integral time.

Curve fluctuates period long, increase integral time again.

Curve oscillates frequency fast, first lower derivative.

Large error with slow fluctuation, increase derivative time.

Ideal curve two waves, high front and low back four to one.

First observe then adjust more analysis, adjustment quality will not be low.

PID is a control algorithm consisting of proportion (P), integration (I), and derivation (D). It does not necessarily require all three algorithms; it can also be PD, PI, or even just P algorithm control. My previous simplest idea for closed-loop control was only P control, feeding the current result back, then subtracting from the target; if positive, slow down; if negative, speed up. Of course, this is the simplest closed-loop control algorithm, so I return to the summary of positional and incremental in the previous section. Specifically, it depends on our current control environment, because each control system is different, and the parameters that can make our system achieve the most stable effect are naturally OK.

Real-time web view
Color block positioning

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文