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

Safe mode #32

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
efc4728
safe mode (child mode)
BrownBear85 Apr 22, 2023
1eba207
child mode refuses arm control
FriedLongJohns Apr 25, 2023
a92d442
Slowmode (dt, arm+wrist, disable X and joysticks)
DriverStationComputer Apr 26, 2023
917c156
fix
FriedLongJohns Apr 29, 2023
6fa4ab0
Use limits instead of multipliers
FriedLongJohns Apr 29, 2023
ddf341b
Add Arm kD value
DriverStationComputer May 17, 2023
20da511
addding encoder connected code and recalibrated
DriverStationComputer Sep 28, 2023
c3afc26
Remove unused forbFlag
FriedLongJohns Sep 29, 2023
4039891
fix baby vel & accel limits
FriedLongJohns Sep 30, 2023
cf37551
merged baby and slow booloean suppliers into slow
TuskAct2 Sep 30, 2023
f510639
Revert "merged baby and slow booloean suppliers into slow"
FriedLongJohns Oct 1, 2023
eec4b4a
Shift RollerMode to Roller
FriedLongJohns Oct 1, 2023
d6b8515
Merge branch 'master' into safe-mode
FriedLongJohns Oct 1, 2023
88cace6
Reorganize lambdas
FriedLongJohns Oct 1, 2023
87c5866
Merge branch 'safe-mode' of https://github.com/DeepBlueRobotics/Robot…
FriedLongJohns Oct 1, 2023
46866e3
copied arm encoder dc logic into wrist
TuskAct2 Oct 1, 2023
6a5b4a7
if encoders are dc then motors will stop
TuskAct2 Oct 1, 2023
6d929d1
shorten functions
FriedLongJohns Oct 1, 2023
e5907cd
fix stupid ifs
FriedLongJohns Oct 1, 2023
9c4f55b
merge driver modes
FriedLongJohns Oct 1, 2023
fe366fe
alt + shift + f, autoformatting everything
ProfessorAtomicManiac Oct 1, 2023
15f0207
added constants together
ProfessorAtomicManiac Oct 1, 2023
1812ca5
documentation of DISCONNECTED_ENCODER_TIMEOUT_SEC
ProfessorAtomicManiac Oct 1, 2023
531783d
format RunRoller and TeleopDrive
ProfessorAtomicManiac Oct 1, 2023
becd19a
remove useless line
ProfessorAtomicManiac Oct 1, 2023
7ff0122
made wrist encoder disconnection detection work
ProfessorAtomicManiac Oct 1, 2023
8955c82
documentation of disconnected encoder code
ProfessorAtomicManiac Oct 1, 2023
feea3e3
Fix logic
FriedLongJohns Oct 1, 2023
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
15 changes: 14 additions & 1 deletion src/main/java/org/carlmontrobotics/robotcode2023/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public static final class Drivetrain {
public static final double kNormalDriveRotation = 0.5; // Percent Multiplier
public static final double kSlowDriveSpeed = 0.4; // Percent Multiplier
public static final double kSlowDriveRotation = 0.250; // Percent Multiplier
public static final double kBabyDriveSpeed = 0.1; // Percent Multiplier
public static final double kBabyTurnSpeed = 0.2; // Percent Multiplier
public static final double kAlignMultiplier = 1D/3D;
public static final double kAlignForward = 0.6;

Expand Down Expand Up @@ -222,6 +224,8 @@ public static final class Arm {

// TODO: Determine actual max vel/accel
// public static double[] MAX_FF_VEL = {.25, .25}; // rad / s
//Arm, Wrist
public static double[] ARM_SLOWMODE_MULT = {.1, .5};
public static double[] MAX_FF_VEL_MANUAL = {1, 3}; // rad / s
public static double[] MAX_FF_VEL_AUTO = {1.25, 5}; // rad / s
public static double[] MAX_FF_ACCEL = {5, 5}; // rad / s^2
ProfessorAtomicManiac marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -383,7 +387,8 @@ public static class RollerMode {
public static RollerMode OUTTAKE_CONE = new RollerMode(0.5, .5, GameObject.NONE, defaultColor);
public static RollerMode OUTTAKE_CUBE = new RollerMode(-0.5, .5, GameObject.NONE, defaultColor);
public static RollerMode STOP = new RollerMode(0, .1, GameObject.NONE, defaultColor);
public double speed, time;
private double speed;
public double time;
public GameObject obj;
public Color ledColor;

Expand All @@ -399,6 +404,14 @@ public RollerMode(double speed, double time, GameObject obj, Color ledColor) {
this.obj = obj;
ProfessorAtomicManiac marked this conversation as resolved.
Show resolved Hide resolved
this.ledColor = ledColor;
}

public double getSpeed() {
return speed;
}

public void setSpeed(double speed) {
this.speed = speed;
}
ProfessorAtomicManiac marked this conversation as resolved.
Show resolved Hide resolved
}

//#endregion
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/carlmontrobotics/robotcode2023/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandScheduler;

public class Robot extends TimedRobot {
Expand All @@ -26,6 +27,8 @@ public void robotInit() {
DriverStation.startDataLog(DataLogManager.getLog());
if(!DriverStation.isFMSAttached()) PathPlannerServer.startServer(5811);
robotContainer = new RobotContainer();

SmartDashboard.putBoolean("safeMode", false);
ProfessorAtomicManiac marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand All @@ -40,6 +43,8 @@ public void simulationInit() {
public void robotPeriodic() {
CommandScheduler.getInstance().run();
MotorErrors.printSparkMaxErrorMessages();

RobotContainer.isdriverchild = SmartDashboard.getBoolean("safeMode", false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

public class RobotContainer {

public static boolean isdriverchild = false;

public final GenericHID driverController = new GenericHID(Driver.port);
public final GenericHID manipulatorController = new GenericHID(Manipulator.port);

Expand Down Expand Up @@ -132,15 +134,16 @@ public RobotContainer() {
() -> inputProcessing(getStickValue(driverController, Axis.kLeftY)),
() -> inputProcessing(getStickValue(driverController, Axis.kLeftX)),
() -> inputProcessing(getStickValue(driverController, Axis.kRightX)),
() -> driverController.getRawButton(Driver.slowDriveButton)
() -> driverController.getRawButton(Driver.slowDriveButton),
() -> {return isdriverchild;}
));

configureButtonBindingsDriver();
configureButtonBindingsManipulator();
arm.setDefaultCommand(new ArmTeleop(
arm,
() -> inputProcessing(getStickValue(manipulatorController, Axis.kLeftY)),
() -> inputProcessing(getStickValue(manipulatorController, Axis.kRightY))
() -> {return (isdriverchild ? 0 : inputProcessing(getStickValue(manipulatorController, Axis.kLeftY)));},
() -> {return (isdriverchild ? 0 : inputProcessing(getStickValue(manipulatorController, Axis.kRightY)));}
));
}
private void configureButtonBindingsDriver() {
Expand All @@ -159,7 +162,7 @@ private void configureButtonBindingsManipulator() {
BooleanSupplier isIntake = () -> !isCube.getAsBoolean();

new JoystickButton(manipulatorController, Manipulator.storePosButton).onTrue(new SetArmWristGoalPreset(GoalPos.STORED, isCube, isFront, arm));
new JoystickButton(manipulatorController, Manipulator.lowPosButton).onTrue(new SetArmWristGoalPreset(GoalPos.LOW, isCube, isFront, arm));
//new JoystickButton(manipulatorController, Manipulator.lowPosButton).onTrue(new SetArmWristGoalPreset(GoalPos.LOW, isCube, isFront, arm));
new JoystickButton(manipulatorController, Manipulator.midPosButton).onTrue(new SetArmWristGoalPreset(GoalPos.MID, isCube, isFront, arm));
new JoystickButton(manipulatorController, Manipulator.highPosButton).onTrue(new SetArmWristGoalPreset(GoalPos.HIGH, isCube, isFront, arm));
new POVButton(manipulatorController, Manipulator.shelfPickupPOV).onTrue(new SetArmWristGoalPreset(GoalPos.SHELF, isCube, isFront, arm));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RunRoller(Roller roller, RollerMode mode) {
public void initialize() {
System.err.println("=============================RunRoller is Started=============================");

if (mode.speed > 0) { // should not interrupt command to stop rollers
if (mode.getSpeed() > 0) { // should not interrupt command to stop rollers
if(roller.hasGamePiece() && isIntake()) cancel();
if(!roller.hasGamePiece() && !isIntake()) cancel();
}
Expand All @@ -48,7 +48,7 @@ public void end(boolean interrupted) {
@Override
public boolean isFinished() {

if(mode.speed == 0) return true;
if(mode.getSpeed() == 0) return true;

double time = timer.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ public class TeleopDrive extends CommandBase {
private DoubleSupplier str;
private DoubleSupplier rcw;
private BooleanSupplier slow;
private BooleanSupplier baby;
private double currentForwardVel = 0;
private double currentStrafeVel = 0;

/**
* Creates a new TeleopDrive.
*/
public TeleopDrive(Drivetrain drivetrain, DoubleSupplier fwd, DoubleSupplier str, DoubleSupplier rcw, BooleanSupplier slow) {
public TeleopDrive(Drivetrain drivetrain, DoubleSupplier fwd, DoubleSupplier str, DoubleSupplier rcw, BooleanSupplier slow, BooleanSupplier baby) {
TuskAct2 marked this conversation as resolved.
Show resolved Hide resolved
addRequirements(this.drivetrain = drivetrain);
this.fwd = fwd;
this.str = str;
this.rcw = rcw;
this.slow = slow;
this.baby = baby;
}

// Called when the command is initially scheduled.
Expand Down Expand Up @@ -67,8 +69,8 @@ public double[] getRequestedSpeeds() {
if (Math.abs(rotateClockwise) <= Constants.OI.JOY_THRESH) rotateClockwise = 0.0;
else rotateClockwise *= maxRCW;

double driveMultiplier = slow.getAsBoolean() ? kSlowDriveSpeed : kNormalDriveSpeed;
double rotationMultiplier = slow.getAsBoolean() ? kSlowDriveRotation : kNormalDriveRotation;
double driveMultiplier = baby.getAsBoolean() ? kBabyDriveSpeed : (slow.getAsBoolean() ? kSlowDriveSpeed : kNormalDriveSpeed);
double rotationMultiplier = baby.getAsBoolean() ? kBabyTurnSpeed : (slow.getAsBoolean() ? kSlowDriveRotation : kNormalDriveRotation);
TuskAct2 marked this conversation as resolved.
Show resolved Hide resolved

forward *= driveMultiplier;
strafe *= driveMultiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.carlmontrobotics.MotorConfig;
import org.carlmontrobotics.lib199.MotorControllerFactory;
import org.carlmontrobotics.robotcode2023.RobotContainer;
import org.carlmontrobotics.robotcode2023.Constants.GoalPos;
import org.carlmontrobotics.robotcode2023.commands.ArmTeleop;

Expand Down Expand Up @@ -149,9 +150,10 @@ public void autoCancelArmCommand() {
//#region Drive Methods

private void driveArm(TrapezoidProfile.State state) {
double speedMult = RobotContainer.isdriverchild ? ARM_SLOWMODE_MULT[0] : 1;
double kgv = getKg();
double armFeedVolts = kgv * getCoM().getAngle().getCos() + armFeed.calculate(state.velocity, 0);
double armPIDVolts = armPID.calculate(getArmPos(), state.position);
double armPIDVolts = armPID.calculate(getArmPos(), state.position) * speedMult;
FriedLongJohns marked this conversation as resolved.
Show resolved Hide resolved
if ((getArmPos() > ARM_UPPER_LIMIT_RAD && state.velocity > 0) ||
(getArmPos() < ARM_LOWER_LIMIT_RAD && state.velocity < 0)) {
forbFlag = true;
Expand All @@ -169,9 +171,10 @@ private void driveArm(TrapezoidProfile.State state) {
}

private void driveWrist(TrapezoidProfile.State state) {
double speedMult = RobotContainer.isdriverchild ? ARM_SLOWMODE_MULT[1] : 1;
double kgv = wristFeed.calculate(getWristPosRelativeToGround(), state.velocity, 0);
double wristFeedVolts = wristFeed.calculate(getWristPosRelativeToGround(), state.velocity, 0);
double wristPIDVolts = wristPID.calculate(getWristPos(), state.position);
FriedLongJohns marked this conversation as resolved.
Show resolved Hide resolved
double wristPIDVolts = wristPID.calculate(getWristPos(), state.position) * speedMult;
if ((getWristPos() > WRIST_UPPER_LIMIT_RAD && state.velocity > 0) ||
(getWristPos() < WRIST_LOWER_LIMIT_RAD && state.velocity < 0)) {
forbFlag = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,26 @@ public double getGamePieceDistanceIn() {
}

public void setRollerMode(RollerMode mode) {
setSpeed(mode.speed);
setSpeed(mode.getSpeed());
setLedColor(mode.ledColor);
}

public void putRollerConstsOnSmartDashboard() {
SmartDashboard.putNumber("Intake Cone Speed", RollerMode.INTAKE_CONE.speed);
SmartDashboard.putNumber("Outtake Cone Speed", RollerMode.OUTTAKE_CONE.speed);
SmartDashboard.putNumber("Intake Cube Speed", RollerMode.INTAKE_CUBE.speed);
SmartDashboard.putNumber("Outtake Cube Speed", RollerMode.OUTTAKE_CUBE.speed);
SmartDashboard.putNumber("Intake Cone Speed", RollerMode.INTAKE_CONE.getSpeed());
SmartDashboard.putNumber("Outtake Cone Speed", RollerMode.OUTTAKE_CONE.getSpeed());
SmartDashboard.putNumber("Intake Cube Speed", RollerMode.INTAKE_CUBE.getSpeed());
SmartDashboard.putNumber("Outtake Cube Speed", RollerMode.OUTTAKE_CUBE.getSpeed());
SmartDashboard.putNumber("Intake Cone Time", RollerMode.INTAKE_CONE.time);
SmartDashboard.putNumber("Outtake Cone Time", RollerMode.OUTTAKE_CONE.time);
SmartDashboard.putNumber("Intake Cube Time", RollerMode.INTAKE_CUBE.time);
SmartDashboard.putNumber("Outtake Cube Time", RollerMode.OUTTAKE_CUBE.time);
}

public void getRollerConstsOnSmartDashboard() {
RollerMode.INTAKE_CONE.speed = SmartDashboard.getNumber("Intake Cone Speed", RollerMode.INTAKE_CONE.speed);
RollerMode.OUTTAKE_CONE.speed = SmartDashboard.getNumber("Outtake Cone Speed", RollerMode.OUTTAKE_CONE.speed);
RollerMode.INTAKE_CUBE.speed = SmartDashboard.getNumber("Intake Cube Speed", RollerMode.INTAKE_CUBE.speed);
RollerMode.OUTTAKE_CUBE.speed = SmartDashboard.getNumber("Outtake Cube Speed", RollerMode.OUTTAKE_CUBE.speed);
RollerMode.INTAKE_CONE.setSpeed(SmartDashboard.getNumber("Intake Cone Speed", RollerMode.INTAKE_CONE.getSpeed()));
RollerMode.OUTTAKE_CONE.setSpeed(SmartDashboard.getNumber("Outtake Cone Speed", RollerMode.OUTTAKE_CONE.getSpeed()));
RollerMode.INTAKE_CUBE.setSpeed(SmartDashboard.getNumber("Intake Cube Speed", RollerMode.INTAKE_CUBE.getSpeed()));
RollerMode.OUTTAKE_CUBE.setSpeed(SmartDashboard.getNumber("Outtake Cube Speed", RollerMode.OUTTAKE_CUBE.getSpeed()));
RollerMode.INTAKE_CONE.time = SmartDashboard.getNumber("Intake Cone Time", RollerMode.INTAKE_CONE.time);
RollerMode.OUTTAKE_CONE.time = SmartDashboard.getNumber("Outtake Cone Time", RollerMode.OUTTAKE_CONE.time);
RollerMode.INTAKE_CUBE.time = SmartDashboard.getNumber("Intake Cube Time", RollerMode.INTAKE_CUBE.time);
Expand Down