Skip to content
Open
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
22 changes: 22 additions & 0 deletions tasks/java-evaluation/Elevator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Elevator {
private int floor;

public Elevator(int start) {
System.out.println("Elevator instantiated at floor " + start);
floor = start;
}

public void moveUp() {
floor++;
System.out.println("Moving up... now at floor " + floor);
}

public void moveDown() {
floor--;
System.out.println("Moving down... now at floor " + floor);
}

public int getCurrentFloor() {
return floor;
}
}
26 changes: 26 additions & 0 deletions tasks/java-evaluation/ElevatorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class ElevatorController {
private int minFloor;
private int maxFloor;
private Elevator elevator;

public ElevatorController(Elevator e, int min, int max) {
elevator = e;
minFloor = min;
maxFloor = max;
}

public void goToFloor(int floor) {
if (floor < minFloor || floor > maxFloor) {
System.out.println("Floor " + floor + " is not a valid floor");
} else {
while (elevator.getCurrentFloor() != floor) {
if (elevator.getCurrentFloor() < floor) {
elevator.moveUp();
} else {
elevator.moveDown();
}
}
System.out.println("Arrived at floor " + floor);
}
}
}
12 changes: 12 additions & 0 deletions tasks/java-evaluation/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Main {
public static void main(String[] args) {
Elevator elevator = new Elevator(1);
ElevatorController controller = new ElevatorController(elevator, 1, 5);
controller.goToFloor(3);
controller.goToFloor(2);
controller.goToFloor(0);
controller.goToFloor(6);
controller.goToFloor(5);
controller.goToFloor(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public RobotContainer() {

private void configureBindings() {
// TODO: Bind indexForSeconds(1.5) to joystick button 1
joystick.button(1).onTrue(indexer.indexForSeconds(1.5));
}

public Command getAutonomousCommand() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.*;

public class Indexer extends SubsystemBase {
// TODO: Add indexing state variable here

private boolean indexing;
/** Creates a new Indexer subsystem. */
public Indexer() {}

public Indexer() {
indexing = false;
}
/** Starts the indexing process. */
public void startIndexing() {
// TODO: Set indexing state to true
indexing = true;
}

/** Stops the indexing process. */
public void stopIndexing() {
// TODO: Set indexing state to false
indexing = false;
}

/**
Expand All @@ -29,10 +33,14 @@ public void stopIndexing() {
*/
public boolean isIndexing() {
// TODO: Return indexing state
return false;
return indexing;
}

// TODO: Implement indexForSeconds() command factory
public Command indexForSeconds(double seconds) {
// return Commands.runOnce(() -> startIndexing()).withTimeout(seconds).runOnce(() -> stopIndexing());
return Commands.runOnce(() -> startIndexing()).andThen(Commands.waitSeconds(seconds)).andThen(()-> stopIndexing());
}

@Override
public void periodic() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@
public class RobotContainer {
private final CommandJoystick joystick = new CommandJoystick(0);

// private final Shooter shooter;
private final Shooter shooter;

public RobotContainer() {
// Use real or sim ShooterIO
// shooter = new Shooter(RobotBase.isReal() ? new ShooterIOTalonFX() : new ShooterIOSim());
shooter = new Shooter(RobotBase.isReal() ? new ShooterIOTalonFX() : new ShooterIOSim());

configureBindings();
}

private void configureBindings() {
// Example binding: spin shooter at 50% while holding button 1
// Once the shooter is implemented, you should see the motor spinning at 3000rpm when button 1 is held down
/*
joystick
.button(1)
.whileTrue(Commands.run(() -> shooter.spin(0.5), shooter))
.onFalse(Commands.run(() -> shooter.stop(), shooter));
*/
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
package frc.robot.subsystems.shooter;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.subsystems.shooter.ShooterIO.ShooterIOInputs;

// Main Shooter subsystem logic
public class Shooter extends SubsystemBase {
// TODO: Add a private field for your ShooterIO instance
// TODO: Add a private field for your ShooterIOInputs instance and initialize it
private ShooterIO io;

private ShooterIOInputs inputs = new ShooterIOInputs();
// TODO: Create the constructor that takes a ShooterIO instance as a parameter
// public Shooter(ShooterIO io) { ... }
public Shooter(ShooterIO io) {
this.io = io;
}

@Override
public void periodic() {
// This method will be called once per scheduler run
// TODO: Call the updateInputs method on your ShooterIO instance
io.updateInputs(inputs);
System.out.println(inputs.motorRPM);
}

// TODO: Add a public method to spin the shooter motor at a given percentage output
// public void spin(double percent) { ... }

public void spin(double percent) {
io.setMotorPercentOutput(percent);
}
// TODO: Add a public method to stop the shooter motor
// public void stop() { ... }

public void stop() {
io.setMotorPercentOutput(0.0);
}
// TODO: Add a public method to return the current motor RPM
// public double getCurrentRPM() { ... }
public double getCurrentRPM(){
return inputs.motorRPM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
public class ShooterIOSim implements ShooterIO {
// Usually this would be in a Constants file, we have it here for convenience
private static final double MAX_RPM = 6000.0;
private double simulatedMotorPercent;

// TODO: Add a private field `simulatedMotorPercent` to store the simulated motor percentage

@Override
public void updateInputs(ShooterIOInputs inputs) {
// TODO: Simulate motorRPM by multiplying the stored simulatedMotorPercent by the max RPM
inputs.motorRPM = 0.0; // Placeholder - replace 0.0
inputs.motorRPM = simulatedMotorPercent * MAX_RPM; // Placeholder - replace 0.0
}

@Override
public void setMotorPercentOutput(double percent) {
// TODO: Store the given `percent` in your simulated motor percentage field
simulatedMotorPercent = percent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public ShooterIOTalonFX() {
public void updateInputs(ShooterIOInputs inputs) {
// TODO: Read the motor’s velocity (rotations per second) as a double using
// motor.getVelocity().getValueAsDouble()

double rps = motor.getVelocity().getValueAsDouble();
// TODO: Save the RPM to inputs.motorRPM (convert from rotations per second)
inputs.motorRPM = rps * 60;
}

@Override
public void setMotorPercentOutput(double percent) {
// TODO: Use motor.setControl and the dutyCycleOut variable to set the motor’s percent output
// Tip: Search up documentation for DutyCycleOut methods
motor.setControl(dutyCycleOut.withOutput(percent));
}
}