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
Binary file added tasks/java-evaluation/Elevator.class
Binary file not shown.
43 changes: 43 additions & 0 deletions tasks/java-evaluation/Elevator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.Scanner;
public class Elevator {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int floorafter = 1;
int floorbefore = 1;
boolean floortrue = true;
System.out.println("Welcome to the elevator");
System.out.println("Elevator initiated at floor 1");
while (true) {
System.out.println("Floor request:");
floorafter = scan.nextInt();
if (floorafter > 5 || floorafter < 1) {
System.out.println("Sorry that is not a valid floor");
floortrue = false;
} else if (floorafter > floorbefore) {
System.out.println("Going up");
for (int i = floorbefore; i <= floorafter; i++) {
System.out.println("Floor " + i);
}

} else if (floorafter == floorbefore) {
System.out.println("That is the same floor");
} else {
System.out.println("Going down");
for (int i = floorbefore; i >= floorafter; i--) {
System.out.println("Floor " + i);
}

}

if (floortrue) {
floorbefore = floorafter;
}
System.out.println("Elevator initiated at floor "+floorbefore);
floortrue = true;

}

}
}


12 changes: 12 additions & 0 deletions tasks/java-evaluation/Indexer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@





/*In `Indexer.java`:
- Add a boolean field `indexing`
- Create methods:
- `public void startIndexing()`: set `indexing` to true
- `public void stopIndexing()`: set `indexing` to false
- `public boolean isIndexing()`: return `indexing`
*/
3 changes: 1 addition & 2 deletions tasks/lesson2-indexer-task/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ plugins {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

}

def ROBOT_MAIN_CLASS = "frc.robot.Main"
Expand Down
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).whileTrue(indexer.indexForSeconds(1.5));
}

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

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

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

/** 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 @@ -29,10 +34,14 @@ public void stopIndexing() {
*/
public boolean isIndexing() {
// TODO: Return indexing state
return false;
return indexing;

}

// TODO: Implement indexForSeconds() command factory
public Command indexForSeconds(double time) {
return Commands.run(() -> startIndexing()).withTimeout(time).finallyDo(() -> stopIndexing());
}

@Override
public void periodic() {
Expand Down
2 changes: 1 addition & 1 deletion tasks/lesson3-shooter-task/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ wpi.java.configureTestTasks(test)
// Configure string concat to always inline compile
tasks.withType(JavaCompile) {
options.compilerArgs.add '-XDstringConcat=inline'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public final class Constants {
public static class OperatorConstants {
public static final int kDriverControllerPort = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ private Main() {}
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ public void simulationInit() {}
/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ 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));
/*
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
Expand Up @@ -44,4 +44,4 @@ public void periodic() {
public void simulationPeriodic() {
// This method will be called once per scheduler run during simulation
}
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
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
private final ShooterIO io;
// TODO: Add a private field for your ShooterIOInputs instance and initialize it

private final ShooterIOInputs ShooterIOInput = new ShooterIOInputs();
// TODO: Create the constructor that takes a ShooterIO instance as a parameter
public Shooter(ShooterIO io) {
this.io = io;
}
// public Shooter(ShooterIO 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(ShooterIOInput);

System.out.println("Shooter RPM: " + ShooterIOInput.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 ShooterIOInput.motorRPM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class ShooterIOInputs {
* @param percent Output percentage from -1.0 to 1.0.
*/
void setMotorPercentOutput(double percent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ public class ShooterIOSim implements ShooterIO {
private static final double MAX_RPM = 6000.0;

// TODO: Add a private field `simulatedMotorPercent` to 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
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 @@ -26,14 +26,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()
double motorVelocityRPM = motor.getVelocity().getValueAsDouble();

// TODO: Save the RPM to inputs.motorRPM (convert from rotations per second)
inputs.motorRPM = motorVelocityRPM * 60.0;
}

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