Difference between revisions of "FTC Using methods 20203018"

From wikidb
Jump to: navigation, search
(Full Code One Method)
(Code Outline)
Line 16: Line 16:
 
     public void runOpMode() throws InterruptedException
 
     public void runOpMode() throws InterruptedException
 
     {
 
     {
 +
        double TARGET_DISTANCE    = 300;        // mm (about 12 inches)
 +
        double MAX_MOTOR_VELOCITY = 600;        // mm / second
 +
        double TARGET_VELOCITY    = MAX_MOTOR_VELOCITY / 4;
 +
        double TARGET_TURN        =  90;        // degrees
 +
        int    SQUARE_SIDES      =  4;
 +
 
         waitForStart();
 
         waitForStart();
 
         int count = 0;
 
         int count = 0;

Revision as of 12:17, 18 March 2022

Why Use Abstraction

  • Makes it easier to reason about complex programs
  • Easier to test programs - can test small part individually
  • Code is reused making it more reliable

Code Outline

  • Code based on FTC_Motor_Encoders_20200304
  • Enhance the drive forward with encoders using the setVelocity to drive the robot in a square.

public  class DriveInASquare extends LinearOpMode
{
    @Override
    public void runOpMode() throws InterruptedException
    {
        double TARGET_DISTANCE    = 300;         // mm (about 12 inches)
        double MAX_MOTOR_VELOCITY = 600;         // mm / second
        double TARGET_VELOCITY    = MAX_MOTOR_VELOCITY / 4;
        double TARGET_TURN        =  90;         // degrees
        int    SQUARE_SIDES       =   4;

        waitForStart();
        int count = 0;
        while (opModeIsActive() && count < SQUARE_SIDES)
        {
            driveForMmAt (TARGET_DISTANCE, TARGET_VELOCITY);
            turnForDegrees (TARGET_TURN);
            count++;
        }
    }

    void driveForMmAt (double distanceMm, double velocityMmPerSec)
    {

    }

    void turnForDegrees (double turnDegrees)
    {

    }
}

Full Code One Method