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
  1. This domain is now depreciated and is no longer updated! Please visit this domain for the new TT!

Tank Drive (Part 2)

PreviousMecanum Drive (Part 2)NextIntroduction to Pure Pursuit

Last updated 1 year ago

Prerequisites:

  • - Get a solid understanding of coordinate-based autonomous movement first.

Resources

  • - Must read! Excellent guide explaining the logic behind a tank drive system controller.

We will now be creating a far more accurate movement system for our tank robot, which if done correctly, should look something like this:

For the various benefits of using this type of movement controller as opposed to the previous controller mentioned in part one, please refer to Mecanum Drive part 2.

In general, this controller involves feeding in the coordinate point the robot must travel to and the desired heading of the robot. Unlike a mecanum robot, a tank drive system cannot move sideways, meaning we cannot simultaneously move to the desired point and turn to the desired angle. This means the robot must reach the desired (x,y) point before turning to the desired heading.

As mentioned in the mecanum section we will be making use of a positional feedback controller that relies on our odometry localization to check the controller's status. By continuously analyzing the error between the goal point and the robot's current position we can power the robot's motors in such a way that it is driven toward the destination point. Given that your localization system is accurate, this results in improved accuracy and consistency in the final position of the robot.

The math behind this controller is explained very well in CTL ALT FTC, which we have linked below:

Implementation

Although the implementation found in CTRL ALT FTC is of high quality it does not show how to terminate the loop so that the robot can complete other tasks.

To do this we follow the same concept seen in the mecanum part 2 module. If both the position and angle threshold has been reached then we can exit from the loop. However, if there is another type of error we need another method of exiting the controller, this is where the timeout method comes into play.

We are going to assume that you know how to implement a PID controller by now, make sure to use different coefficients for the distance and angle controller.

double timeout = 5000; // 5000 ms or 5 seconds
boolean loopIsActive = true;
double threshold = 2, angleThreshold = 2; // 2 inches and 2 degrees of error allowed 
distanceController = new PID();
angleController = new PID();  // make sure this follows "Dealing with Angles" 
ElapsedTime timer = new ElapsedTime();

public void setRobotRelative(f,t){
    frontLeftMotor.setPower(f + t);
    backLeftMotor.setPower(f + t);
    frontRightMotor.setPower(f - t);
    backRightMotor.setPower(f - t);
}

while (loopIsActive && timer.milliseconds() <= timeout) {
    double xError = targetX - robotX;
    double yError = targetY - robotY; 
    double theta = Math.atan2(yError,xError);
    // 0 is the reference because we want the distance to go to 0 
    double distance = Math.hypot(xError, yError);
    double f, t; // forward power, turn power
    if (distance < threshold) { // assuming the coordinate position is correct.... 
         f = 0;
         t = angleController.calculate(targetAngle, robotTheta);      
         double angleError = targetAngle - robotTheta; // check angle error. 
         if(Math.abs(angleError) < angleThreshold){
             loopIsActive = false;  // break when the condition is reached. 
         }
    } else {
        f = distanceController.calculate(0, distance); 
        t = angleController.calculate(theta, robotTheta);
    }
    // Range.clip is included in the SDK and will clip between two values
    // angleController.error is a demonstrative attribute that gets the error. 
    f *= Math.cos(Range.clip(angleController.error, -PI/2, PI/2));
    
    // set motor power here! 
    setRobotRelative(f,t); 
    
}

Mecanum Drive Part 2
Localization
CTRL ALT FTC
Drivetrain ControlCTRL ALT FTC
Logo