{"id":18810718,"url":"https://github.com/jackw01/arduino-pid-autotuner","last_synced_at":"2025-05-05T22:35:45.428Z","repository":{"id":41416695,"uuid":"93464620","full_name":"jackw01/arduino-pid-autotuner","owner":"jackw01","description":"Automated PID tuning using Ziegler-Nichols/relay method","archived":false,"fork":false,"pushed_at":"2022-10-04T13:15:28.000Z","size":24,"stargazers_count":190,"open_issues_count":3,"forks_count":61,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-31T00:23:41.232Z","etag":null,"topics":["arduino","arduino-library","embedded","microcontrollers","pid-control"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jackw01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-06T01:58:15.000Z","updated_at":"2025-03-23T19:47:54.000Z","dependencies_parsed_at":"2023-01-19T04:02:29.748Z","dependency_job_id":null,"html_url":"https://github.com/jackw01/arduino-pid-autotuner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackw01%2Farduino-pid-autotuner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackw01%2Farduino-pid-autotuner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackw01%2Farduino-pid-autotuner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackw01%2Farduino-pid-autotuner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackw01","download_url":"https://codeload.github.com/jackw01/arduino-pid-autotuner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252587345,"owners_count":21772451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-library","embedded","microcontrollers","pid-control"],"created_at":"2024-11-07T23:21:59.152Z","updated_at":"2025-05-05T22:35:45.407Z","avatar_url":"https://github.com/jackw01.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arduino-pid-autotuner\nAutomated PID tuning using Ziegler-Nichols/relay method.\n\nOriginally written for Arduino and compatible boards, but does not rely on the Arduino standard library.\n\n## Disclaimer\n**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](https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method) 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.**\n\n## How does it work?\n`pidautotuner.h` and `pidautotuner.cpp` are fully commented to explain how the algorithm works.\n\n## What PID controller does this work with?\nThis algorithm should work with any implementation of PID control if it is properly configured.\n\n## Example code (Arduino)\n```c\n#include \u003cpidautotuner.h\u003e\n\nvoid setup() {\n\n    PIDAutotuner tuner = PIDAutotuner();\n\n    // Set the target value to tune to\n    // This will depend on what you are tuning. This should be set to a value within\n    // the usual range of the setpoint. For low-inertia systems, values at the lower\n    // end of this range usually give better results. For anything else, start with a\n    // value at the middle of the range.\n    tuner.setTargetInputValue(targetInputValue);\n\n    // Set the loop interval in microseconds\n    // This must be the same as the interval the PID control loop will run at\n    tuner.setLoopInterval(loopInterval);\n\n    // Set the output range\n    // These are the minimum and maximum possible output values of whatever you are\n    // using to control the system (Arduino analogWrite, for example, is 0-255)\n    tuner.setOutputRange(0, 255);\n\n    // Set the Ziegler-Nichols tuning mode\n    // Set it to either PIDAutotuner::ZNModeBasicPID, PIDAutotuner::ZNModeLessOvershoot,\n    // or PIDAutotuner::ZNModeNoOvershoot. Defaults to ZNModeNoOvershoot as it is the\n    // safest option.\n    tuner.setZNMode(PIDAutotuner::ZNModeBasicPID);\n\n    // This must be called immediately before the tuning loop\n    // Must be called with the current time in microseconds\n    tuner.startTuningLoop(micros());\n\n    // Run a loop until tuner.isFinished() returns true\n    long microseconds;\n    while (!tuner.isFinished()) {\n\n        // This loop must run at the same speed as the PID control loop being tuned\n        long prevMicroseconds = microseconds;\n        microseconds = micros();\n\n        // Get input value here (temperature, encoder position, velocity, etc)\n        double input = doSomethingToGetInput();\n\n        // Call tunePID() with the input value and current time in microseconds\n        double output = tuner.tunePID(input, microseconds);\n\n        // Set the output - tunePid() will return values within the range configured\n        // by setOutputRange(). Don't change the value or the tuning results will be\n        // incorrect.\n        doSomethingToSetOutput(output);\n\n        // This loop must run at the same speed as the PID control loop being tuned\n        while (micros() - microseconds \u003c loopInterval) delayMicroseconds(1);\n    }\n\n    // Turn the output off here.\n    doSomethingToSetOutput(0);\n\n    // Get PID gains - set your PID controller's gains to these\n    double kp = tuner.getKp();\n    double ki = tuner.getKi();\n    double kd = tuner.getKd();\n}\n\nvoid loop() {\n\n    // ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackw01%2Farduino-pid-autotuner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackw01%2Farduino-pid-autotuner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackw01%2Farduino-pid-autotuner/lists"}