Skip to content

Commit

Permalink
Switched some commands to the new version so the students have examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Frei committed Sep 16, 2024
1 parent 92cf769 commit 128db2f
Show file tree
Hide file tree
Showing 29 changed files with 211 additions and 331 deletions.
Binary file modified Field.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
@SuppressWarnings("WeakerAccess")
public class FtcRobotControllerActivity extends Activity
{
public static double endAutoHeading = 0.0;
public static double headingUpdateTime = 0.0;
public static Object SaveBetweenRuns = null;

public static final String TAG = "RCActivity";
public String getTag() { return TAG; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static void main(String[] args) {
);
AutoConstants.func = (Pose2d pose) -> new TrajectoryBuilder(pose, min_vel, prof_accel);
RoadRunnerBotEntity myBot = new DefaultBotBuilder(meepMeep)
.setDimensions(17.5, 18)
.followTrajectorySequence(drive -> getRedTrajectory(drive));
.setDimensions(15, 17.5)
.followTrajectorySequence(Sixteen750Testing::getRedTrajectory);
try {
// Try to load the field image from the repo:
meepMeep.setBackground(ImageIO.read(new File("Field.jpg")));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.firstinspires.ftc.sixteen750.commands.driving;

import com.technototes.library.command.Command;
import org.firstinspires.ftc.sixteen750.subsystems.DrivebaseSubsystem;

public class DrivingCommands {

public static Command NormalDriving(DrivebaseSubsystem ds) {
return Command.create(ds::setNormalMode);
}

public static Command SnailDriving(DrivebaseSubsystem ds) {
return Command.create(ds::setSnailMode);
}

public static Command TurboDriving(DrivebaseSubsystem ds) {
return Command.create(ds::setTurboMode);
}

public static Command NormalSpeed(DrivebaseSubsystem ds) {
return Command.create(ds::auto);
}

public static Command SlowSpeed(DrivebaseSubsystem ds) {
return Command.create(ds::slow);
}

public static Command FastSpeed(DrivebaseSubsystem ds) {
return Command.create(ds::fast);
}

public static Command ResetGyro(DrivebaseSubsystem ds) {
return Command.create(ds::setExternalHeading, 0.0);
}

public static Command RecordHeading(DrivebaseSubsystem drive) {
return Command.create(drive::saveHeading);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import com.technototes.library.control.Stick;
import org.firstinspires.ftc.sixteen750.Robot;
import org.firstinspires.ftc.sixteen750.Setup;
import org.firstinspires.ftc.sixteen750.commands.driving.DrivingCommands;
import org.firstinspires.ftc.sixteen750.commands.driving.JoystickDriveCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.NormalModeCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.ResetGyroCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.SnailModeCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.TurboModeCommand;

public class DriverController {

Expand Down Expand Up @@ -53,11 +50,11 @@ public void bindDriveControls() {
)
);

turboButton.whenPressed(new TurboModeCommand(robot.drivebase));
turboButton.whenReleased(new NormalModeCommand(robot.drivebase));
snailButton.whenPressed(new SnailModeCommand(robot.drivebase));
snailButton.whenReleased(new NormalModeCommand(robot.drivebase));
turboButton.whenPressed(DrivingCommands.TurboDriving(robot.drivebase));
turboButton.whenReleased(DrivingCommands.NormalDriving(robot.drivebase));
snailButton.whenPressed(DrivingCommands.SnailDriving(robot.drivebase));
snailButton.whenReleased(DrivingCommands.NormalDriving(robot.drivebase));

resetGyroButton.whenPressed(new ResetGyroCommand(robot.drivebase));
resetGyroButton.whenPressed(DrivingCommands.ResetGyro(robot.drivebase));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import com.technototes.library.control.Stick;
import org.firstinspires.ftc.sixteen750.Robot;
import org.firstinspires.ftc.sixteen750.Setup;
import org.firstinspires.ftc.sixteen750.commands.driving.DrivingCommands;
import org.firstinspires.ftc.sixteen750.commands.driving.JoystickDriveCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.NormalModeCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.ResetGyroCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.SnailModeCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.TurboModeCommand;

public class SingleController {

Expand Down Expand Up @@ -41,19 +38,17 @@ private void AssignNamedControllerButton() {

turboButton = gamepad.rightBumper;
snailButton = gamepad.leftBumper;

}

public void bindDriveControls() {
CommandScheduler.scheduleJoystick(
new JoystickDriveCommand(robot.drivebase, driveLeftStick, driveRightStick)
);
turboButton.whenPressed(new TurboModeCommand(robot.drivebase));
turboButton.whenReleased(new NormalModeCommand(robot.drivebase));
snailButton.whenPressed(new SnailModeCommand(robot.drivebase));
snailButton.whenReleased(new NormalModeCommand(robot.drivebase));
turboButton.whenPressed(DrivingCommands.TurboDriving(robot.drivebase));
turboButton.whenReleased(DrivingCommands.NormalDriving(robot.drivebase));
snailButton.whenPressed(DrivingCommands.SnailDriving(robot.drivebase));
snailButton.whenReleased(DrivingCommands.NormalDriving(robot.drivebase));

resetGyroButton.whenPressed(new ResetGyroCommand(robot.drivebase));
resetGyroButton.whenPressed(DrivingCommands.ResetGyro(robot.drivebase));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.firstinspires.ftc.sixteen750.helpers;

import org.firstinspires.ftc.robotcontroller.internal.FtcRobotControllerActivity;

public class HeadingHelper {

public double headingUpdateTime;
public double lastHeading;
public double lastXPosition;
public double lastYPosition;

public HeadingHelper(double lastX, double lastY, double heading) {
headingUpdateTime = System.currentTimeMillis() / 1000.0;
lastXPosition = lastX;
lastYPosition = lastY;
lastHeading = heading;
}

public static void saveHeading(double x, double y, double h) {
FtcRobotControllerActivity.SaveBetweenRuns = new HeadingHelper(x, y, h);
}

public static void clearSavedInfo() {
FtcRobotControllerActivity.SaveBetweenRuns = null;
}

public static boolean validHeading() {
HeadingHelper hh = (HeadingHelper) FtcRobotControllerActivity.SaveBetweenRuns;
if (hh == null) {
return false;
}
double now = System.currentTimeMillis() / 1000.0;
return now < hh.headingUpdateTime + 45;
}

public static double getSavedHeading() {
HeadingHelper hh = (HeadingHelper) FtcRobotControllerActivity.SaveBetweenRuns;
if (hh != null) {
return hh.lastHeading;
}
return 0.0;
}

public static double getSavedX() {
HeadingHelper hh = (HeadingHelper) FtcRobotControllerActivity.SaveBetweenRuns;
if (hh != null) {
return hh.lastXPosition;
}
return 0.0;
}

public static double getSavedY() {
HeadingHelper hh = (HeadingHelper) FtcRobotControllerActivity.SaveBetweenRuns;
if (hh != null) {
return hh.lastYPosition;
}
return 0.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.technototes.library.command.CommandScheduler;
import com.technototes.library.command.SequentialCommandGroup;
import com.technototes.library.structure.CommandOpMode;
import com.technototes.library.util.Alliance;
import java.util.Set;
import org.firstinspires.ftc.sixteen750.AutoConstants;
import org.firstinspires.ftc.sixteen750.Hardware;
import org.firstinspires.ftc.sixteen750.Robot;
import org.firstinspires.ftc.sixteen750.Setup;
import org.firstinspires.ftc.sixteen750.commands.driving.ResetGyroCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.DrivingCommands;
import org.firstinspires.ftc.sixteen750.controls.DriverController;
import org.firstinspires.ftc.sixteen750.controls.OperatorController;
import org.firstinspires.ftc.sixteen750.helpers.StartingPosition;
Expand All @@ -37,7 +35,7 @@ public void uponInit() {
// Just pick a starting point
robot.drivebase.setPoseEstimate(AutoConstants.START.toPose());
CommandScheduler.scheduleForState(
new ResetGyroCommand(robot.drivebase),
DrivingCommands.ResetGyro(robot.drivebase),
OpModeState.INIT
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.firstinspires.ftc.sixteen750.Hardware;
import org.firstinspires.ftc.sixteen750.Robot;
import org.firstinspires.ftc.sixteen750.Setup;
import org.firstinspires.ftc.sixteen750.commands.driving.ResetGyroCommand;
import org.firstinspires.ftc.sixteen750.controls.OperatorController;
import org.firstinspires.ftc.sixteen750.controls.SingleController;
import org.firstinspires.ftc.sixteen750.controls.TestingController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.firstinspires.ftc.sixteen750.Hardware;
import org.firstinspires.ftc.sixteen750.Robot;
import org.firstinspires.ftc.sixteen750.Setup;
import org.firstinspires.ftc.sixteen750.commands.driving.ResetGyroCommand;
import org.firstinspires.ftc.sixteen750.commands.driving.DrivingCommands;
import org.firstinspires.ftc.sixteen750.controls.SingleController;
import org.firstinspires.ftc.sixteen750.helpers.StartingPosition;

Expand All @@ -29,6 +29,9 @@ public void uponInit() {
robot = new Robot(hardware, Alliance.NONE, StartingPosition.Unspecified);
controls = new SingleController(driverGamepad, robot, setup);
robot.drivebase.setPoseEstimate(AutoConstants.TELESTART.toPose());
CommandScheduler.scheduleForState(new ResetGyroCommand(robot.drivebase), OpModeState.INIT);
CommandScheduler.scheduleForState(
DrivingCommands.ResetGyro(robot.drivebase),
OpModeState.INIT
);
}
}
Loading

0 comments on commit 128db2f

Please sign in to comment.