{"id":32819376,"url":"https://github.com/crissccl/digital_controlsim","last_synced_at":"2025-11-07T13:02:18.587Z","repository":{"id":320909674,"uuid":"1083638819","full_name":"CrissCCL/Digital_ControlSim","owner":"CrissCCL","description":"Tutorial-oriented simulation of a discrete-time PI control loop applied to a first-order system. Includes actuator saturation to emulate real microcontroller behavior. Designed for educational purposes and digital control learning.","archived":false,"fork":false,"pushed_at":"2025-10-26T17:19:18.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-26T18:29:07.303Z","etag":null,"topics":["arduino","digital-control","education","esp32","first-order-system","matlab","pi-controller","saturation","simulation","teensy","tutorial"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"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/CrissCCL.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-26T12:43:19.000Z","updated_at":"2025-10-26T17:19:22.000Z","dependencies_parsed_at":"2025-10-26T18:29:09.033Z","dependency_job_id":null,"html_url":"https://github.com/CrissCCL/Digital_ControlSim","commit_stats":null,"previous_names":["crissccl/digital_controlsim"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/CrissCCL/Digital_ControlSim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissCCL%2FDigital_ControlSim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissCCL%2FDigital_ControlSim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissCCL%2FDigital_ControlSim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissCCL%2FDigital_ControlSim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CrissCCL","download_url":"https://codeload.github.com/CrissCCL/Digital_ControlSim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissCCL%2FDigital_ControlSim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283190205,"owners_count":26794589,"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","status":"online","status_checked_at":"2025-11-07T02:00:06.343Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","digital-control","education","esp32","first-order-system","matlab","pi-controller","saturation","simulation","teensy","tutorial"],"created_at":"2025-11-07T13:01:42.930Z","updated_at":"2025-11-07T13:02:18.570Z","avatar_url":"https://github.com/CrissCCL.png","language":"MATLAB","readme":"# 🧪 Digital Control Simulation — First Order System + Saturation\n\nThis repository provides a **tutorial-oriented simulation** of a **digital PI control loop** applied to a **first-order system identified via non-parametric methods**.  \nThe objective is to reproduce in simulation the **same discrete behavior** expected when the controller is later implemented on a **microcontroller** (Arduino, Teensy, ESP32, etc.), including **actuator saturation**.\n\n\u003e ⚠️ **Note:** This tutorial is for **educational purposes only**. It focuses on simulation and understanding discrete-time digital control.\n\n## 🎯 Goals of the Tutorial\n\n- Model a first-order process identified experimentally (non-parametric fit)\n- Discretize the plant using Zero-Order Hold (ZOH)\n- Implement a **discrete PI controller** using incremental form\n- Add **saturation limits** to emulate real actuator constraints\n- Compare reference tracking and control signal behavior\n\n## 🧩 System Model\n\nA first-order model without delay was identified experimentally from step-response data:\n\n$$\nG_p(s) = \\frac{K}{\\tau s + 1}\n$$\n\nIn the included example:\n\n$$\nG_p(s)= \\frac{20}{50s + 1}\n$$\n\nThis model is discretized with sampling period  \n$$T_s = 0.1 s$$  \n\nusing Zero-Order Hold.\n\n```matlab\nTs = 0.1;\ngp  = tf(20,[50 1]);           % First-order plant\ngpd = c2d(gp,Ts,'zoh');        % Discrete plant\n[num,den] = tfdata(gpd,'v');\n```\nThe discrete model implemented is:\n\n```matlab\ny(k) = num(2)*u1 - den(2)*y1;\n```\n\n## ⚙️ Digital PI Controller (Incremental Form)\n\nThe discrete control law implemented is:\n\n$$\nu(k)=u(k-1)+K_0 e(k)+K_1 e(k-1)\n$$\n\n```matlab\n    error  = Ref(k) - y(k);\n    u  = u1 + K0*error + K1*error1;\n```\n\nWith tuning parameters derived from:\n- Proportional gain: $$K_p$$\n- Integral time: $$T_i$$\n- Sampling time: $$T_s$$\n\nWhere\n\n$$\nK_0 = K_p + \\frac{K_p}{2T_i}T_s\n$$\n\n$$\nK_1 = -K_p + \\frac{K_p}{2T_i}T_s\n$$\n\n\n## 🔒 Actuator Saturation\nTo emulate microcontroller behavior, the controller output is **limited to a predefined range**:\n\n- Prevents unrealistic actuator commands  \n- Reflects PWM or DAC limits on embedded hardware  \n- Avoids integrator wind-up if actuator saturates\n\nExample: 0% ≤ u(n) ≤ 100%\n\nWithout saturation, simulation results may falsely assume an ideal actuator with infinite authority, which never matches microcontroller deployments.\nTo emulate real microcontroller behavior — such as PWM range or fixed DAC limits —  \na **hard saturation** is enforced:\n\n```matlab\nif u \u003e 100\n    u=100;\nend\nif u\u003c 0\n    u=0;\nend\n```\n\nBelow are example plots generated with the script:\n\n\u003cp align=\"center\"\u003e\n\u003cimg width=\"500\" alt=\"Control simulation\" src=\"https://github.com/user-attachments/assets/f208de9a-0f46-4059-af58-50642f70e590\" /\u003e\n\u003c/p\u003e\n\n## 📜 License\nMIT License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrissccl%2Fdigital_controlsim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrissccl%2Fdigital_controlsim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrissccl%2Fdigital_controlsim/lists"}