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

      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.
      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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control 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

    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.
    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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ###### tags: `程式組教程` # Mecanum Drive Odometry A user can use the mecanum drive kinematics classes in order to perform [odometry](https://hackmd.io/@Mo-Yu/HJfJHxZxc). WPILib contains a **MecanumDriveOdometry** class that can be used to track the position of a mecanum drive robot on the field. :::info **Note:** Because this method only uses encoders and a gyro, the estimate of the robot’s position on the field will drift over time, especially as your robot comes into contact with other robots during gameplay. However, odometry is usually very accurate during the autonomous period. ::: --- :::spoiler Chinese > perform 執行 > estimate 估計 > drift 飄移 > accurate 精準的 > period 其間 ::: --- # Creating the odometry object The **MecanumDriveOdometry** class requires two mandatory arguments and one optional argument. The mandatory arguments are the kinematics object that represents your mecanum drive (in the form of a **MecanumDriveKinematics** class) and the angle reported by your gyroscope (as a Rotation2d). The third optional argument is the starting pose of your robot on the field (as a **Pose2d**). By default, the robot will start at **x = 0, y = 0, theta = 0**. :::info **Note:** 0 degrees / radians represents the robot angle when the robot is facing directly toward your opponent’s alliance station. As your robot turns to the left, your gyroscope angle should increase. By default, WPILib gyros exhibit the opposite behavior, so you should negate the gyro angle. ::: --- :::spoiler Chinese > mandatory 強制的 > mandatory 參數 > optional 可選的 > represents 代表 > reported 回傳 ::: --- ==**API**== ``` Constructor and Description: Translation2d( double x, double y ) Explanation: The X and Y values are derived from their respective relative distances from the chassis i.e. Assume the center of the site as the origin ---------- Constructor: MecanumDriveOdometry( MecanumDriveKinematics kinematics, Rotation2d gyroAngle, Pose2d initialPoseMeters ) Description: Constructs a MecanumDriveOdometry object. ---------- Constructor: Pose2d(double x, double y, Rotation2d rotation) Description: Convenience constructors that takes in x and y values directly instead of having to construct a Translation2d. ---------- Constructor: Rotation2d() Description: Constructs a Rotation2d with a default angle of 0 degrees. ``` ==**JAVA**== ```java= // Locations of the wheels relative to the robot center. Translation2d m_frontLeftLocation = new Translation2d( 0.381, 0.381 ); Translation2d m_frontRightLocation = new Translation2d( 0.381, -0.381 ); Translation2d m_backLeftLocation = new Translation2d( -0.381, 0.381 ); Translation2d m_backRightLocation = new Translation2d( -0.381, -0.381 ); // Creating my kinematics object using the wheel locations. MecanumDriveKinematics m_kinematics = new MecanumDriveKinematics( m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation ); // Creating my odometry object from the kinematics object. // Here, our starting pose is 5 meters along the long end of the field // and in the center of the field along the short end, facing forward. MecanumDriveOdometry m_odometry = new MecanumDriveOdometry( m_kinematics, getGyroHeading(), new Pose2d( 5.0, 13.5, new Rotation2d() ) ); ``` ==**C++**== ```cpp= // Locations of the wheels relative to the robot center. frc::Translation2d m_frontLeftLocation{ 0.381_m, 0.381_m }; frc::Translation2d m_frontRightLocation{ 0.381_m, -0.381_m }; frc::Translation2d m_backLeftLocation{ -0.381_m, 0.381_m }; frc::Translation2d m_backRightLocation{ -0.381_m, -0.381_m }; // Creating my kinematics object using the wheel locations. frc::MecanumDriveKinematics m_kinematics{ m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation }; // Creating my odometry object from the kinematics object. // Here, our starting pose is 5 meters along the long end of the field and // in the center of the field along the short end, facing forward. frc::MecanumDriveOdometry m_odometry{ m_kinematics, GetGyroHeading(), frc::Pose2d{ 5_m, 13.5_m, 0_rad } }; ``` # Updating the robot pose The **update** method of the odometry class updates the robot position on the field. The update method takes in the gyro angle of the robot, along with a **MecanumDriveWheelSpeeds** object representing the speed of each of the 4 wheels on the robot. This **update** method must be called periodically, preferably in the **periodic()** method of a [Subsystem](https://docs.wpilib.org/en/stable/docs/software/commandbased/subsystems.html#subsystems). The **update** method returns the new updated pose of the robot. :::info **Note:** The **MecanumDriveWheelSpeeds** class in Java must be constructed with each wheel speed in meters per second. In C++, the units library must be used to represent your wheel speeds. ::: :::spoiler Chinese > takes in > along with 隨著 > periodically 定期的 > preferably 最好 > constructed 建構 > ::: ==**API**== ``` Modifier and Type: double Method: getRate() Description: Return the rate of rotation of the yaw (Z-axis) gyro, in degrees per second. ---------- Modifier and Type: static Rotation2d Method: fromDegrees( double degrees ) Description: Constructs and returns a Rotation2d with the given degree value. Method Details: public static Rotation2d fromDegrees(double degrees) Constructs and returns a Rotation2d with the given degree value. Parameters: degrees - The value of the angle in degrees. Returns: The rotation object with the desired angle value. ---------- Modifier and Type: getAngle() Description: Returns the total accumulated yaw angle (Z Axis, in degrees) reported by the sensor. ``` ==**JAVA**== ```java= @Override public void periodic() { // Get my wheel speeds var wheelSpeeds = new MecanumDriveWheelSpeeds( m_frontLeftEncoder.getRate(), m_frontRightEncoder.getRate(), m_backLeftEncoder.getRate(), m_backRightEncoder.getRate() ); // Get my gyro angle. // We are negating the value because gyros return positive // values as the robot turns clockwise. // This is not standard convention that is used by the WPILib classes. var gyroAngle = Rotation2d.fromDegrees( -m_gyro.getAngle() ); // Update the pose m_pose = m_odometry.update( gyroAngle, wheelSpeeds ); } ``` ==**C++**== ```cpp= void Periodic() override { // Get my wheel speeds frc::MecanumDriveWheelSpeeds wheelSpeeds{ units::meters_per_second_t(m_frontLeftEncoder.GetRate()), units::meters_per_second_t(m_frontRightEncoder.GetRate()), units::meters_per_second_t(m_backLeftEncoder.GetRate()), units::meters_per_second_t(m_backRightEncoder.GetRate()) }; // Get my gyro angle. We are negating the value because gyros return positive // values as the robot turns clockwise. This is not standard convention that is // used by the WPILib classes. frc::Rotation2d gyroAngle{ units::degree_t( -m_gyro.GetAngle()) }; // Update the pose m_pose = m_odometry.Update( gyroAngle, wheelSpeeds ); } ``` # Resetting the Robot Pose The robot pose can be reset via the **resetPose** method. This method accepts two arguments – the new field-relative pose and the current gyro angle. :::success **Important:** If at any time, you decide to reset your gyroscope, the **resetPose** method MUST be called with the new gyro angle. ::: :::info **Note:** A full example of a mecanum drive robot with odometry is available here: [C++](https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/MecanumBot) / [Java](https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot). ::: In addition, the **GetPose** (C++) / **getPoseMeters** (Java) methods can be used to retrieve the current robot pose without an update. :::spoiler Chinese > via 通過 > retrieve 取回 ::: # Original link and Reference website * [API - Pose2d](https://first.wpi.edu/wpilib/allwpilib/docs/release/java/edu/wpi/first/math/geometry/Pose2d.html) * [API - MecanumDriveOdometry](https://first.wpi.edu/wpilib/allwpilib/docs/release/java/edu/wpi/first/math/kinematics/MecanumDriveOdometry.html) * [API - Rotation2d](https://first.wpi.edu/wpilib/allwpilib/docs/release/java/edu/wpi/first/math/geometry/Rotation2d.html) * [API - Encoder(getRate)](https://www.kauailabs.com/public_files/navx-mxp/apidocs/java/com/kauailabs/navx/frc/AHRS.html)

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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