Tech Toolbox
  • Please Visit https://ftc-tech-toolbox.vercel.app/ for the new tech toolbox!!
    • Introduction
    • Choosing an IDE
    • Creating an OpMode
    • Motors and Encoders
    • Servos
    • Gamepad Controls
    • Drive Systems
    • Lynx Modules
    • Telemetry
    • Wireless Download
    • The Sleep Command
  • Please Visit the New Link
    • Tank Drive / Skid Steer (Part 1)
    • Mecanum Drive (Part 1)
    • Turrets
    • Linear Slides
    • Kicker
    • Active Intake / Sweepers
    • Flywheels / Shooters
  • Please Visit the new Link
    • Base Class (Step 1)
    • Module Classes (Step 2)
    • OpMode Classes (Step 3)
  • This domain is now depreciated and is no longer updated!
  • This domain is now depreciated and is no longer updated!
    • What is Localization?
    • General Odometry Logic
    • Tank (No Deadwheels)
    • Mecanum (No Deadwheels)
    • Deadwheel Odometry (Mecanum and Tank)
    • VSLAM
  • This domain is now depreciated and is no longer updated!
    • What is Control Theory?
    • Custom PID Loops
    • Essential Control Theory Concepts
    • Resources for Learning Advanced Control Theory
  • This domain is now depreciated and is no longer updated! Please visit this domain for the new TT!
    • Introduction
    • Mecanum Drive (Part 2)
    • Tank Drive (Part 2)
    • Introduction to Pure Pursuit
    • Pure Pursuit: Mecanum
    • Pure Pursuit: Tank
    • Advanced Pure Pursuit
    • Guided Vector Fields
    • Autonomous Movement Libraries
  • Sensors
    • IMU
    • Color Sensors
      • Advanced Sensing Code
    • Distance Sensors
    • Touch Sensor
  • Computer Vision
    • Setting up Camera/Intro to Computer Vision Tools
      • Intro to OpenCV
      • Vuforia
    • Streaming Frames
    • Color Thresholding
    • April Tags
    • Linear Regression
    • Machine Learning Toolchain
    • Object Distance Estimation
    • Object Tracking / Driving to an Object
    • Computer Vision Simulators
  • Simulators
    • Beta8397 Simulator
    • VRS
  • Cool Codebases
Powered by GitBook
On this page
  • Logic
  • General Implementation
  1. This domain is now depreciated and is no longer updated!

General Odometry Logic

PreviousWhat is Localization?NextTank (No Deadwheels)

Last updated 1 year ago

The foundation of any autonomous movement system in a robot is the implementation of an accurate odometry localization algorithm. It allows the robot to accurately keep track of the its current position on the field.

On the surface the current position of the robot may seem to have little value, however, it is actually a key value in many navigation algorithms which allows the robot to traverse any point of the field.

Logic

General Logic As mentioned above, odometry allows the robot to keep track of its current position, relative to its origin. The algorithm starts by storing the robot’s initial position on the field which can be represented mathematically using a simple pose matrix:

O=(x0y0θ0)\begin{equation*} O = \begin{pmatrix} x_{0}\\ y_{0}\\ \theta_{0} \end{pmatrix} \end{equation*} O=​x0​y0​θ0​​​​

After the origin point is known, odometry then returns the amount that it has moved from its current position, also known as displacement.

We then add the displacement value to the robot's origin position to find the current position. This process is repeated every few milliseconds to ensure the position that is stored is as accurate as possible to the true position of the robot. The equation used to update the position continuously can be mathematically represented below:

(xyθ)=O+(ΔxΔyΔθ)\begin{equation*} \begin{pmatrix} x\\ y\\ \theta \end{pmatrix} = O + \begin{pmatrix} \Delta{x}\\ \Delta{y}\\ \Delta{\theta} \end{pmatrix} \end{equation*}​xyθ​​=O+​ΔxΔyΔθ​​​

Simply explained, the current position of the robot is equal to the origin of the robot, the OOO matrix, plus the displacement of the robot, the Δ\DeltaΔ matrix. The Δx\Delta{x}Δx, Δy\Delta{y}Δy, and Δθ\Delta{\theta}Δθ symbols in the matrix represent the amount that the robot has strafed (sideways movement), moved forward, and turned, respective to the robot's origin.

Now that we know that odometry works by updating its position by using the robot’s origin or previously found position value and summing it by the robot’s displacement, a key question may be asked: How is the displacement value of the robot calculated?

Teams use odometry input sources, essentially specialized sensors, that return raw position data, and when processed, the displacement of the robot can be calculated. These sensors used as well as their implementations in code will be covered in the following sections.

General Implementation

When implementing this process practically, the logic from the theoretical explanation above mostly carries over, however, in the code, there are a few small changes to the equation. At the beginning of the program, a current-position variable is initialized to the robot's starting point.

void updatePosition(){
    Point currentPosition = (0, 0, 0); // initialized to origin 
    // point, equal to $O$ matrix; changes
    // depending on the starting point of the robot on field
    Input OdometryInputSource = new Input();
    
        /* By continuously summing the amount the robot has moved from the previously 
        calculated position, the robot can be localized.
        Theoretical Equation: currentPosition = origin + overallDisplacement
        
        New Equation: currentPosition = 
        previouslyCalculatedPosition + displacementFromPreviousPosition
        */
    while(matchIsOccurring){
        Point displacement = OdometryInputSource.getDisplacement(); // receives
        // the $\Delta$ matrix of the equation
        

        currentPosition.x = currentPosition.x + displacement.x;
        currentPosition.y = currentPosition.y + displacement.y;
        currentPosition.theta = currentPosition.theta + displacement.theta;
    }
}

Then in every other iteration of the code, this value is updated continuously by adding the displacement values, or the Δ\DeltaΔ matrix, received from the odometry input sources. This means that the current-position matrix is set to the OOO matrix to store the origin, and as the program starts it updates itself by summing itself by the displacement from the previously calculated position. This in turn leaves us with a modified equation, which is displayed in the pseudocode below: