Bloomkd46/just-drive#27
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new teleop program called "Just Drive" that provides basic driving functionality for an FTC robot. The program allows a driver to control the robot's movement using gamepad inputs with speed modulation via triggers.
- New teleop operation mode focused solely on drive control
- Implements gamepad-based drive control with trigger-based speed adjustment
- Uses the existing Robot hardware abstraction for drive commands
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,69 @@ | |||
| package org.firstinspires.ftc.teamcode.programs.teleop; | |||
|
|
|||
| import com.qualcomm.robotcore.eventloop.opmode.Disabled; | |||
| import com.qualcomm.robotcore.hardware.DcMotor; | ||
| import com.qualcomm.robotcore.hardware.DcMotorEx; |
There was a problem hiding this comment.
The imports DcMotor and DcMotorEx are unused in this class and should be removed.
| import com.qualcomm.robotcore.hardware.DcMotor; | |
| import com.qualcomm.robotcore.hardware.DcMotorEx; |
| public class JustDrive extends OpMode { | ||
| public Robot robot; | ||
|
|
||
| // |
There was a problem hiding this comment.
Empty comment should be removed as it provides no value.
| // |
| double x = gamepad1.left_stick_x / 3; | ||
| x *= 2; | ||
| x += gamepad1.right_trigger * (gamepad1.left_stick_x / 3); | ||
| x -= gamepad1.left_trigger * (gamepad1.left_stick_x / 3); | ||
| double y = -gamepad1.left_stick_y / 3; | ||
| y *= 2; | ||
| y += gamepad1.right_trigger * (-gamepad1.left_stick_y / 3); | ||
| y -= gamepad1.left_trigger * (-gamepad1.left_stick_y / 3); | ||
| double z = gamepad1.right_stick_x / 3; | ||
| z *= 2; | ||
| z += gamepad1.right_trigger * (gamepad1.right_stick_x / 3); | ||
| z -= gamepad1.left_trigger * (gamepad1.right_stick_x / 3); |
There was a problem hiding this comment.
The stick input values (e.g., gamepad1.left_stick_x / 3) are recomputed multiple times. Store these values in local variables to improve readability and avoid redundant calculations. For example: double leftStickXScaled = gamepad1.left_stick_x / 3;
| double x = gamepad1.left_stick_x / 3; | |
| x *= 2; | |
| x += gamepad1.right_trigger * (gamepad1.left_stick_x / 3); | |
| x -= gamepad1.left_trigger * (gamepad1.left_stick_x / 3); | |
| double y = -gamepad1.left_stick_y / 3; | |
| y *= 2; | |
| y += gamepad1.right_trigger * (-gamepad1.left_stick_y / 3); | |
| y -= gamepad1.left_trigger * (-gamepad1.left_stick_y / 3); | |
| double z = gamepad1.right_stick_x / 3; | |
| z *= 2; | |
| z += gamepad1.right_trigger * (gamepad1.right_stick_x / 3); | |
| z -= gamepad1.left_trigger * (gamepad1.right_stick_x / 3); | |
| double leftStickXScaled = gamepad1.left_stick_x / 3; | |
| double leftStickYScaled = -gamepad1.left_stick_y / 3; | |
| double rightStickXScaled = gamepad1.right_stick_x / 3; | |
| double x = leftStickXScaled; | |
| x *= 2; | |
| x += gamepad1.right_trigger * leftStickXScaled; | |
| x -= gamepad1.left_trigger * leftStickXScaled; | |
| double y = leftStickYScaled; | |
| y *= 2; | |
| y += gamepad1.right_trigger * leftStickYScaled; | |
| y -= gamepad1.left_trigger * leftStickYScaled; | |
| double z = rightStickXScaled; | |
| z *= 2; | |
| z += gamepad1.right_trigger * rightStickXScaled; | |
| z -= gamepad1.left_trigger * rightStickXScaled; |
| double x = gamepad1.left_stick_x / 3; | ||
| x *= 2; |
There was a problem hiding this comment.
The magic numbers /3 and *2 appear throughout the code without explanation. These should be extracted as named constants (e.g., STICK_SCALE_FACTOR and BASE_SPEED_MULTIPLIER) to clarify their purpose and make them easier to tune.
| x += gamepad1.right_trigger * (gamepad1.left_stick_x / 3); | ||
| x -= gamepad1.left_trigger * (gamepad1.left_stick_x / 3); | ||
| double y = -gamepad1.left_stick_y / 3; | ||
| y *= 2; | ||
| y += gamepad1.right_trigger * (-gamepad1.left_stick_y / 3); | ||
| y -= gamepad1.left_trigger * (-gamepad1.left_stick_y / 3); | ||
| double z = gamepad1.right_stick_x / 3; | ||
| z *= 2; | ||
| z += gamepad1.right_trigger * (gamepad1.right_stick_x / 3); | ||
| z -= gamepad1.left_trigger * (gamepad1.right_stick_x / 3); | ||
|
|
There was a problem hiding this comment.
The logic appears incorrect. After multiplying by 2 on line 47, lines 48-49 add/subtract the original scaled value, which seems unintended. If the right trigger is meant to increase speed, it should multiply the current value of x, not add to it based on the original stick position. The intended behavior is unclear but the current implementation will produce unexpected results.
| x += gamepad1.right_trigger * (gamepad1.left_stick_x / 3); | |
| x -= gamepad1.left_trigger * (gamepad1.left_stick_x / 3); | |
| double y = -gamepad1.left_stick_y / 3; | |
| y *= 2; | |
| y += gamepad1.right_trigger * (-gamepad1.left_stick_y / 3); | |
| y -= gamepad1.left_trigger * (-gamepad1.left_stick_y / 3); | |
| double z = gamepad1.right_stick_x / 3; | |
| z *= 2; | |
| z += gamepad1.right_trigger * (gamepad1.right_stick_x / 3); | |
| z -= gamepad1.left_trigger * (gamepad1.right_stick_x / 3); | |
| x *= (1 + gamepad1.right_trigger - gamepad1.left_trigger); | |
| double y = -gamepad1.left_stick_y / 3; | |
| y *= 2; | |
| y *= (1 + gamepad1.right_trigger - gamepad1.left_trigger); | |
| double z = gamepad1.right_stick_x / 3; | |
| z *= 2; | |
| z *= (1 + gamepad1.right_trigger - gamepad1.left_trigger); |
It does just that. It drives