FRC #7589 Lishan Blue Magpie
      • 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
    # 程式101 ###### tags: `程式` `函式庫安裝` ## 安裝環境 有(at least)三包東西要安裝 ### 1. FRC game tool 由NI(National Instrument)提供 對機器通訊用的程式們,例如Driver Station (以及LabVIEW編寫FRC機器用的library [^LabVIEWLib]) https://www.ni.com/zh-tw/support/downloads/drivers/download.frc-game-tools.html#440024 [^LabVIEWLib]: 類似於java要裝WPILib這個程式庫才能寫FRC的程式,LabVIEW要裝這些library才能寫FRC,總之不是我們要用的東西 ### 2. WPILib 由[WPI](https://zh.wikipedia.org/zh-tw/%E4%BC%8D%E6%96%AF%E7%89%B9%E7%90%86%E5%B7%A5%E5%AD%A6%E9%99%A2)提供 讓C++/java可以寫FRC機器程式的library,以及code裡面寫說在`edu.wpi.first.wpilibj`package底下的所有東西 內含VSCode、Smart dashboard等,一堆很厲害的東西 https://github.com/wpilibsuite/allwpilib/releases ### 3. [3rd Party libraries](https://docs.wpilib.org/en/stable/docs/software/vscode-overview/3rd-party-libraries.html) #### [線上安裝方法(Online Installation)](https://docs.wpilib.org/en/latest/docs/software/vscode-overview/3rd-party-libraries.html#adding-offline-libraries) * 打開 WPILib VS Code 並點擊右上角的 WPILib 圖示 * 選擇Manage Vendor Libraries * 按一下Install new libraries (online) * 貼上URL並按下Enter #### 1.REV Robotics REVLib 搭配SPARK MAX和Color Sensor V3 *Online Installation URL:* https://software-metadata.revrobotics.com/REVLib-2024.json *Offline Installation* * 下載REVLib壓縮檔 * 解壓縮後將所有資料夾複製到”C:\Users\Public\wpilib\2024”中 * 完成安裝 https://docs.revrobotics.com/brushless/revlib/revlib-overview#c-and-java-installation #### 2.[CTRE Phoenix Framework](https://store.ctr-electronics.com/software/) 由CTRE(Victor SPX, Talon SRX馬達控制器和CANcoder, CANifier, Pigeon IMU, Pigeon 2.0等CAN裝置的製造商)提供 要操作這兩種馬達控制器用的,還有馬達控制器的很多特異功能 還有[Pheonix tuner X](https://v6.docs.ctr-electronics.com/en/stable/docs/tuner/index.html) *Online Installation URL:* Phoenix 6: https://maven.ctr-electronics.com/release/com/ctre/phoenix6/latest/Phoenix6-frc2024-latest.json *Offline Installation* * 選擇FRC Offline Installer * 在FRC Libraries中勾選"C++/Java" * 等待安裝完成 https://docs.ctr-electronics.com/ ref: https://docs.wpilib.org/en/stable/docs/software/can-devices/third-party-devices.html #### 3.[Kauai Labs](https://pdocs.kauailabs.com/navx-mxp/software/roborio-libraries/java/) 搭配NavX-MXP使用,離線安裝的檔案目前沒有更新,建議使用線上安裝 *Online Installation URL:* https://dev.studica.com/releases/2024/NavX.json ``` //宣告 m_ahrs = new AHRS(SerialPort.Port.kMXP); ``` --- ## 創建新專案 1. 打開VSCode 2. ctrl+shift+P -> "WPILib: create a new project" 3. (GUI表單) 選擇語言(C++/Java), 框架(Timed/Command), 資料夾, 隊號 4. ctrl+shift+P -> "WPILib: Manage Vendor Libraries" 或 檔案列表build.gradle按右鍵"Manage Vendor Libraries" 5. -> "install new libraries" -> "CTRE-Pheonix" (1,2,3 ref: https://docs.wpilib.org/en/latest/docs/zero-to-robot/step-4/creating-benchtop-test-program-cpp-java.html) (1,2,3 ref: https://docs.wpilib.org/en/stable/docs/software/vscode-overview/creating-robot-program.html) (4,5 ref: https://docs.wpilib.org/en/latest/docs/software/vscode-overview/3rd-party-libraries.html) --- ## 編譯上傳 ctrl+shift+P -> "WPILib: Deploy Robot Code" 或 檔案列表build.gradle按右鍵"Deploy Robot Code" --- ## Timed Robot 基本架構 `src\main\java\frc\robot\Robot.java` ```java public void robotInit() { // 機器剛開機執行一次 // 用來初始化各個元件(搖桿&馬達) } public void teleopInit() { // 剛進入teleOp模式時執行一次 // 通常留空,或者設定一些狀態例如變速檔位,以及機器初始狀態所有馬達靜止 } public void teleopPeriodic() { // 在teleOp模式時每20ms一直重複執行 // 大部分事情寫在這裡 } // 自走模式的init和periodic public void autonomousInit() { } public void autonomousPeriodic() { } ``` --- ## 基本元件 ### XboxController `XboxController` extends `GenericHID` https://docs.wpilib.org/en/stable/docs/software/basic-programming/joystick.html#xboxcontroller-class https://first.wpi.edu/wpilib/allwpilib/docs/release/java/edu/wpi/first/wpilibj/XboxController.html ```java import edu.wpi.first.wpilibj.XboxController; ... XboxController con; ... con = new XboxController(0); ... con.getAButton(); // 被按著 con.getAButtonPressed(); // 按一次 con.getAButtonReleased(); // 放開(一次) ... con.getLeftX(); // 左蘑菇頭的X軸 ... // methods inherit from GenericHID con.getPOV(0) // 第0個POV被按下的角度 con.getPOV() // 預設(第0個)POV被按下的角度 /* Don't use these: con.getRawButton(6) // 第6顆按鈕被按著 con.getRawButtonPressed(6) // 第6顆按鈕被按下過 con.getRawButtonReleased(6) // 第6顆按鈕被放開過 // 按鈕編號從1開始 con.getRawAxis(3) // 第0個軸 // 軸編號從0開始 */ ``` ### WPI_VictorSPX `WPI_VictorSPX` extends `VictorSPX` https://api.ctr-electronics.com/phoenix/release/java/com/ctre/phoenix/motorcontrol/can/WPI_VictorSPX.html ```java import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX; ... WPI_VictorSPX motor1; ... motor1 = new WPI_VictorSPX(8); ... motor1.set(-0.4) ``` --- ## Smart Dashboard https://docs.wpilib.org/en/stable/docs/software/dashboards/shuffleboard/getting-started/shuffleboard-tour.html https://first.wpi.edu/wpilib/allwpilib/docs/release/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.html ```java import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; ... SmartDashboard.putNumber("Car_Speed", 0); ... carspeed=SmartDashboard.getNumber("Car_Speed", 0); ``` --- ## Example code ```java // Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package frc.robot; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.XboxController; import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX; /** * The VM is configured to automatically run this class, and to call the * functions corresponding to * each mode, as described in the TimedRobot documentation. If you change the * name of this class or * the package after creating this project, you must also update the * build.gradle file in the * project. */ public class Robot extends TimedRobot { private XboxController con; private WPI_VictorSPX motor1; /** * This function is run when the robot is first started up and should be used * for any * initialization code. */ @Override public void robotInit() { con = new XboxController(0); motor1 = new WPI_VictorSPX(8); } /** * This function is called every 20 ms, no matter the mode. Use this for items * like diagnostics * that you want ran during disabled, autonomous, teleoperated and test. * * <p> * This runs after the mode specific periodic functions, but before LiveWindow * and * SmartDashboard integrated updating. */ @Override public void robotPeriodic() { } /** * This autonomous (along with the chooser code above) shows how to select * between different * autonomous modes using the dashboard. The sendable chooser code works with * the Java * SmartDashboard. If you prefer the LabVIEW Dashboard, remove all of the * chooser code and * uncomment the getString line to get the auto name from the text box below the * Gyro * * <p> * You can add additional auto modes by adding additional comparisons to the * switch structure * below with additional strings. If using the SendableChooser make sure to add * them to the * chooser code above as well. */ @Override public void autonomousInit() { } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { } /** This function is called once when teleop is enabled. */ @Override public void teleopInit() { } /** This function is called periodically during operator control. */ @Override public void teleopPeriodic() { if (con.getAButton()) { motor1.set(0.3); } else { motor1.set(0.0); } } /** This function is called once when the robot is disabled. */ @Override public void disabledInit() { } /** This function is called periodically when disabled. */ @Override public void disabledPeriodic() { } /** This function is called once when test mode is enabled. */ @Override public void testInit() { } /** This function is called periodically during test mode. */ @Override public void testPeriodic() { } /** This function is called once when the robot is first started up. */ @Override public void simulationInit() { } /** This function is called periodically whilst in simulation. */ @Override public void simulationPeriodic() { } } ``` ```java // Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package frc.robot; import edu.wpi.first.wpilibj.TimedRobot; /** * The VM is configured to automatically run this class, and to call the * functions corresponding to * each mode, as described in the TimedRobot documentation. If you change the * name of this class or * the package after creating this project, you must also update the * build.gradle file in the * project. */ public class Robot extends TimedRobot { /** * This function is run when the robot is first started up and should be used * for any * initialization code. */ @Override public void robotInit() { } /** * This function is called every 20 ms, no matter the mode. Use this for items * like diagnostics * that you want ran during disabled, autonomous, teleoperated and test. * * <p> * This runs after the mode specific periodic functions, but before LiveWindow * and * SmartDashboard integrated updating. */ @Override public void robotPeriodic() { } /** * This autonomous (along with the chooser code above) shows how to select * between different * autonomous modes using the dashboard. The sendable chooser code works with * the Java * SmartDashboard. If you prefer the LabVIEW Dashboard, remove all of the * chooser code and * uncomment the getString line to get the auto name from the text box below the * Gyro * * <p> * You can add additional auto modes by adding additional comparisons to the * switch structure * below with additional strings. If using the SendableChooser make sure to add * them to the * chooser code above as well. */ @Override public void autonomousInit() { } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { } /** This function is called once when teleop is enabled. */ @Override public void teleopInit() { } /** This function is called periodically during operator control. */ @Override public void teleopPeriodic() { } /** This function is called once when the robot is disabled. */ @Override public void disabledInit() { } /** This function is called periodically when disabled. */ @Override public void disabledPeriodic() { } /** This function is called once when test mode is enabled. */ @Override public void testInit() { } /** This function is called periodically during test mode. */ @Override public void testPeriodic() { } /** This function is called once when the robot is first started up. */ @Override public void simulationInit() { } /** This function is called periodically whilst in simulation. */ @Override public void simulationPeriodic() { } } ```

    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