FTC Drive In a Square Outline 20230112

From wikidb
Jump to: navigation, search
package org.firstinspires.ftc.teamcode;

import ...

@Autonomous(name="Drive in a square 1/11/23", group="Concept")
public  class DriveInASquareEpp extends LinearOpMode
{
    double TARGET_DISTANCE    = 450;         // mm (about 18 inches)
    double DEGREES_90         = 125;         // mm wheel distance guess
    double MAX_MOTOR_VELOCITY = 600;         // mm / second
    double TARGET_VELOCITY    = MAX_MOTOR_VELOCITY / 4;
    int    SQUARE_SIDES       =   2;

    DcMotorEx leftMotor;
    ...

    public void runOpMode() throws InterruptedException
    {
        leftMotor = hardwareMap.get(DcMotorEx.class,"myLeftMotor");
        leftMotor.setDirection(DcMotor.Direction.REVERSE);
        leftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
        ...
 
        int count = 0;
        while (opModeIsActive() && count < SQUARE_SIDES)
        {
            powerUpMotors(TARGET_DISTANCE, TARGET_VELOCITY,
                          TARGET_DISTANCE, TARGET_VELOCITY);
            powerUpMotors(DEGREES_90, TARGET_VELOCITY,
                          -DEGREES_90, -TARGET_VELOCITY);
            count++;
        }
    }

    void powerUpMotors (double leftMotorDistance, double leftMotorVelocity,
                        double rightMotorDistance, double rightMotorVelocity)
   {
        double mMPerTick = 283.0 / 288.0;
        double leftTicksToMove = leftMotorDistance / mMPerTick;
        double leftTicksPerSecond = leftMotorVelocity / mMPerTick;
        ...
        leftMotor.setVelocity(leftTicksPerSecond);
        ...
   }
}