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

Arm skeleton #14

Merged
merged 9 commits into from
Jan 21, 2025
Merged
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
86 changes: 86 additions & 0 deletions src/main/java/org/sciborgs1155/robot/arm/Arm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.sciborgs1155.robot.arm;

import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import monologue.Annotations.Log;
import monologue.Logged;
import org.sciborgs1155.robot.Robot;

/** Simple Arm subsystem used for climbing and intaking coral from the ground. */
public class Arm extends SubsystemBase implements Logged, AutoCloseable {
/** Interface for interacting with the motor itself. */
@Log.NT private final ArmIO hardware;

/**
* Returns a new {@link Arm} subsystem, which will have real hardware if the robot is real, and
* simulated if it isn't.
*/
public static Arm create() {
return new Arm(Robot.isReal() ? new RealArm() : new SimArm());
}

/** Creates a new {@link Arm} with no hardware interface(does nothing). */
public static Arm none() {
return new Arm(new NoArm());
}

/**
* Constructor.
*
* @param hardware : The ArmIO object (real/simulated/nonexistent) that will be operated on.
*/
private Arm(ArmIO hardware) {
this.hardware = hardware;
}

/**
* @return The position in radians.
*/
@Log.NT
public double position() {
return 0;
}

/**
* @return True if the arm's position is close enough to its goal, False if it isn't.
*/
public boolean atGoal() {
return true;
}

/**
* @return The position in radians/sec.
*/
@Log.NT
public double velocity() {
return 0;
}

@Log.NT
/** Moves the arm towards a specified goal angle. */
public Command goTo(Angle goal) {
return Commands.none();
}

/**
* Changes the current limit of the arm motor.
*
* @param limit The limit, in amps.
*/
public void currentLimit(double limit) {}

public Command climbSetup() {
return Commands.none();
}

public Command climbExecute() {
return Commands.none();
}

@Override
public void close() throws Exception {
hardware.close();
}
}
23 changes: 23 additions & 0 deletions src/main/java/org/sciborgs1155/robot/arm/ArmConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sciborgs1155.robot.arm;

import static edu.wpi.first.units.Units.Radians;

import edu.wpi.first.units.measure.Angle;

/** Constants for the {@link Arm} subsystem. */
public class ArmConstants {
public static final Angle INTAKE_ANGLE = Radians.of(-Math.PI / 4);
public static final Angle PROCESSOR_OUTTAKE_ANGLE = Radians.of(Math.PI * 3 / 4);
public static final Angle TROUGH_OUTTAKE_ANGLE = Radians.of(Math.PI * 3 / 4);

public static final Angle STARTING_ANGLE = Radians.of(Math.PI / 2);
public static final Angle DEFAULT_ANGLE = Radians.of(Math.PI * 5 / 8);
public static final Angle CLIMB_INTAKE_ANGLE = Radians.of(0);
public static final Angle CLIMB_FINAL_ANGLE = Radians.of(Math.PI * 3 / 4);

/** Fully extended. */
public static final Angle MIN_ANGLE = Radians.of(-Math.PI / 4 - 0.2);

/** Fully retracted. */
public static final Angle MAX_ANGLE = Radians.of(Math.PI * 3 / 4 + 0.1);
}
24 changes: 24 additions & 0 deletions src/main/java/org/sciborgs1155/robot/arm/ArmIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.sciborgs1155.robot.arm;

/** Hardware interface for {@link Arm} subsystem */
public interface ArmIO extends AutoCloseable {
/**
* @return The position in radians.
*/
public double position();

/**
* @return The position in radians/sec.
*/
public double velocity();

/** Sets the voltage of the arm motor. */
public void setVoltage(double voltage);

/**
* Changes the current limit of the arm motor.
*
* @param limit The limit, in amps.
*/
public void setCurrentLimit(double limit);
}
23 changes: 23 additions & 0 deletions src/main/java/org/sciborgs1155/robot/arm/NoArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sciborgs1155.robot.arm;

public class NoArm implements ArmIO {

@Override
public double position() {
return 0;
}

@Override
public double velocity() {
return 0;
}

@Override
public void setVoltage(double voltage) {}

@Override
public void setCurrentLimit(double limit) {}

@Override
public void close() throws Exception {}
}
23 changes: 23 additions & 0 deletions src/main/java/org/sciborgs1155/robot/arm/RealArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sciborgs1155.robot.arm;

public class RealArm implements ArmIO {

@Override
public double position() {
return 0;
}

@Override
public double velocity() {
return 0;
}

@Override
public void setVoltage(double voltage) {}

@Override
public void setCurrentLimit(double limit) {}

@Override
public void close() throws Exception {}
}
23 changes: 23 additions & 0 deletions src/main/java/org/sciborgs1155/robot/arm/SimArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sciborgs1155.robot.arm;

public class SimArm implements ArmIO {

@Override
public double position() {
return 0;
}

@Override
public double velocity() {
return 0;
}

@Override
public void setVoltage(double voltage) {}

@Override
public void setCurrentLimit(double limit) {}

@Override
public void close() throws Exception {}
}
Loading