Skip to content

Commit 47b4f19

Browse files
Ishan1522lukeful
andauthored
Examples yay (#21)
* maybe it will work * Added more intake stuff and made it finally build! * intake commands * Cool elevator stuff * more elevator stuff * Hopefully i finish this soon * idk how that got in there * Fun arm things * format * Remove unnecessary blank line in MathUtil.java * nerf intake to not use position for otb intake. delete arm example bc it is redundant with elevator existing * format i think? * update beta version --------- Co-authored-by: Ishan1522 <[email protected]>
1 parent 4444305 commit 47b4f19

File tree

16 files changed

+475
-39
lines changed

16 files changed

+475
-39
lines changed

src/main/java/frc/robot/BuildConstants.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ public final class BuildConstants {
66
public static final String MAVEN_NAME = "4829-BaseRobotCode";
77
public static final String VERSION = "unspecified";
88
public static final int GIT_REVISION = 15;
9-
public static final String GIT_SHA = "f6cf5383d95d1116029cbb69e2db020295f5c2bf";
10-
public static final String GIT_DATE = "2024-11-09 19:29:39 EST";
11-
public static final String GIT_BRANCH = "actual-unit-tests";
12-
public static final String BUILD_DATE = "2024-11-09 19:50:39 EST";
13-
public static final long BUILD_UNIX_TIME = 1731199839115L;
9+
public static final String GIT_SHA = "9b2d52efc94f51550c86781dc4d51112afc44b13";
10+
public static final String GIT_DATE = "2024-12-16 17:53:23 EST";
11+
public static final String GIT_BRANCH = "ExamplesYay";
12+
public static final String BUILD_DATE = "2024-12-18 17:41:48 EST";
13+
public static final long BUILD_UNIX_TIME = 1734561708416L;
1414
public static final int DIRTY = 1;
1515

1616
private BuildConstants() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This command ejects the note from the intake by reversing the rollors
2+
3+
package frc.robot.commands.intake;
4+
5+
import edu.wpi.first.wpilibj2.command.Command;
6+
import frc.robot.subsystems.intake.Intake;
7+
8+
public class Outtake extends Command {
9+
private final Intake intakeSubsystem;
10+
11+
public Outtake(Intake intake) {
12+
this.intakeSubsystem = intake;
13+
addRequirements(this.intakeSubsystem);
14+
}
15+
16+
// Called when the command is initially scheduled.
17+
@Override
18+
public void initialize() {}
19+
20+
// Called every time the scheduler runs while the command is scheduled.
21+
@Override
22+
public void execute() {
23+
intakeSubsystem.setIntakeSpeed(-1);
24+
}
25+
26+
// Called once the command ends or is interrupted.
27+
@Override
28+
public void end(boolean interrupted) {}
29+
30+
// Returns true when the command should end.
31+
@Override
32+
public boolean isFinished() {
33+
return false;
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This command runs the rollers from the intake and grabs the note from the floor
2+
3+
package frc.robot.commands.intake;
4+
5+
import edu.wpi.first.wpilibj2.command.Command;
6+
import frc.robot.subsystems.intake.Intake;
7+
8+
public class RegularIntake extends Command {
9+
private final Intake intakeSubsystem;
10+
11+
public RegularIntake(Intake intake) {
12+
this.intakeSubsystem = intake;
13+
addRequirements(this.intakeSubsystem);
14+
}
15+
16+
// Called when the command is initially scheduled.
17+
@Override
18+
public void initialize() {}
19+
20+
// Called every time the scheduler runs while the command is scheduled.
21+
@Override
22+
public void execute() {
23+
intakeSubsystem.setIntakeSpeed(1);
24+
}
25+
26+
// Called once the command ends or is interrupted.
27+
@Override
28+
public void end(boolean interrupted) {}
29+
30+
// Returns true when the command should end.
31+
@Override
32+
public boolean isFinished() {
33+
return false;
34+
}
35+
}

src/main/java/frc/robot/extras/util/JoystickUtil.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ public static double modifyAxis(DoubleSupplier supplierValue, int exponent) {
4343
return value;
4444
}
4545

46-
public static double modifyAxisCubed(DoubleSupplier supplierValue) {
47-
double value = supplierValue.getAsDouble();
48-
49-
// Deadband
50-
value = JoystickUtil.deadband(value, JoystickConstants.DEADBAND_VALUE);
51-
52-
// Cube the axis
53-
value = Math.copySign(value * value * value, value);
54-
55-
return value;
56-
}
57-
5846
/**
5947
* Converts the two axis coordinates to polar to get both the angle and radius, so they can work
6048
* in a double[] list.
@@ -81,22 +69,4 @@ public static double[] modifyAxisPolar(
8169
Math.copySign(Math.pow(yInput, exponent), yInput)
8270
};
8371
}
84-
85-
public static double[] modifyAxisCubedPolar(DoubleSupplier xJoystick, DoubleSupplier yJoystick) {
86-
double xInput =
87-
JoystickUtil.deadband(xJoystick.getAsDouble(), JoystickConstants.DEADBAND_VALUE);
88-
double yInput = deadband(yJoystick.getAsDouble(), JoystickConstants.DEADBAND_VALUE);
89-
if (Math.abs(xInput) > 0 && Math.abs(yInput) > 0) {
90-
double theta = Math.atan(xInput / yInput);
91-
double hypotenuse = Math.sqrt(xInput * xInput + yInput * yInput);
92-
double cubedHypotenuse = Math.pow(hypotenuse, 3);
93-
xInput = Math.copySign(Math.sin(theta) * cubedHypotenuse, xInput);
94-
yInput = Math.copySign(Math.cos(theta) * cubedHypotenuse, yInput);
95-
return new double[] {xInput, yInput};
96-
}
97-
return new double[] {
98-
Math.copySign(xInput * xInput * xInput, xInput),
99-
Math.copySign(yInput * yInput * yInput, yInput)
100-
};
101-
}
10272
}

src/main/java/frc/robot/extras/util/MathUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package frc.robot.extras.util;
22

33
import edu.wpi.first.math.geometry.Rotation3d;
4+
import frc.robot.BuildConstants;
45
import java.util.Random;
56

67
public class MathUtil {
78
/**
89
* random object that generates random variables the seed is the hash of GIT_SHA this way when you
910
* do log-replay even the generated random numbers are the same
1011
*/
11-
private static final Random random = new Random((long) Math.random());
12+
private static final Random random = new Random(BuildConstants.GIT_SHA.hashCode());
1213

1314
public static double linearInterpretationWithBounding(
1415
double x1, double y1, double x2, double y2, double x) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/** This subsystem is an elevator that uses PID for its position. */
2+
package frc.robot.subsystems.elevator;
3+
4+
import edu.wpi.first.wpilibj2.command.SubsystemBase;
5+
import org.littletonrobotics.junction.Logger;
6+
7+
public class Elevator extends SubsystemBase {
8+
/** Creates a new Elevator. */
9+
private ElevatorInterface elevatorInterface;
10+
11+
private ElevatorInputsAutoLogged inputs = new ElevatorInputsAutoLogged();
12+
13+
public Elevator(ElevatorInterface elevatorInterface) {
14+
this.elevatorInterface = elevatorInterface;
15+
}
16+
17+
public double getElevatorPosition() {
18+
return elevatorInterface.getElevatorPosition();
19+
}
20+
21+
public double getVolts() {
22+
return elevatorInterface.getVolts();
23+
}
24+
25+
public void setElevatorPosition(double position) {
26+
elevatorInterface.setElevatorPosition(position);
27+
}
28+
29+
public void setVolts(double volts) {
30+
elevatorInterface.setVolts(volts);
31+
}
32+
33+
@Override
34+
public void periodic() {
35+
// This method will be called once per scheduler run
36+
elevatorInterface.updateInputs(inputs);
37+
Logger.processInputs("Elevator/", inputs);
38+
}
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package frc.robot.subsystems.elevator;
2+
3+
public class ElevatorConstants {
4+
public static final int ELEVATOR_LEADER_MOTOR_ID = 0 - 9;
5+
public static final int ELEVATOR_FOLLOWER_MOTOR_ID = 0 - 9;
6+
7+
public static final double ELEVATOR_P = 0 - 9;
8+
public static final double ELEVATOR_I = 0 - 9;
9+
public static final double ELEVATOR_D = 0 - 9;
10+
11+
public static final double DRUM_RADIUS = 0 - 9;
12+
public static final double ELEVATOR_GEAR_RATIO = 2;
13+
public static final double ELEVATOR_CARRIAGE_MASS = 0 - 9;
14+
public static final double ENCODER_CONVERSION_FACTOR = 71.81;
15+
public static final double MIN_HEIGHT = 0;
16+
public static final double MAX_HEIGHT = 0 - 9;
17+
18+
public static final double INTAKE_POSITION = MIN_HEIGHT;
19+
public static final double SHOOT_AMP_POSITION = 0 - 9;
20+
public static final double SHOOT_SPEAKER_POSITION = 0 - 9;
21+
public static final double SHOOT_PASS_POSITION = 0 - 9;
22+
public static final double ELEVATOR_OVER_DEFENSE = MAX_HEIGHT;
23+
24+
public static final double VELOCITY_METERS_PER_SECOND = 0 - 9;
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package frc.robot.subsystems.elevator;
2+
3+
import org.littletonrobotics.junction.AutoLog;
4+
5+
public interface ElevatorInterface {
6+
7+
@AutoLog
8+
public static class ElevatorInputs {
9+
public double leaderMotorPosition = 0.0;
10+
11+
public double followerMotorPosition = 0.0;
12+
}
13+
14+
/**
15+
* Updates inputs for elevator for AdvantageKit to log
16+
*
17+
* @param inputs values related to the elevator
18+
*/
19+
public default void updateInputs(ElevatorInputs inputs) {}
20+
21+
/**
22+
* Gets the current position of the elevator
23+
*
24+
* @return
25+
*/
26+
public default double getElevatorPosition() {
27+
return 0.0;
28+
}
29+
30+
public default void setElevatorPosition(double position) {}
31+
32+
public default void setVolts(double volts) {}
33+
34+
public default double getVolts() {
35+
return 0.0;
36+
}
37+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package frc.robot.subsystems.elevator;
2+
3+
import com.ctre.phoenix6.StatusSignal;
4+
import com.ctre.phoenix6.configs.TalonFXConfiguration;
5+
import com.ctre.phoenix6.hardware.TalonFX;
6+
import edu.wpi.first.units.measure.Angle;
7+
import edu.wpi.first.units.measure.Voltage;
8+
import frc.robot.subsystems.elevator.ElevatorInterface.ElevatorInputs;
9+
10+
/** Add your docs here. */
11+
public class PhysicalElevator {
12+
private TalonFX leaderMotor = new TalonFX(ElevatorConstants.ELEVATOR_LEADER_MOTOR_ID);
13+
private TalonFX followerMotor = new TalonFX(ElevatorConstants.ELEVATOR_FOLLOWER_MOTOR_ID);
14+
15+
StatusSignal<Angle> leaderPosition;
16+
StatusSignal<Angle> followerPosition;
17+
18+
StatusSignal<Voltage> leaderAppliedVoltage;
19+
StatusSignal<Voltage> followerAppliedVoltage;
20+
21+
public PhysicalElevator() {
22+
leaderPosition = leaderMotor.getRotorPosition();
23+
followerPosition = followerMotor.getRotorPosition();
24+
25+
leaderAppliedVoltage = leaderMotor.getMotorVoltage();
26+
followerAppliedVoltage = followerMotor.getMotorVoltage();
27+
28+
TalonFXConfiguration elevatorConfig = new TalonFXConfiguration();
29+
30+
elevatorConfig.Slot0.kP = ElevatorConstants.ELEVATOR_P;
31+
elevatorConfig.Slot0.kI = ElevatorConstants.ELEVATOR_I;
32+
elevatorConfig.Slot0.kD = ElevatorConstants.ELEVATOR_D;
33+
34+
leaderMotor.getConfigurator().apply(elevatorConfig);
35+
followerMotor.getConfigurator().apply(elevatorConfig);
36+
}
37+
38+
public void updateInputs(ElevatorInputs inputs) {
39+
inputs.leaderMotorPosition = leaderPosition.getValueAsDouble();
40+
inputs.followerMotorPosition = followerPosition.getValueAsDouble();
41+
}
42+
43+
public double getElevatorPosition() {
44+
return leaderPosition.getValueAsDouble();
45+
}
46+
47+
public void setElevatorPosition(double position) {
48+
leaderMotor.setPosition(position);
49+
followerMotor.setPosition(position);
50+
}
51+
52+
public void setVolts(double volts) {
53+
leaderMotor.setVoltage(volts);
54+
followerMotor.setVoltage(volts);
55+
;
56+
}
57+
58+
public double getVolts() {
59+
return leaderMotor.getMotorVoltage().getValueAsDouble();
60+
}
61+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package frc.robot.subsystems.elevator;
2+
3+
import edu.wpi.first.math.controller.PIDController;
4+
import edu.wpi.first.math.system.plant.DCMotor;
5+
import edu.wpi.first.wpilibj.simulation.ElevatorSim;
6+
7+
/** Add your docs here. */
8+
public class SimulatedElevator implements ElevatorInterface {
9+
private ElevatorSim elevatorSim =
10+
new ElevatorSim(
11+
DCMotor.getFalcon500(2),
12+
ElevatorConstants.ELEVATOR_GEAR_RATIO,
13+
ElevatorConstants.ELEVATOR_CARRIAGE_MASS,
14+
ElevatorConstants.DRUM_RADIUS,
15+
ElevatorConstants.MIN_HEIGHT,
16+
ElevatorConstants.MAX_HEIGHT,
17+
true,
18+
0.0);
19+
private PIDController simPID;
20+
private double currentVolts;
21+
22+
public SimulatedElevator() {
23+
simPID =
24+
new PIDController(
25+
ElevatorConstants.ELEVATOR_P,
26+
ElevatorConstants.ELEVATOR_I,
27+
ElevatorConstants.ELEVATOR_D);
28+
}
29+
30+
public void updateInputs(ElevatorInputs inputs) {
31+
inputs.leaderMotorPosition = getElevatorPosition();
32+
inputs.followerMotorPosition = getElevatorPosition();
33+
}
34+
35+
public void setElevatorPosition(double position) {
36+
setVolts(simPID.calculate(getElevatorPosition(), position));
37+
}
38+
39+
public double getElevatorPosition() {
40+
return elevatorSim.getPositionMeters();
41+
}
42+
43+
public void setVolts(double volts) {
44+
currentVolts = simPID.calculate(volts);
45+
elevatorSim.setInputVoltage(currentVolts);
46+
}
47+
48+
public double getVolts() {
49+
return currentVolts;
50+
}
51+
}

0 commit comments

Comments
 (0)