All Projects → jackw01 → arduino-pid-autotuner

jackw01 / arduino-pid-autotuner

Licence: MIT license
Automated PID tuning using Ziegler-Nichols/relay method

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to arduino-pid-autotuner

Button2
Arduino Library to simplify working with buttons. It allows you to use callback functions to track single, double, triple and long clicks. It also takes care of debouncing.
Stars: ✭ 109 (+7.92%)
Mutual labels:  embedded, arduino-library
NuttX
Official micro-ROS RTOS
Stars: ✭ 63 (-37.62%)
Mutual labels:  embedded, microcontrollers
CML
Fast, safe and easy to use Cortex-M HAL Library, written in C++ 17
Stars: ✭ 17 (-83.17%)
Mutual labels:  embedded, microcontrollers
Guislice
GUIslice drag & drop embedded GUI in C for touchscreen TFT on Arduino, Raspberry Pi, ARM, ESP8266 / ESP32 / M5stack using Adafruit-GFX / TFT_eSPI / UTFT / SDL
Stars: ✭ 534 (+428.71%)
Mutual labels:  embedded, arduino-library
AutomationShield
Arduino library and MATLAB/Simulink API for the AutomationShield Arduino expansion boards for control engineering education.
Stars: ✭ 22 (-78.22%)
Mutual labels:  embedded, arduino-library
Arduinojson
📟 JSON library for Arduino and embedded C++. Simple and efficient.
Stars: ✭ 5,456 (+5301.98%)
Mutual labels:  embedded, arduino-library
ArduinoSpritzCipher
Spritz encryption system portable C library, CSPRNG, cryptographic hash and MAC functions, symmetric-key data encryption, and general-purpose functions. It's also an Arduino library.
Stars: ✭ 67 (-33.66%)
Mutual labels:  embedded, arduino-library
Easyntpclient
Library to read time from Network Time Protocol (NTP) servers.
Stars: ✭ 20 (-80.2%)
Mutual labels:  embedded, arduino-library
Helios
The free embedded operating system.
Stars: ✭ 223 (+120.79%)
Mutual labels:  embedded, arduino-library
Arduino-FrequencyDetector
Fast audio frequency detector without fft for plain Arduino and Attiny85. Whistle switch example included.
Stars: ✭ 22 (-78.22%)
Mutual labels:  arduino-library
micropython-tft-gui
Simple GUI for Pyboard and TFT touch panel displays
Stars: ✭ 72 (-28.71%)
Mutual labels:  embedded
atat
no_std crate for parsing AT commands
Stars: ✭ 50 (-50.5%)
Mutual labels:  embedded
SparkFun ADXL345 Arduino Library
Arduino Library for the ADXL345
Stars: ✭ 34 (-66.34%)
Mutual labels:  arduino-library
rosedb
🚀 A high performance NoSQL database based on bitcask, supports string, list, hash, set, and sorted set.
Stars: ✭ 2,957 (+2827.72%)
Mutual labels:  embedded
Modbus-TCP
Modbus TCP client library to interact with Modbus servers such as PLCs.
Stars: ✭ 43 (-57.43%)
Mutual labels:  arduino-library
Loom
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Stars: ✭ 24 (-76.24%)
Mutual labels:  arduino-library
miZy
miZy - tiny fast embedded linux
Stars: ✭ 106 (+4.95%)
Mutual labels:  embedded
nrf52832-pac
Peripheral Access Crate for the nRF52832 microcontroller
Stars: ✭ 21 (-79.21%)
Mutual labels:  embedded
bxcan
bxCAN peripheral driver for STM32 chips
Stars: ✭ 22 (-78.22%)
Mutual labels:  embedded
piranha
Piranha - a modern cloud runtime
Stars: ✭ 136 (+34.65%)
Mutual labels:  embedded

arduino-pid-autotuner

Automated PID tuning using Ziegler-Nichols/relay method.

Originally written for Arduino and compatible boards, but does not rely on the Arduino standard library.

Disclaimer

Issues have been disabled on this repository due to too many off-topic questions about PID control in general or how to use this code. This project is a simple implementation of the algorithm described here and is not guaranteed to work in every use case. If you don't know what this code is intended to do, you probably don't need to use it.

How does it work?

pidautotuner.h and pidautotuner.cpp are fully commented to explain how the algorithm works.

What PID controller does this work with?

This algorithm should work with any implementation of PID control if it is properly configured.

Example code (Arduino)

#include <pidautotuner.h>

void setup() {

    PIDAutotuner tuner = PIDAutotuner();

    // Set the target value to tune to
    // This will depend on what you are tuning. This should be set to a value within
    // the usual range of the setpoint. For low-inertia systems, values at the lower
    // end of this range usually give better results. For anything else, start with a
    // value at the middle of the range.
    tuner.setTargetInputValue(targetInputValue);

    // Set the loop interval in microseconds
    // This must be the same as the interval the PID control loop will run at
    tuner.setLoopInterval(loopInterval);

    // Set the output range
    // These are the minimum and maximum possible output values of whatever you are
    // using to control the system (Arduino analogWrite, for example, is 0-255)
    tuner.setOutputRange(0, 255);

    // Set the Ziegler-Nichols tuning mode
    // Set it to either PIDAutotuner::ZNModeBasicPID, PIDAutotuner::ZNModeLessOvershoot,
    // or PIDAutotuner::ZNModeNoOvershoot. Defaults to ZNModeNoOvershoot as it is the
    // safest option.
    tuner.setZNMode(PIDAutotuner::ZNModeBasicPID);

    // This must be called immediately before the tuning loop
    // Must be called with the current time in microseconds
    tuner.startTuningLoop(micros());

    // Run a loop until tuner.isFinished() returns true
    long microseconds;
    while (!tuner.isFinished()) {

        // This loop must run at the same speed as the PID control loop being tuned
        long prevMicroseconds = microseconds;
        microseconds = micros();

        // Get input value here (temperature, encoder position, velocity, etc)
        double input = doSomethingToGetInput();

        // Call tunePID() with the input value and current time in microseconds
        double output = tuner.tunePID(input, microseconds);

        // Set the output - tunePid() will return values within the range configured
        // by setOutputRange(). Don't change the value or the tuning results will be
        // incorrect.
        doSomethingToSetOutput(output);

        // This loop must run at the same speed as the PID control loop being tuned
        while (micros() - microseconds < loopInterval) delayMicroseconds(1);
    }

    // Turn the output off here.
    doSomethingToSetOutput(0);

    // Get PID gains - set your PID controller's gains to these
    double kp = tuner.getKp();
    double ki = tuner.getKi();
    double kd = tuner.getKd();
}

void loop() {

    // ...
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].