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

Safe mode #32

wants to merge 28 commits into from

Conversation

ProfessorAtomicManiac
Copy link
Contributor

Don't merge into master until after everything is tested out

Copy link
Contributor Author

@ProfessorAtomicManiac ProfessorAtomicManiac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this code has already been tested and it works ok, but I still see a lot of problems with it that I would like to see resolved ideally before Save the Music. I can't "Request Changes" on my own branch but I do not approve this PR. @FriedLongJohns (work on arm related issues) or @BrownBear85 (work on drivetrain related issues) please fix this when you have time.

FriedLongJohns and others added 4 commits April 28, 2023 17:30
Fix everything charles whined about except using multipliers instead of limits
was an unused controller rumble variable
wasn't fully implemented before

+allow ArmTeleop.getRequestedSpeeds() to use baby max vel

+fix Arm.arm/wristConstraints not changing the max ff accel even though we had a baby max accel
@FriedLongJohns
Copy link
Contributor

FriedLongJohns commented Sep 30, 2023

Tasks

(in chronological order, not importance order!)

  • Copy arm encoder shutoff code to wrist
  • Reorganize wrist enum RollerMode
  • Make sure Roller is unaffected by slow/baby mode
  • Review drivetrain baby/slowmode code

^ Above tasks can be done in any order

    • Review that all baby/slow/normal speeds are applied correctly
    • Merge baby/slow/normal mode into an enum
    • Charles moment
    • Test code AT WORKSESSION
    • Remove debug statements, merge into master

Also, a review of how baby/safemode affects things (Correct me if I'm wrong, @ProfessorAtomicManiac ):

  Drivetrain
    slows turning max accel + max vel
    slows movement max accel + max vel
  Arm/Wrist
     slows all feedForward motor accel + max vel
     turns off manual joystick control
   Roller
     no effect

@ProfessorAtomicManiac
Copy link
Contributor Author

ProfessorAtomicManiac commented Sep 30, 2023

Yep that's correct!
Also there is a "slow mode" which is completely different from "baby mode". "Slow Mode" does:

Drivetrain
  slows turning max accel + max vel (not as much as baby mode i think)
  slows movement max accel + max vel (not as much as baby mode)
Arm/Wrist
   no effect
Roller
   no effect

FriedLongJohns

This comment was marked as resolved.

was changeable but in constants, now moved to Roller subsystem

=Also remove get/set of RollerMode.speed in favor of just making it public (if you both get and set a variable publicly without doing anything special, don't make it private)
TuskAct2 and others added 5 commits October 1, 2023 00:54
Copy link
Contributor Author

@ProfessorAtomicManiac ProfessorAtomicManiac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the looks of it, it mostly works. The code is still rough in some places so please try to clean those up before Sunday's worksession.

Comment on lines -377 to -402
// TODO: Determine actual speeds/timings for roller
public static class RollerMode {
public static RollerMode INTAKE_CONE = new RollerMode(-0.5, .5, GameObject.CONE, conePickupColor);
public static RollerMode INTAKE_CUBE = new RollerMode(0.4, .25, GameObject.CUBE, cubePickupColor);
// The obj indicates which game object the roller is trying to intake
// if obj == NONE, that means it is trying to outtake rather than intake
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;
public GameObject obj;
public Color ledColor;

/**
* @param speed A number between -1 and 1
* @param time Amount of time in seconds to keep the motor running after
* distance sensor has detected an object
* @param intake Whether the roller is outtaking or intaking
*/
public RollerMode(double speed, double time, GameObject obj, Color ledColor) {
this.speed = speed;
this.time = time;
this.obj = obj;
this.ledColor = ledColor;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally Ryan wanted all constants put into Constants.java. Personally, I think constants that are strictly only used in subsystems should stay in their subsystem classes and the only appropriate constants that should be put in Constants.java are constants that are used between subsystems or ports. That way, there is less clutter in Constants.java and it is easier to find certain constants. Seems like you agree with me on this, but do we wanna make it convention that all subsystem specific constants (excluding ports) should stay in subsystems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other solutions include creating completely new files just to store constants to organize them better. I realize that storing goal positions in Arm.java would be extremely annoying. We should probably discuss and agree on how exactly we want to store constants.

Comment on lines 47 to 53
//set mode to baby if baby was true
//else but don't set mode to norm if slow was true
if (SmartDashboard.getBoolean("safeMode", false)) {
RobotContainer.driverMode = RobotContainer.DriverMode.BABY;
} else if (RobotContainer.driverMode.isSlow()) {
RobotContainer.driverMode = RobotContainer.DriverMode.NORM;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you enable safeMode or slow the robot, how is it supposed to return back to normal mode when switched off?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see my comment in RobotContainer.java

Comment on lines +312 to +327

public static enum DriverMode {
NORM, SLOW, BABY;

public boolean isNorm() {
return this == DriverMode.NORM;
}

public boolean isSlow() {
return this == DriverMode.SLOW;
}

public boolean isBaby() {
return this == DriverMode.BABY;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really against having the logic for DriverMode snucked away in a class file meant to initialize joysticks and commands. DriverMode logic is also mixed into Robot.java. In the future if someone wants to change up DriverMode, they would have to edit code in RobotContainer.java and Robot.java, both files that I would argue would not be the first place a programmer would think of to look in. Please refactor the driver mode code (maybe make an entire subsystem class just to keep track of DriverMode, as this is used across multiple subsystems. That's just an idea though, maybe there is a less "boilerplaty" solution).

Copy link
Contributor Author

@ProfessorAtomicManiac ProfessorAtomicManiac Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also know that Ryan implemented a lib199 implmentation of all the safe mode stuff if you want to use that instead. I forgot how it works though.

Comment on lines 72 to 77
double driveMultiplier = ((DriverMode)mode.get()).isBaby() ? kBabyDriveSpeed : (
((DriverMode)mode.get()).isSlow() ? kSlowDriveSpeed : kNormalDriveSpeed
);
double rotationMultiplier = ((DriverMode)mode.get()).isBaby() ? kBabyTurnSpeed : (
((DriverMode)mode.get()).isSlow() ? kSlowDriveRotation : kNormalDriveRotation
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the code before, I realized that kBabyDriveSpeed was never actually used and baby mode was just "slow mode". This will fix that error but kinda interesting that baby mode was never used.

Comment on lines +122 to +147
public static class RollerMode {
public static RollerMode INTAKE_CONE = new RollerMode(-0.5, .5, GameObject.CONE, conePickupColor);
public static RollerMode INTAKE_CUBE = new RollerMode(0.4, .25, GameObject.CUBE, cubePickupColor);
// The obj indicates which game object the roller is trying to intake
// if obj == NONE, that means it is trying to outtake rather than intake
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;
public double time;
public GameObject obj;
public Color ledColor;

/**
* @param speed A number between -1 and 1
* @param time Amount of time in seconds to keep the motor running after
* distance sensor has detected an object
* @param intake Whether the roller is outtaking or intaking
*/
public RollerMode(double speed, double time, GameObject obj, Color ledColor) {
this.speed = speed;
this.time = time;
this.obj = obj;
this.ledColor = ledColor;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in Constants.java

make robot be able to get back to NORM drivermode
shift lambda work from RobotContainer to ArmTeleop itself
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants