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

public Elevator(int initialFloor) {
floor = initialFloor;
}

public void moveUp() {
floor++;
}

public void moveDown() {
floor--;
}

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

public ElevatorController(Elevator elevator, int minFloor, int maxFloor) {
this.elevator = elevator;
this.MIN_FLOOR = minFloor;
this.MAX_FLOOR = maxFloor;

System.out.println("Elevator instantiated at floor " + elevator.getCurrentFloor());
}

public void goToFloor(int goalFloor) {
if (goalFloor < MIN_FLOOR || goalFloor > MAX_FLOOR) {
System.out.println("Floor " + goalFloor + " is not a valid floor");
return;
}

while (elevator.getCurrentFloor() != goalFloor) {
if (goalFloor > elevator.getCurrentFloor()) {
elevator.moveUp();
System.out.println("Moving up... now at floor " + elevator.getCurrentFloor());
} else {
elevator.moveDown();
System.out.println("Moving down... now at floor " + elevator.getCurrentFloor());
}
}

System.out.println("Arrived at floor " + elevator.getCurrentFloor());
}
}
26 changes: 26 additions & 0 deletions tasks/java-evaluation/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Elevator elevator = new Elevator(1);
ElevatorController elevatorController = new ElevatorController(elevator, 1, 5);

Scanner scanner = new Scanner(System.in);

while (true) {
System.out.print("\nRequest floor: ");
String input = scanner.next();

if (input.equals("quit") || input.equals("q")) break;

try {
int requestedFloor = Integer.parseInt(input);
elevatorController.goToFloor(requestedFloor);
} catch (NumberFormatException e) {
System.out.println("Please enter a valid number.");
}
}

scanner.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public RobotContainer() {
}

private void configureBindings() {
// TODO: Bind indexForSeconds(1.5) to joystick button 1
// Bind button 1 on joystick to run indexForSeconds(1.5)
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 @@ -4,22 +4,24 @@

package frc.robot.subsystems;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Indexer extends SubsystemBase {
// TODO: Add indexing state variable here
private boolean indexing = false;

/** Creates a new Indexer subsystem. */
public Indexer() {}

/** 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 @@ -28,11 +30,20 @@ public void stopIndexing() {
* @return true if indexing, false otherwise
*/
public boolean isIndexing() {
// TODO: Return indexing state
return false;
return indexing;
}

// TODO: Implement indexForSeconds() command factory
/**
* Returns a command that indexes for a given number of seconds.
*
* @param seconds duration to index
* @return a command that runs the indexer for the given time
*/
public Command indexForSeconds(double seconds) {
return Commands.runOnce(this::startIndexing)
.andThen(Commands.waitSeconds(seconds))
.andThen(Commands.runOnce(this::stopIndexing));
}

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

// private final Shooter shooter;
// Declare the Shooter subsystem
private final Shooter shooter;

public RobotContainer() {
// Use real or sim ShooterIO
// shooter = new Shooter(RobotBase.isReal() ? new ShooterIOTalonFX() : new ShooterIOSim());
// Instantiate with real or sim implementation
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
/*
// Spin shooter at 50% while holding button 1
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,38 @@
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 final ShooterIO io;
private final 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
// Update sensor data from io
io.updateInputs(inputs);

// Debugging output
System.out.println("Shooter RPM: " + inputs.motorRPM);
}

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

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

// TODO: Add a public method to return the current motor RPM
// public double getCurrentRPM() { ... }
// Return the current motor RPM
public double getCurrentRPM() {
return inputs.motorRPM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ 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;

// TODO: Add a private field `simulatedMotorPercent` to store the simulated motor percentage
// Store the simulated motor percentage
private double simulatedMotorPercent = 0.0;

@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
// Simulate motor RPM
inputs.motorRPM = simulatedMotorPercent * MAX_RPM;
}

@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 @@ -25,15 +25,16 @@ public ShooterIOTalonFX() {

@Override
public void updateInputs(ShooterIOInputs inputs) {
// TODO: Read the motor’s velocity (rotations per second) as a double using
// motor.getVelocity().getValueAsDouble()
// Read the motor’s velocity (rotations per second)
double velocityRPS = motor.getVelocity().getValueAsDouble();

// TODO: Save the RPM to inputs.motorRPM (convert from rotations per second)
// Convert to RPM and store in inputs
inputs.motorRPM = velocityRPS * 60.0;
}

@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
// Set the percent output using DutyCycleOut
motor.setControl(dutyCycleOut.withOutput(percent));
}
}