Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Servo Testing in LearnBot #56

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public Hardware(HardwareMap hwmap) {
if (Setup.Connected.SERVO) {
this.servo = new Servo(Setup.HardwareNames.SERVO);
}
if (Setup.Connected.COLOR_SENSOR) {
this.colorSensor = new ColorDistanceSensor(Setup.HardwareNames.COLOR);
}
// if (Setup.Connected.COLOR_SENSOR) {
// this.colorSensor = new ColorDistanceSensor(Setup.HardwareNames.COLOR);
// }
}
this.imu = new IMU(
Setup.HardwareNames.IMU,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ public class Robot implements Loggable {
public StartingPosition position;
public Alliance alliance;
public double initialVoltage;
public TestSubsystem test;
public DrivebaseSubsystem drivebaseSubsystem;

public PlacementSubsystem placementSubsystem;
public TestSubsystem testsubsystem;

public Robot(Hardware hw) {
this.initialVoltage = hw.voltage();
this.test = new TestSubsystem(hw);
this.testsubsystem = new TestSubsystem(hw);
if (Setup.Connected.DRIVEBASE) {
this.drivebaseSubsystem = new DrivebaseSubsystem(
hw.flMotor,
Expand All @@ -30,7 +29,7 @@ public Robot(Hardware hw) {
);
}
if (Setup.Connected.TESTSUBSYSTEM) {
this.test = new TestSubsystem(hw);
this.testsubsystem = new TestSubsystem(hw);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public class Setup {
@Config
public static class Connected {

public static boolean DRIVEBASE = true;
public static boolean TESTSUBSYSTEM = false;
public static boolean DRIVEBASE = false;
public static boolean TESTSUBSYSTEM = true;
public static boolean MOTOR = false;
public static boolean SERVO = false;
public static boolean SERVO = true;
public static boolean DISTANCE_SENSOR = false;
public static boolean COLOR_SENSOR = false;
public static boolean FLYWHEEL = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,39 @@

import com.technototes.library.command.Command;
import com.technototes.library.command.MethodCommand;
import org.firstinspires.ftc.learnbot.Robot;
import org.firstinspires.ftc.learnbot.subsystems.TestSubsystem;

public class Test {

public static Command ServoMax(Robot r) {
if (r.testsubsystem == null) {
throw new RuntimeException("null testsubsystem in robot");
}
return Command.create(r.testsubsystem::servoMaxPos, r.testsubsystem);
}

public static Command ServoMin(Robot r) {
if (r.testsubsystem == null) {
throw new RuntimeException("null testsubsystem in robot");
}
return Command.create(r.testsubsystem::servoMinPos, r.testsubsystem);
}

public static Command ServoInc(Robot r) {
if (r.testsubsystem == null) {
throw new RuntimeException("null testsubsystem in robot");
}
return Command.create(r.testsubsystem::servoIncrement, r.testsubsystem);
}

public static Command ServoDec(Robot r) {
if (r.testsubsystem == null) {
throw new RuntimeException("null testsubsystem in robot");
}
return Command.create(r.testsubsystem::servoDecrement, r.testsubsystem);
}

public static Command ServoLeft(TestSubsystem ts) {
return new MethodCommand(TestSubsystem::servoLeft, ts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.firstinspires.ftc.learnbot.Robot;
import org.firstinspires.ftc.learnbot.commands.AnalogMotorControlCmd;
import org.firstinspires.ftc.learnbot.commands.EZCmd;
import org.firstinspires.ftc.learnbot.commands.Test;
import org.firstinspires.ftc.learnbot.subsystems.TestSubsystem;

public class TestController implements Loggable {

Expand All @@ -17,6 +19,10 @@ public class TestController implements Loggable {
public CommandButton servoright;
public CommandAxis motorAxis;
public CommandButton modeToggle;
public CommandButton servoMax;
public CommandButton servoMin;
public CommandButton servoInc;
public CommandButton servoDec;

public CommandButton liftLow, liftMid, liftHigh;

Expand All @@ -26,25 +32,40 @@ public class TestController implements Loggable {
public AnalogMotorControlCmd motorMovement;

public TestController(CommandGamepad g, Robot r) {
if (g == null) {
throw new RuntimeException("Null CommandGamepad in TestController");
}
if (r == null) {
throw new RuntimeException("Null robot in TestController");
}
this.gamepad = g;
this.robot = r;
this.liftLow = gamepad.ps_triangle;
this.liftMid = gamepad.ps_cross;
this.liftHigh = gamepad.ps_circle;
// this.liftLow = gamepad.ps_triangle;
// this.liftMid = gamepad.ps_cross;
// this.liftHigh = gamepad.ps_circle;
this.servoMax = gamepad.ps_triangle;
this.servoMin = gamepad.ps_cross;
this.servoInc = gamepad.dpadUp;
this.servoDec = gamepad.dpadDown;
// this.servoleft.whenPressed(new ServoLeft(r.test));
// this.servoright.whenPressed((new ServoRight(r.test)));
this.motorAxis = gamepad.rightStickY;
//this.motorAxis = gamepad.rightStickY;
this.modeToggle = gamepad.rightStickButton;
// this.motorMovement = new MotorMovementCommand(r.test, this.motorAxis);
// this.modeToggle.whenPressed(new ToggleMotorStopModeCommand(r.test));
// CommandScheduler.scheduleJoystick(motorMovement);
this.trigger = gamepad.leftTrigger;
//this.trigger = gamepad.leftTrigger;
this.threshold = gamepad.rightTrigger.getAsButton(0.5);
bindControls();
}

public void bindControls() {
liftLow.whenPressed(EZCmd.Placement.LiftLow(robot.placementSubsystem));
liftMid.whenPressed(EZCmd.Placement.LiftMedium(robot.placementSubsystem));
liftHigh.whenPressed(EZCmd.Placement.LiftHigh(robot.placementSubsystem));
// liftLow.whenPressed(EZCmd.Placement.LiftLow(robot.placementSubsystem));
// liftMid.whenPressed(EZCmd.Placement.LiftMedium(robot.placementSubsystem));
// liftHigh.whenPressed(EZCmd.Placement.LiftHigh(robot.placementSubsystem));
servoMax.whenPressed(Test.ServoMax(robot));
servoMin.whenPressed(Test.ServoMin(robot));
servoInc.whenPressed(Test.ServoInc(robot));
servoDec.whenPressed(Test.ServoDec(robot));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.technototes.library.command.Command;
import com.technototes.library.command.CommandScheduler;
import com.technototes.library.logger.Loggable;
import com.technototes.library.structure.CommandOpMode;
import org.firstinspires.ftc.learnbot.Hardware;
import org.firstinspires.ftc.learnbot.Robot;
import org.firstinspires.ftc.learnbot.commands.TriggerTestCommand;
import org.firstinspires.ftc.learnbot.controllers.TestController;

@TeleOp(name = "Test")
@SuppressWarnings("unused")
public class Test extends CommandOpMode implements Loggable {
public class TestOpmode extends CommandOpMode implements Loggable {

public Robot robot;
public TestController testCtrl;
Expand All @@ -28,10 +26,10 @@ public void uponInit() {
hardware = new Hardware(hardwareMap);
robot = new Robot(hardware);
testCtrl = new TestController(driverGamepad, robot);
trigTest = new TriggerTestCommand(
driverGamepad.leftTrigger,
driverGamepad.leftTrigger.getAsButton(.5)
);
CommandScheduler.scheduleJoystick(trigTest);
// trigTest = new TriggerTestCommand(
// driverGamepad.leftTrigger,
// driverGamepad.leftTrigger.getAsButton(.5)
// );
// CommandScheduler.scheduleJoystick(trigTest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ public TestSubsystem(Hardware hw) {
resetTicks();
}

public void servoIncrement() {
running = true;
servo.setPosition(servo.getPosition() + 0.1);
}

public void servoDecrement() {
running = true;
servo.setPosition(servo.getPosition() - 0.1);
}

public void servoMaxPos() {
if (servo == null) {
throw new RuntimeException("Null servo in TestSubsystem");
}
running = true;
servo.setPosition(1);
}

public void servoMinPos() {
running = true;
servo.setPosition(0);
}

public void servoLeft() {
running = true;
setPosition(0.5);
Expand Down
Loading