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

Algae #28

Merged
merged 6 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.subsystems.AlgaeArm;
import frc.robot.subsystems.AlgaeGripper;

public class Robot extends TimedRobot {
private AlgaeArm algaeArm;
private AlgaeGripper algaeGripper;

@Override
public void robotInit() {
algaeArm = new AlgaeArm();
algaeGripper = new AlgaeGripper();

}

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/frc/robot/RobotMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
public class RobotMap {

private RobotMap() {}

public static final int ALGAE_GRIPPER_DIGITALINPUT = 0;
public static final int ALGAE_ARM_TOP = 0;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
public static final int ALGAE_ARM_BOTTOM = 0;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
public static final int ALGAE_GRIPPER_MOTOR = 0;
public static final int FORWARD_PISTON_FORWARD_CHANNEL = 0;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
public static final int FORWARD_PISTON_REVERSE_CHANI = 0;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
public static final int BACKWARD_PISTON_FORWARD_CHANNEL = 0;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
public static final int BACKWARD_PISTON_REVERSE_CHANI = 0;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
// add constants here
// public static final type NAME = value;
}
36 changes: 36 additions & 0 deletions src/main/java/frc/robot/commands/CollectAlgae.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.AlgaeGripper;

public class CollectAlgae extends Command {
private AlgaeGripper algaeGripper;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

public CollectAlgae(){
this.algaeGripper = new AlgaeGripper();
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

addRequirements(algaeGripper);
}

@Override
public void initialize() {
algaeGripper.rotateCollect();
}

@Override
public void execute() {

}

@Override
public boolean isFinished() {
return algaeGripper.hasAlgae();
}

@Override
public void end(boolean interrupted) {
algaeGripper.stop();
}


}
35 changes: 35 additions & 0 deletions src/main/java/frc/robot/commands/ExtendedAlgaeArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.AlgaeArm;

public class ExtendedAlgaeArm extends Command {
private AlgaeArm algaeArm;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

public ExtendedAlgaeArm(){
this.algaeArm = new AlgaeArm();
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

addRequirements(algaeArm);
}

@Override
public void initialize() {
algaeArm.extend();
}

@Override
public void execute() {

}

@Override
public boolean isFinished() {
return algaeArm.isExtended();
}

@Override
public void end(boolean interrupted) {
algaeArm.stop();
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
}

}
34 changes: 34 additions & 0 deletions src/main/java/frc/robot/commands/HoldAlgae.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.AlgaeGripper;

public class HoldAlgae extends Command {
private AlgaeGripper algaeGripper;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

public HoldAlgae(){
this.algaeGripper = new AlgaeGripper();
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

addRequirements(algaeGripper);
}

@Override
public void initialize() {
algaeGripper.rotateHold();
}

@Override
public void execute() {

}

@Override
public boolean isFinished() {
return false;
}

@Override
public void end(boolean interrupted) {
algaeGripper.stop();
}
}
34 changes: 34 additions & 0 deletions src/main/java/frc/robot/commands/ReleaseAlgae.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.AlgaeGripper;

public class ReleaseAlgae extends Command {
private AlgaeGripper algaeGripper;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

public ReleaseAlgae(){
this.algaeGripper = new AlgaeGripper();
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

addRequirements(algaeGripper);
}

@Override
public void initialize() {
algaeGripper.rotateRelease();
}

@Override
public void execute() {

}

@Override
public boolean isFinished() {
return !algaeGripper.hasAlgae();
}

@Override
public void end(boolean interrupted) {

tomtzook marked this conversation as resolved.
Show resolved Hide resolved
}
}
34 changes: 34 additions & 0 deletions src/main/java/frc/robot/commands/RetractAlgaeArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.AlgaeArm;

public class RetractAlgaeArm extends Command {
private AlgaeArm algaeArm;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

public RetractAlgaeArm(){
this.algaeArm = new AlgaeArm();
tomtzook marked this conversation as resolved.
Show resolved Hide resolved

addRequirements(algaeArm);
}

@Override
public void initialize() {
algaeArm.retract();
}

@Override
public void execute() {

}

@Override
public boolean isFinished() {
return algaeArm.isRetracted();
}

@Override
public void end(boolean interrupted) {
}

}
52 changes: 52 additions & 0 deletions src/main/java/frc/robot/subsystems/AlgaeArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.RobotMap;

public class AlgaeArm extends SubsystemBase {
private DoubleSolenoid solenoidForward;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
private DoubleSolenoid solenoidBackward;
private DigitalInput switchTop;
private DigitalInput switchBottom;

public AlgaeArm(){
this.solenoidForward = new DoubleSolenoid(PneumaticsModuleType.REVPH, RobotMap.FORWARD_PISTON_FORWARD_CHANNEL, RobotMap.FORWARD_PISTON_REVERSE_CHANI);
this.solenoidBackward = new DoubleSolenoid(PneumaticsModuleType.REVPH, RobotMap.BACKWARD_PISTON_FORWARD_CHANNEL, RobotMap.BACKWARD_PISTON_REVERSE_CHANI);
this.switchTop = new DigitalInput(RobotMap.ALGAE_ARM_TOP);
this.switchBottom = new DigitalInput(RobotMap.ALGAE_ARM_BOTTOM);
}

public boolean isExtended(){
return !(switchTop.get()) && !(switchBottom.get());
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
}

public boolean isRetracted(){
return switchTop.get() && switchBottom.get();
}

public void extend(){
solenoidForward.set(DoubleSolenoid.Value.kForward);
solenoidBackward.set(DoubleSolenoid.Value.kForward);
}

public void retract(){
solenoidForward.set(DoubleSolenoid.Value.kReverse);
solenoidBackward.set(DoubleSolenoid.Value.kReverse);
}

public void stop(){
solenoidForward.set(DoubleSolenoid.Value.kOff);
solenoidBackward.set(DoubleSolenoid.Value.kOff);
}

@Override
public void periodic(){
SmartDashboard.putBoolean("AlgaeArmExtended", isExtended());
SmartDashboard.putBoolean("AlgaeArmRetracted", isRetracted());
}

}
47 changes: 47 additions & 0 deletions src/main/java/frc/robot/subsystems/AlgaeGripper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package frc.robot.subsystems;

import com.revrobotics.spark.SparkLowLevel;
import com.revrobotics.spark.SparkMax;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.RobotMap;

public class AlgaeGripper extends SubsystemBase {
private static final double COLLECT_SPEED = 0.8;
tomtzook marked this conversation as resolved.
Show resolved Hide resolved
private static final double RELEASE_SPEED = -0.5;
private static final double HOLD_SPEED = 0.2;
private SparkMax motor;
private DigitalInput digitalInput;


public AlgaeGripper(){
this.motor = new SparkMax(RobotMap.ALGAE_GRIPPER_MOTOR, SparkLowLevel.MotorType.kBrushless);
this.digitalInput = new DigitalInput(RobotMap.ALGAE_GRIPPER_DIGITALINPUT);
}

public boolean hasAlgae(){
return !digitalInput.get();
}

public void rotateCollect(){
motor.set(COLLECT_SPEED);
}

public void rotateRelease(){
motor.set(RELEASE_SPEED);
}

public void rotateHold(){
motor.set(HOLD_SPEED);
}

public void stop(){
motor.stopMotor();
}

@Override
public void periodic(){
SmartDashboard.putBoolean("HasAlgae", hasAlgae());
}
}