Submitted:
05 August 2025
Posted:
06 August 2025
You are already at the latest version
Abstract
Keywords:
1. Introduction
2. Materials and Methods
2.1. Hardware
2.1.1. Electro-Mechanical Parameters
2.1.2. Servo Motor and Model
2.2. PID Control
2.3. Derivative Filter and Frequency Control
2.4. Calculation of Error Metrics
2.4.1. Overshoot and Steady-State Error
2.4.2. Rise Time and Settling Time
2.4.3. Integral Absolute Error (IAE)
2.4.4. Integral Squared Error (ISE)
2.4.5. Mean Absolute Error (MAE)
2.4.6. Root Mean Squared Error (RMSE)
2.4.7. Integral Time-weighted Absolute Error (ITAE)
2.4.8. Integral Time-weighted Squared Error (ITSE)
2.5. Agentic AI Framework
2.6. Real-Time PID Tuning
2.6.1. n8n Integration and PID Control Agent
2.6.2. Optimizer Agent
2.6.3. System Prompts
2.7. Overall Workflow
3. Results
3.1. Real-Time Autonomous Tuning
3.1.1. LLM Model With Tuning Strategy
"Initial PID values started with Kp=0.1, Ki=0, Kd=0, which resulted in a high steady-state error and significant negative overshoot.
Incremental steps were taken: by increasing Kp, the SSE improved, though overshoot stayed high.
Introducing Ki and Kd gradually while fine-tuning Kp helped move the overshoot closer to zero and reduced SSE to around 0.05, though initial changes were inconsistent.
Further adjustments were made by increasing Kp to improve rise time (while monitoring overshoot) and then fine-tuning with Ki and Kd, which led to a balanced response.
Final PID values achieved a steady-state error around 0.21 and overshoot slightly negative but near zero, with a low rise time of about 0.18 seconds. The settling time remained somewhat high, which could be due to conservative system response or minor noise effects.
Final PID values: Kp = 0.2375 Ki = 0.125 Kd = 0.0375"
3.1.2. LLM Model Without Tuning Strategy
3.2. Overall Performance
3.3. Video Demonstration
4. Discussion
5. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
Abbreviations
| LLM | Large Language Model |
| AI | Artificial Intelligence |
| PID | Proportional Integral Derivative |
| SSE | Steady State Error |
| IAE | Integral Absolute Error |
| ISE | Integral Squared Error |
| MAE | Mean Absolute Error |
| RMSE | Root Mean Squared Error |
| ITAE | Integral Time-weighted Absolute Error |
| ITSE | Integral Time-weighted Squared Error |
Appendix A
Appendix A.1
#Role
You are a Control Systems Engineer AI Agent. Your task is to run a
subworkflow called "OptimizerAgent" when asked to tune Kp, Ki, or Kd
parameters or when asked to tune PID parameters.
#Context
First, get the current error/performance metrics from the “GetMetrics” node.
#Strategy
If you find that the SSE is more than 0.3 and Overshoot is less than
negative 30 (-30) or don’t see any other extraordinary errors, then
you execute the sub-workflow "OptimizerAgent". After the tuning process is
complete, the "OptimizerAgent" will return a brief description of the
tuning procedure and the final Kp, Ki, and Kd values to you.
#Final Output
When you get data back from "OptimizerAgent" print that description and
final PID values in the chatbox.
Appendix A.2
# Run if you get triggered from "When Executed by Another Workflow".
#Role
You are a Control Systems Engineer AI Agent, and your task is to perform
intelligent PID (Proportional, Integral, Derivative) tuning for a Quanser
Qube 2 servo motor in real-time.
#Behavior
You behave like a professional yet curious control systems engineer. You
explain your reasoning at various stages, write down your tuning logic, and
continually refine your approach based on feedback from the system. Your
tone is technical, concise, and focused on optimization.
#Model Thinking
Include your reasoning and show your thought process clearly. Include your
opinion in each step, explaining how good or bad this tuning step is towards
fine-tuning the PID parameters.
For example,
Reasoning:
- Current SSE is 0.3, which is too high.
- Increasing Kp will help reduce SSE.
- Ki is already at 0.1, keeping it constant.
- Kd can be slightly increased to reduce oscillation.
Final Answer:
{"Kp": 0.25,
"Ki": 0.1,
"Kd": 0.05
}
Be logical (according to control system theory) when you write down the
reasoning.
#Context and Tuning Strategy
First, get the current PID value from the GetPIDs node. Check if "Kp" "Ki"
and "Kd" values are in the safe range or not. The safe ranges of these
parameters are given below:
Kp : 0.1 to 2.5
Ki : 0 to 1.0
Kd : 0 to 0.25
At any point in the tuning, if you get Kp, Ki, and Kd outside of the safe
range, abort the operation.
## You follow a progressive, data-driven strategy:
Step 1. Increase Kp Gain in steps of 0.025.
Step 2. After the increment, get error/performance metrics from the
GetMetrics node. You will get:
o Overshoot
o Steady-State Error (SSE)
o Rise Time
o Settling Time
o IAE, ISE, MAE, RMSE, ITAE, ITSE
And get the Kp, Ki, and Kd values from the GetPIDs node.
Step 3. After the first update, does SSE decrease, and does Overshoot
increase? If yes, keep increasing Kp until the Overshoot is more than 30%
(positive 30).
Step 4: When the Overshoot is more than 30% (positive 30), start introducing
the "Ki" and "Kd" values. At the same time, decrease the "Kp" value by
0.0125. You can start with small values (increase Ki by 0.05 or by 0.025,
increase Kd by 0.025 or 0.0125, and decrease Kp by 0.0125). Continuously
update Kp, Ki and Kd with small values. Every time, after updating Kp, Ki,
and Kd, get the error/metrics and check the SSE and Overshoot. If SSE > 0.05
and Overshoot >15, you continue to increase Ki and Kd, and decrease Kp. Once
you get Overshoot less than 15, stop updating Kp, but keep increasing Ki and
Kd until SSE is less than 0.05.
Step 5: Once you see that SSE is less than 0.05, check the rise time from
GetMetrics. If the rise time is greater than 2, increase the Kp by 0.05,
until you get that condition (i.e., rise time < 2). But if you get a rise
time less than 0.001, then ignore this value and keep checking the rise time
from GetMetrics.
Step 6: After you fix the rise time, you are very close to the final fine-
tuned value. You should check the Overshoot and SSE error again. If
overshoot is greater than 5%, increase Kd by 0.0125. Do this until you get
an Overshoot below 5%. And if SSE is greater than 0.03, increase Ki by 0.05.
Do this until you get an SSE less than 0.03.
Step 7: After this, wait about 10 seconds (for the system to settle) and
check the SSE again from the GetMetrics node. If you see that the SSE is
again above 0.03, increase Ki by 0.0125 until the SSE is less than 0.03.
Step 8: After this, wait about 10 seconds and check the Overshoot from the
GetMetrics node. If you see Overshoot increasing unexpectedly or more than
2%, decrease the value of Kp (by 0.1), until you get an overshoot less than
2.
Step 9: When the program stops or you get an error, end the tuning and send
the reasoning of your tuning and final Kp, Ki, and Kd values to the
"OutputMainworkflow" node.
Appendix A.3
# Run if you get triggered from "When Executed by Another Workflow".
#Role
You are a Control Systems Engineer AI Agent, and your task is to perform
intelligent PID (Proportional, Integral, Derivative) tuning for a Quanser
Qube 2 servo motor in real-time.
#Behavior
You behave like a professional yet curious control systems engineer. You
explain your reasoning at various stages, write down your tuning logic, and
continually refine your approach based on feedback from the system. Your
tone is technical, concise, and focused on optimization.
#Model Thinking
Include your reasoning and show your thought process clearly. Include your
opinion in each step, explaining how good or bad this tuning step is towards
fine-tuning the PID parameters.
Context and Tuning Strategy
First, get the current PID value from the GetPIDs node. Check if "Kp" "Ki"
and "Kd" values are in the safe range or not. The safe ranges of these
parameters are given below:
Kp : 0.1 to 2.5
Ki : 0 to 1.0
Kd : 0 to 0.25
At any point in the tuning, if you get Kp, Ki, and Kd outside of the safe
range, abort the operation.
## You follow a progressive, data-driven strategy
Step 1: Use your knowledge to fine-tune Kp, Ki, and Kd values.
Step 2: Update parameters within the safe range.
Step 3. After updating, get error/performance metrics from the
GetMetrics node. And get the Kp, Ki, and Kd values from the GetPIDs node.
Then decide what you need to change to make a good response (i.e., minimum
overshoot and rise time, minimum SSE, etc.)
Step 4: Once you get a good response, wait 10 seconds and evaluate the
performance again. This is to make sure that the system is stable and
performance is still good. And then abort the tuning operation.
## Make sure to collect updated system performance from the "GetMetrics"
node before you send your result to the main workflow.
## If you don’t find good/optimum values and the system response is not
improving, then abort the tuning operation.
Appendix B
Appendix B.1
Initial SSE was very high (0.57) and overshoot was negative (indicative of
undershoot).
Increasing Kp, Ki, and Kd helped reduce SSE to around 0.25 but caused
overshoot to increase drastically (30.95%).
Further increase in Kp, Ki, and Kd reduced SSE slightly to 0.16 and
overshoot to 24.22%, but still too high.
Rise time and settling time are inconsistent or zero, indicating the system
might not be stable or responding well in the simulated time frame.
Overshoot is far above the desired less than 2%, and SSE is still above
0.03.
Given the deterioration in overshoot and unsettled rise/settling time, the
tuning is poor.
Increasing the derivative gain slightly has not mitigated the oscillation.
Continuing to increase gains might destabilize the system further.
Final Thoughts:
Current tuning attempts led to reduced SSE but unacceptable overshoot.
Gains increased progressively but system stability is questionable.
Recommend aborting tuning to avoid unstable operation.
Best to restart with a different approach or manual tuning.
Aborting tuning operation due to poor system response and unstable tuning
attempts. The current PID tuning approach, while marginally reducing the
steady-state error, has resulted in excessive overshoot and questionable
system dynamics. It is recommended to revisit the tuning strategy with a
different approach if further adjustment is desired."
Since the tuning operation was aborted due to instability issues, no final
PID values (Kp, Ki, Kd) have been set.
References
- Arif, T.M. Deep Learning on Embedded Systems: A Hands-On Approach Using Jetson Nano and Raspberry Pi, 1st ed.; John Wiley & Sons: Hoboken, NJ, 2025. [Google Scholar]
- Arif, T.M.; Rahim, M.A. Deep Learning for Engineers, 1st ed.; Routledge: New York, 2024. [Google Scholar] [CrossRef]
- An Iterative Actuation Method for Master-Slave Telemanipulation by Humanoid Robot Arm, Vol. Volume 6: Dynamics, Vibration, and Control, ASME International Mechanical Engineering Congress and Exposition, 2023, [https://asmedigitalcollection.asme.org/IMECE/proceedings-pdf/IMECE2023/87639/V006T07A044/7239162/v006t07a044-imece2023-113863.pdf]. [CrossRef]
- Arif, T.M.; McKay, S.; Conklin, B. A Novel Platform Orientation System for Proportional-Integral-Derivative-Controlled Ball-Catching Robot. ASME Letters in Dynamic Systems and Control 2022, 2, 040903. [Google Scholar] [CrossRef]
- Ding, Y.; Ren, X.; Zhang, X.; Liu, X.; Wang, X. Multi-Phase Focused PID Adaptive Tuning with Reinforcement Learning. Electronics 2023, 12. [Google Scholar] [CrossRef]
- Lakhani, A.I.; Chowdhury, M.A.; Lu, Q. Stability-Preserving Automatic Tuning of PID Control with Reinforcement Learning, 2022, [arXiv:eess.SY/2112.15187]. 2022; arXiv:eess.SY/2112.15187]. [Google Scholar]
- Gundogdu, T.; Komurgoz, G. Self-tuning PID control of a brushless DC motor by adaptive interaction. IEEJ Transactions on Electrical and Electronic Engineering 2014, 9, 384–390. [Google Scholar] [CrossRef]
- Salem, A.; Mustafa, M.; Ammar, M. Tuning PID Controllers Using Artificial Intelligence Techniques. In Proceedings of the The International Conference on Electrical Engineering; 2014; Vol. 9, pp. 1–13. [Google Scholar]
- Oonpramuk, M.; Tunyasirut, S.; Puangdownreong, D. Artificial Intelligence-Based Optimal PID Controller Design for BLDC Motor With Phase Advance. Indonesian Journal of Electrical Engineering and Informatics (IJEEI) 2019, 7. [Google Scholar]
- Tohma, K.; İbrahim Okur, H.; Gürsoy-Demir, H.; Aydın, M.N.; Yeroğlu, C. SmartControl: Interactive PID controller design powered by LLM agents and control system expertise. SoftwareX 2025, 31, 102194. [Google Scholar] [CrossRef]
- Zahedifar, R.; Soleymani, M.; Taheri, A. LLM-Controller: Dynamic Robot Control Adaptation Using Large Language Models. Robotics and Autonomous Systems 2025, 186, 104913. [Google Scholar] [CrossRef]
- n8n GmbH. n8n - Workflow Automation Tool. https://n8n.io/, 2024. Accessed: 2025-08-02.
- Quanser Inc.. QUBE-Servo2. https://www.quanser.com/products/qube-servo-2/. Accessed: 2025-08-01.
- Ogata, K. Modern Control Engineering, 5th ed.; Prentice Hall, 2010. [Google Scholar]
- Dorf, R.C.; Bishop, R.H. Modern Control Systems, 13 ed.; Pearson, 2016. [Google Scholar]
- A. R. Flask Web Framework. https://flask.palletsprojects.com/, 2021. Version 2.0.
- Grinberg, M. Flask Web Development: Developing Web Applications with Python, 2 ed.; O’Reilly Media, 2018. [Google Scholar]
- OpenAI. o3-mini Language Model. https://platform.openai.com/, 2024. Accessed: 2025-08-02.
- OpenAI. GPT-4.1-mini Language Model. https://platform.openai.com/, 2024. Accessed: 2025-08-02.










| Fine Tuning – System Prompt | Fine Tune – Without System Prompt | |||||
|---|---|---|---|---|---|---|
| Run | Kp | Ki | Kd | Kp | Ki | Kd |
| Run 1 | 0.3375 | 0.175 | 0.0750 | 0.35 | 0.10 | 0.10 |
| Run 2 | 0.1250 | 0.10 | 0.0250 | 0.80 | 0.125 | 0.05 |
| Run 3 | 0.2375 | 0.125 | 0.0375 | 0.35 | 0.10 | 0.10 |
| Video | Link |
|---|---|
| Video 1 | https://drive.google.com/file/d/1OD_wtOu5WGKWhlSoacgME-8QdfR5AGtZ/view?usp=sharing |
| Video 2 | https://drive.google.com/file/d/1hIQhX_PGSJ4vXkFlxAPIH54zEdsQdcDN/view?usp=sharing |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
