5 Commits

Author SHA1 Message Date
9d71ef670c Merge remote-tracking branch 'origin/Branch-Yixuan' into Branch-Yixuan 2024-04-19 21:40:35 -07:00
a9ebe79e01 Added motors array 2024-04-19 21:40:22 -07:00
5d99d94430 I type 2024-03-26 16:16:22 -07:00
d77067538a I type 2024-03-26 15:50:01 -07:00
bf1b45618e I type 2024-03-19 16:31:35 -07:00
2 changed files with 45 additions and 37 deletions

View File

@ -4,14 +4,11 @@ import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple; import com.qualcomm.robotcore.hardware.DcMotorSimple;
public class MovementLibrary { public class MovementLibrary {
public static void setDirectionForward(DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw){ public static void setDirectionForward(DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw){
rhw.setDirection(DcMotor.Direction.REVERSE); rhw.setDirection(DcMotor.Direction.REVERSE);
rlw.setDirection(DcMotor.Direction.FORWARD); rlw.setDirection(DcMotor.Direction.FORWARD);
lhw.setDirection(DcMotorSimple.Direction.FORWARD); lhw.setDirection(DcMotorSimple.Direction.FORWARD);
llw.setDirection(DcMotorSimple.Direction.REVERSE); llw.setDirection(DcMotorSimple.Direction.REVERSE);}
}
public static void setDirectionBackward(DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw){ public static void setDirectionBackward(DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw){
rhw.setDirection(DcMotor.Direction.FORWARD); rhw.setDirection(DcMotor.Direction.FORWARD);
@ -20,26 +17,25 @@ public class MovementLibrary {
llw.setDirection(DcMotorSimple.Direction.FORWARD); llw.setDirection(DcMotorSimple.Direction.FORWARD);
} }
public static void setDirectionLeft (DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw) { public static void setSpeed (double speedValue,DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw){
rhw.setPower(speedValue);
rlw.setPower(speedValue);
llw.setPower(speedValue);
lhw.setPower(speedValue);
}
public static void setDirectionRight(DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw){
rhw.setDirection(DcMotor.Direction.REVERSE); rhw.setDirection(DcMotor.Direction.REVERSE);
rlw.setDirection(DcMotor.Direction.REVERSE); rlw.setDirection(DcMotor.Direction.REVERSE);
lhw.setDirection(DcMotorSimple.Direction.FORWARD); lhw.setDirection(DcMotorSimple.Direction.FORWARD);
llw.setDirection(DcMotorSimple.Direction.FORWARD); llw.setDirection(DcMotorSimple.Direction.FORWARD);
}
public static void setDirectionRight (DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw) { }
public static void setDirectionLeft(DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw){
rhw.setDirection(DcMotor.Direction.FORWARD); rhw.setDirection(DcMotor.Direction.FORWARD);
rlw.setDirection(DcMotor.Direction.FORWARD); rlw.setDirection(DcMotor.Direction.FORWARD);
lhw.setDirection(DcMotorSimple.Direction.REVERSE); lhw.setDirection(DcMotorSimple.Direction.REVERSE);
llw.setDirection(DcMotorSimple.Direction.REVERSE); llw.setDirection(DcMotorSimple.Direction.REVERSE);
} }
public static void setSpeed (double speedValue, DcMotor rhw, DcMotor rlw, DcMotor lhw, DcMotor llw) {
rhw.setPower(speedValue);
rlw.setPower(speedValue);
lhw.setPower(speedValue);
llw.setPower(speedValue);
}
} }

View File

@ -12,8 +12,12 @@ import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.DistanceSensor; import com.qualcomm.robotcore.hardware.DistanceSensor;
import com.qualcomm.robotcore.hardware.TouchSensor; import com.qualcomm.robotcore.hardware.TouchSensor;
import org.firstinspires.ftc.teamcode.MovementLibrary; import org.firstinspires.ftc.teamcode.MovementLibrary;
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit; import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
import java.util.ArrayList;
import java.util.List;
@Autonomous(name="Name") @Autonomous(name="Name")
public class Name extends LinearOpMode { public class Name extends LinearOpMode {
private DcMotor rightHandWheel; private DcMotor rightHandWheel;
@ -35,8 +39,19 @@ public class Name extends LinearOpMode {
distanceSensor = hardwareMap.get(DistanceSensor.class , "distancesensor"); distanceSensor = hardwareMap.get(DistanceSensor.class , "distancesensor");
colorSensor= hardwareMap.get(ColorSensor.class , "colorsensor"); colorSensor= hardwareMap.get(ColorSensor.class , "colorsensor");
DcMotor[] motors = {rightHandWheel, leftHandWheel, rightLegWheel, leftLegWheel};
MovementLibrary.setDirectionForward(rightHandWheel, rightLegWheel, leftHandWheel,leftLegWheel); MovementLibrary.setDirectionForward(rightHandWheel, rightLegWheel, leftHandWheel,leftLegWheel);
MovementLibrary.setSpeed(0.2,rightHandWheel,rightLegWheel,leftHandWheel,leftLegWheel);
//from this
DcMotor[] motors = {rightHandWheel, leftHandWheel, rightLegWheel, leftLegWheel};
//thismotors
MovementLibrary.setDirectionForward(motors);
// Wait for the game to start (driver presses {Play
waitForStart();
// Wait for the game to start (driver presses PLAY) // Wait for the game to start (driver presses PLAY)
waitForStart(); waitForStart();
@ -68,18 +83,15 @@ public class Name extends LinearOpMode {
double nicerValue = distanceSensor.getDistance(DistanceUnit.INCH); double nicerValue = distanceSensor.getDistance(DistanceUnit.INCH);
telemetry.addData("you are this far (in inches) --> ", "%.2f", nicerValue); telemetry.addData("you are this far (in inches) --> ", "%.2f", nicerValue);
telemetry.addData("Red: ", colorSensor.red()); telemetry.addData("green color value",colorSensor.green());
telemetry.addData("Green: ", colorSensor.green()); telemetry.addData("blue color value" ,colorSensor.blue());
telemetry.addData("Blue: ", colorSensor.blue()); telemetry.update();
if(colorSensor.green() > 1100 && colorSensor.blue() > 1000) { if (colorSensor.blue() > 800 && colorSensor.green() > 1100) {
MovementLibrary.setSpeed(0.4, rightHandWheel, rightLegWheel,leftHandWheel,leftLegWheel); MovementLibrary.setSpeed(0.4, rightHandWheel, rightLegWheel,leftHandWheel,leftLegWheel);
}else { }else {
MovementLibrary.setSpeed(0.2, rightHandWheel, rightLegWheel,leftHandWheel,leftLegWheel); MovementLibrary.setSpeed(0.2, rightHandWheel, rightLegWheel,leftHandWheel,leftLegWheel);
}; }
telemetry.update();
} }
} }