Great question! When your power supply or battery can change frequently, and you don’t have the opportunity to manually tune PID parameters each time, relying on fixed PID tuning becomes problematic. Here’s why and what you can do instead:
Why Fixed PID Tuning May Not Work Well in Your Case
- Different batteries have different internal resistances, capacities, and charging characteristics.
- Different USB-C power supplies have different response times, voltage/current limits, and stability.
- PID parameters tuned for one setup may cause:
- Instability or oscillations with another battery or supply,
- Slow or sluggish response with some combinations,
- Overshoot or undershoot leading to unsafe conditions.
What Are Your Options?
1. Use a More Robust Control Strategy
- Adaptive Control: Automatically adjust PID parameters based on observed system behavior (e.g., auto-tuning PID).
- Gain Scheduling: Use different PID parameters depending on detected battery or supply characteristics.
- Simpler Control Loops: Use a conservative proportional-only controller with safety limits to avoid instability.
2. Implement Safety-First, Conservative Defaults
- Use low KP and KI values to avoid aggressive voltage changes.
- Add rate limiting on voltage changes to prevent sudden jumps.
- Enforce hard voltage and current limits to protect battery and supply.
- Use slow control loop frequency (e.g., 1-2 Hz) to allow the system to settle.
3. Add Automatic Parameter Tuning (Auto-Tuning)
- Implement a routine that:
- Applies small test perturbations,
- Measures system response,
- Adjusts PID gains accordingly.
- This is more complex but can greatly improve robustness.
4. Use a Lookup Table or Profiles
- Detect battery type or supply capabilities (e.g., via USB PD communication or user input).
- Load pre-tuned PID parameters or control profiles for that combination.
Practical Recommendations for Your Use Case
- Start with a simple proportional controller with integral action disabled or very low.
- Add safety checks to prevent voltage or current from exceeding safe limits.
- Use slow, smooth voltage adjustments to avoid oscillations.
- Log data if possible, so you can analyze and improve control offline.
- If you can detect battery voltage and current accurately, use a simple bang-bang or hysteresis control as a fallback.
Summary
| Approach | Pros | Cons | Suitability for Your Case |
|---|
| Fixed PID tuning | Precise control when tuned | Not robust to changing hardware | Not ideal if batteries/supplies change frequently |
| Adaptive PID / Auto-tuning | Self-adjusting, robust | Complex to implement | Good if you can invest development time |
| Simple proportional control | Easy, stable, safe | Less precise | Good starting point for variable hardware |
| Lookup tables/profiles | Tailored control | Requires detection & storage | Good if you can identify hardware reliably |
TL;DR
If you expect frequent changes in batteries or power supplies without manual tuning, fixed PID tuning is not reliable. Instead, use a simple, conservative control approach with strong safety limits, or implement adaptive tuning if possible.
If you want, I can help you draft a simple, robust control loop example that works reasonably well across different batteries and supplies!