FRC_7130_4th
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # PID Adjustment ## 一、什麼是 PID ? 要來調 PID 前,總該先知道什麼是 [PID](https://www.youtube.com/watch?v=VRUSG7G58yY) 吧! > The PID controller is a commonly used feedback controller consisting of proportional, integral, and derivative terms, hence the name. This article will build up the definition of a PID controller term by term while trying to provide some intuition for how each of them behaves. > | $$r(t)$$ | setpoint | $$u(t)$$ | control input | > | -------- | -------- | -------- | -------- | > | $$e(t)$$ | error | $$y(t) $$ | output | >**Proportional Term 比例項** >Proportional gains act like a “software-defined springs” that pull the system toward the desired position. Recall from physics that we model springs as F = -kx where F is the force applied, is a proportional constant, and is the displacement from the equilibrium point. This can be written another way as F = k(0-x) where 0 is the equilibrium point. If we let the equilibrium point be our feedback controller’s setpoint, the equations have a one to one correspondence. >![](https://i.imgur.com/5aeMpDK.png) > **Derivative Term 導數項** > A PD controller has a proportional controller for position and a proportional controller for velocity. The velocity setpoint is implicitly provided by how the position setpoint changes over time. > ![](https://i.imgur.com/eZT4zhc.png) > **Integral Term 積分項** > The Integral term accumulates the area between the setpoint and output plots over time (i.e., the integral of position error) and adds the current total to the control input. Accumulating the area between two curves is called integration. > ![](https://i.imgur.com/VcJehse.png) > ![](https://i.imgur.com/aammPDA.png) > 資料來源:https://docs.wpilib.org/en/stable/docs/software/advanced-controls/introduction/introduction-to-pid.html ## 二、執行步驟 ### 1. 先定義要調整PID的馬達控制器 (最好只寫要調整的馬達就好) ```java= WPI_TalonFX masterShooter = new WPI_TalonFX(6); WPI_TalonFX slaveeShooter = new WPI_TalonFX(5); ``` ▲ 設定PID的馬達控制器的程式範例 ### 2. 若是該裝置由兩顆馬達一起控制,則須將跟隨也寫入程式 (且要注意是否需要設定反轉) ```java= slaveeShooter.follow(masterShooter); masterShooter.setInverted(true); slaveeShooter.setInverted(false); ``` ▲ 設定馬達控制器跟隨與設定馬達反轉的程式範例 ### 3. 在程式中加入下列程式用來將馬達控制器的數值回傳到SmartBoard/ShuffleBoard(記得將程式寫在robotPeriodic中,才會不斷讀取新數值)(可在一開始將位置歸零以方便觀察) ![](https://i.imgur.com/m3z6bin.png) ▲ 上圖為將馬達控制器讀取到的數值呈現在Shuffle Board/SmartDashBoard的程式範例 ![](https://i.imgur.com/rcwLVHj.png) ▲ 上圖為將馬達控制器的encorder的位置數值設為0的程式 ### 4. 連上機器人並開啟driverstation-shuffleboard(建議選擇shuffle Board) ![](https://i.imgur.com/dnmqDRu.png) ▲ 上圖為開啟Driver Station並開啟Shuffle Board的範例 ### 5. 開啟shuffleBoard並將預設數值全部刪除 ### 6. 開啟左側欄,選擇需要的數值按右鍵叫出show as : Graph 和 show as : Text View (如Position 則不須叫出圖表) ![](https://i.imgur.com/1nqsVoV.png) ▲ 上圖為Shuffle Board的左側選單顯示與拉出圖表與數值的例子 ![](https://i.imgur.com/klvcgd0.png) ▲ 上圖為完成叫出所有需要的數據和圖表時的情形 ### 7. 開啟Phoenix Tuner並連上機器人,並切換到CAN Device頁面 ![](https://i.imgur.com/QzvX9cf.png) ▲ 上圖為開啟Phoenix Tuner並轉到CAN Device的情形 ### 8. 點選要設定PID的馬達控制器,在左旁的Config選單中找到slot0的部分 ![](https://i.imgur.com/XjPlIsa.png) ▲ 上圖顯示點選要設定PID的馬達後在左方的Config中找到Slot0的範例 ### 9. 右邊選到Control,在Control Mode 為Percentage Output時,先調整中央拉條,再到ShuffleBoard觀察需要的速度(在調整拉條時要先將driver station 設定成enable 再將Phoenix Tuner 設定成 Control Enable) ![](https://i.imgur.com/cNz7egi.png) ▲ 上圖為使用Percentage Output尋找合適速度的範例(Phoenix Tuner) ![](https://i.imgur.com/lYvQBej.png) ▲ 上圖為用Percentage Output尋找適合的速度時,要到Shuffle Board來看確切數值以進行設定的範例 ### 10. 將Control Mode調整到Velocity的部分,並將set output to MAX 的值調整成剛才決定好的值,將set output to MIN 的值調整成負的剛才決定好的值,並將PID0: 中的選項調整成要調整的slot ![](https://i.imgur.com/GXcO7t2.png) ▲ 上圖為要開始調整PID時的Control面板的範例(需改變的地方有Control Mode 、Set Output to Max、Set Output to Min、PID0) ### 11. 先從KP值開始調,在調整KP時先從很小的值開始(10^(-6)),調整完後要點選下面的save ![](https://i.imgur.com/lSfzKpq.png) ▲ 上圖為調整KP的範例 ### 12. 調整中央拉條,將中央拉條拉到最大值,到ShuffleBoard觀察是否有達到期望的速度 ### 13. 若沒有,則再將KP值調大(建議以10倍為單位),並重複測試,直到該KP值有辦法很接近(但小於)期望的數值,之後再慢慢加大KP值直到速度無法再上升(通常就算KP值再調大,也會跟期望值有些許的差別。無法達到期望值,這時候就要藉由設定KI值來達到期望值) ![](https://i.imgur.com/VeCnI11.png) ▲ 上圖為只調整KP值時的圖形與數值,可看出既使達到速度最大值時,也無法觸及我們設定的期望值 ### 14. 設定KI值時也要從極小的數值慢慢往上調(以10倍為單位),並重複測試,讓速度能夠提升到期望值,在KI值很小時,會有比較不明顯的變化,但是若是數值太大,則會造成速度突然衝太高 ### 15. 有時候若是將KP和KI都調整好之後,數值就已經很完美,則就不用再繼續調整KD值 ![](https://i.imgur.com/S6Xlqjl.png) ▲ 上圖為調整KP、KI的範例 ![](https://i.imgur.com/ZPoCE2m.png) ▲ 上圖為設定完KP值和KI值的情形 ### 16. 若是調整完KI值,速度曲線衝過期望值的現象,再考慮進一步調整KD(這情況通常可以藉由將KI的值調小來解決,不過,有時候為了加快速度提升的速度會將KI值調整的略大,這時候再利用KD控制) ![](https://i.imgur.com/i0enLTP.png) ▲ 此圖為調整完KP和KI值後,仍建議調整KD的圖形情形 ![](https://i.imgur.com/QuVML6e.png) ▲ 上圖為設定過高的KI值時會產生的突然提速現象 ### 17. 由於KP和KI都是讓速度提升,但KD是讓速度下降,所以在調整KD值的時候,建議從1開始,以10倍為一單位往上測試 ![](https://i.imgur.com/2VKENQK.png) ▲ 上圖為調整KP、KI、KD的範例 ![](https://i.imgur.com/AbYz7If.png) ▲ 上圖為完成調整KP值、、KI值和KD值後呈現的完美數值 ## 三、注意事項 * 若該機構是由多個馬達控制,則在設定PID時要一次將所有有關聯的馬達一起設定 * 調整拉條時必須先把拉條歸零,在到Driver Station開啟Enable後才到Phoenix Tuner開啟Enable,才可慢慢移動拉條 * 在機器Enable時,手不可以去轉動正在設定的馬達,否則可能因為KP值過大導致馬達迅速迴轉導致手受傷 * 調整KP值和KI值時務必從小數值開始測試,以免馬達突然超高速旋轉使的馬達內部出現損毀 ![](https://i.imgur.com/zLiVeMX.png) ▲ 此圖為注意事項 ## 四、QA時間 :::info Q:為何要設定PID,不能直接使用Percentage Output? A:因為如果使用Percentage Output,馬達的轉速會因為電池的電壓下降而降速,特別是射球這類需要固定轉速的馬達非常建議設定PID ::: :::success Q:為何一開始要將Shuffle Board上的數值全部移除,無法沿用系統預設讀值 A: ::: ###### tags: `程式組教程`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully