Difference between revisions of "FTC Using methods 20203018"
From wikidb
(→Code Outline) |
(→Full Code One Method) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Why Use Abstraction = | = Why Use Abstraction = | ||
− | * Makes it easier to reason about complex programs | + | * Makes it easier to reason about complex programs by reducing the detail you have to think about at one time |
− | * | + | * Makes is easier to test programs - we can test small part individually |
− | * | + | * Makes the code is reusable saving time. We can more easily takes code from one program and use it somewhere else. |
+ | * Makes code more reliable by allowing us to use the same code over and over. | ||
= Code Outline = | = Code Outline = | ||
Line 17: | Line 18: | ||
{ | { | ||
double TARGET_DISTANCE = 300; // mm (about 12 inches) | double TARGET_DISTANCE = 300; // mm (about 12 inches) | ||
− | double MAX_MOTOR_VELOCITY = 600; | + | double MAX_MOTOR_VELOCITY = 600; // mm / second |
double TARGET_VELOCITY = MAX_MOTOR_VELOCITY / 4; | double TARGET_VELOCITY = MAX_MOTOR_VELOCITY / 4; | ||
double TARGET_TURN = 90; // degrees | double TARGET_TURN = 90; // degrees | ||
Line 46: | Line 47: | ||
= Full Code One Method = | = Full Code One Method = | ||
− | * '''Exercise 1''': The turn method is not completed. Your job is to complete it | + | * '''Exercise 1''': The turn method is not completed. Your job is to complete it. The challenges are |
− | * [ | + | ** Computing the clicks for each wheel for a differential drive robot. |
+ | ** Compensating for wheel slippage. | ||
+ | ** The program probably is not optimum and may execute slowly. For example, it may re-execute motor commands that should be executed once. Explore techniques to make it computer more efficiently. | ||
+ | ** Currently the program is not driving straight. Why? | ||
+ | * [https://github.com/edcepp/FTCJavaLabs/blob/main/DriveInASquare.java Drive In a Square] to be finished |
Latest revision as of 13:31, 18 March 2022
Why Use Abstraction
- Makes it easier to reason about complex programs by reducing the detail you have to think about at one time
- Makes is easier to test programs - we can test small part individually
- Makes the code is reusable saving time. We can more easily takes code from one program and use it somewhere else.
- Makes code more reliable by allowing us to use the same code over and over.
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
- Exercise 1: The turn method is not completed. Your job is to complete it. The challenges are
- Computing the clicks for each wheel for a differential drive robot.
- Compensating for wheel slippage.
- The program probably is not optimum and may execute slowly. For example, it may re-execute motor commands that should be executed once. Explore techniques to make it computer more efficiently.
- Currently the program is not driving straight. Why?
- Drive In a Square to be finished