Skip to content

Latest commit

 

History

History
183 lines (134 loc) · 5.71 KB

File metadata and controls

183 lines (134 loc) · 5.71 KB

Getting Started with AutoTunePID

Welcome to the AutoTunePID library! This guide will help you get started quickly with basic PID control. Whether you're new to PID controllers or experienced, this guide will walk you through your first implementation.

Table of Contents

Quick Start (5 Minutes)

Step 1: Installation

Arduino IDE Library Manager (Recommended)

  1. Open Arduino IDE
  2. Go to Sketch > Include Library > Manage Libraries
  3. Search for "AutoTunePID"
  4. Click Install

Manual Installation

  1. Download the latest release ZIP from GitHub Releases
  2. Open Arduino IDE
  3. Go to Sketch > Include Library > Add .ZIP Library
  4. Select the downloaded ZIP file

Step 2: Basic PID Control

Here's the simplest way to use AutoTunePID:

#include <AutoTunePID.h>

using namespace atp;

// Create PID controller (min output, max output, tuning method)
AutoTunePID pid(0.0f, 255.0f, TuningMethod::ZieglerNichols);

void setup() {
    // Set your target value (setpoint)
    pid.setSetpoint(100.0f); // Target temperature, speed, etc.

    // Optional: Set manual PID gains (skip if using auto-tuning)
    pid.setManualGains(2.0f, 0.5f, 0.1f); // Kp, Ki, Kd
}

void loop() {
    // Read your process variable (temperature, speed, position, etc.)
    // Scale to your units (e.g., 0-100°C)
    float currentValue = static_cast<float>(analogRead(A0)) * (100.0f / 1023.0f); 

    // Update PID controller
    pid.update(currentValue);

    // Get control output and apply to your actuator
    float output = pid.getOutput();
    analogWrite(9, static_cast<int>(output)); // PWM output to motor, heater, etc.

    delay(100); // Control loop timing
}

Step 3: Test Your Setup

  1. Upload the sketch to your Arduino
  2. Monitor the serial output (add Serial.println(output); to see values)
  3. Adjust the setpoint and observe how the output responds
  4. Your basic PID controller is working!

Understanding the Basics

What is PID Control?

PID stands for Proportional-Integral-Derivative. It's a control algorithm that:

  • Proportional (P): Responds to current error
  • Integral (I): Corrects accumulated error over time
  • Derivative (D): Predicts future error based on rate of change

Key Concepts

Term Description Your Code
Setpoint (SP) Target value you want pid.setSetpoint(100.0f)
Process Variable (PV) Current measured value float currentValue = static_cast<float>(analogRead(A0))
Error Difference: SP - PV Calculated automatically
Output Control signal to actuator pid.getOutput()
PID Gains Control sensitivity pid.setManualGains(Kp, Ki, Kd)

Tuning Methods

Choose based on your application:

Method Best For Description
Ziegler-Nichols General purpose Good starting point for most systems
Cohen-Coon Processes with dead time Better for slow-responding systems
IMC Fast response needed Balances speed and stability
Manual Tuning Fine control When you know your system well

Common Applications

Temperature Control

using namespace atp;

// Heater control (Normal mode)
AutoTunePID heaterPID(0.0f, 255.0f, TuningMethod::ZieglerNichols);
heaterPID.setSetpoint(25.0f); // Target temperature in °C

// In loop:
float currentTemp = readTemperatureSensor();
heaterPID.update(currentTemp);
analogWrite(heaterPin, static_cast<int>(heaterPID.getOutput()));

Motor Speed Control

using namespace atp;

// DC motor control
AutoTunePID motorPID(0.0f, 255.0f, TuningMethod::CohenCoon);
motorPID.setSetpoint(1500.0f); // Target RPM

// In loop:
float currentRPM = measureMotorRPM();
motorPID.update(currentRPM);
analogWrite(motorPin, static_cast<int>(motorPID.getOutput()));

Position Control

using namespace atp;

// Servo position control
AutoTunePID servoPID(0.0f, 180.0f, TuningMethod::Manual);
servoPID.setManualGains(1.2f, 0.1f, 0.05f);
servoPID.setSetpoint(90.0f); // Target angle

// In loop:
float currentAngle = readServoPosition();
servoPID.update(currentAngle);
servo.write(static_cast<int>(servoPID.getOutput()));

Next Steps

For Beginners

  1. Try the Examples: Look at examples/BasicPID/BasicPID.ino
  2. Learn Manual Tuning: Read docs/manual.md
  3. Understand Auto-Tuning: See examples/ZieglerNichols/

For Advanced Users

  1. Operational Modes: Check docs/usage.md for all control modes
  2. Signal Filtering: Learn about anti-windup and filtering
  3. System Architecture: Read docs/system_architecture.md

Troubleshooting

  • Output not responding: Check your actuator wiring and power
  • Oscillating wildly: Reduce PID gains or use different tuning method
  • No change in output: Verify your setpoint and input ranges

Need Help?

  • Examples: Check examples/ folder for complete working sketches
  • Documentation: See all docs in docs/ folder
  • Issues: Report bugs on GitHub Issues

Happy controlling!