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

Feature/arm 2024 #7

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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
21 changes: 11 additions & 10 deletions src/main/java/frc/robot/subsystems/arm/Arm.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

public class Arm extends SubsystemBase {
private static Arm INSTANCE;
private final ArmInputsLogged inputs = new ArmInputsLogged();
katzuv marked this conversation as resolved.
Show resolved Hide resolved
private final ArmIO io;
private final Mechanism2d mechanism = new Mechanism2d(
3, 3
Expand All @@ -27,24 +28,24 @@ public class Arm extends SubsystemBase {
new MechanismLigament2d("Shoulder", ArmConstants.SHOULDER_LENGTH, 0)
);
private final MechanismLigament2d elbow = shoulder.append(
new MechanismLigament2d("Elbow", ArmConstants.ELBOW_LENGTH, 0, 10, new Color8Bit(Color.kPurple))
new MechanismLigament2d("Elbow", ArmConstants.ELBOW_LENGTH, 0)
);
private Command lastCommand = null;
private Command currentCommand = null;
private boolean changedToDefaultCommand = false;

private Arm(ArmIO io) {
this.io = io;

private Arm() {
if (Robot.isReal()) {
io = new ArmIOReal();
} else {
io = new ArmIOReal();
}
}

public static Arm getINSTANCE() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static Arm getINSTANCE() {
public static Arm getInstance() {

if (INSTANCE == null) {
if (Robot.isReal()) {
INSTANCE = new Arm(new ArmIOSim(inputs));

} else {
INSTANCE = new Arm(new ArmIOSim(inputs));
}
Comment on lines +35 to -48
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arm object doesn't need to know whether or not it's real. In the future (already exists in the robot template), there is going to be a static initializing function for each subsystem, to which the robot mode will be passed. So for now, the creation of the io should be done in the getInstance function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there are more than 2 implementations? For example, Falcon 500 and NEO swerve implementations (Robotinyo? 👀).

INSTANCE = new Arm();
}
return INSTANCE;
}
Expand Down Expand Up @@ -93,7 +94,7 @@ public Translation2d getEndPosition() {
return ArmIO.armKinematics.forwardKinematics(shoulderAngle, shoulderAngle + elbowAngle - Math.PI);
}

public ArmIO.ArmInputs getInputs() {
public ArmInputsLogged getInputs() {
return inputs;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/subsystems/arm/ArmConstants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package frc.robot.subsystems.arm;

import com.ctre.phoenix.motorcontrol.SupplyCurrentLimitConfiguration;
import com.ctre.phoenix.motorcontrol.TalonFXInvertType;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.geometry.Translation3d;
Expand Down Expand Up @@ -45,6 +46,8 @@ public class ArmConstants {
public static final double END_POSITION_LOWER_X_LIMIT = 0; //[cm]
public static final double SHOULDER_ABSOLUTE_ENCODER_OFFSET = 0.4090 - SHOULDER_ZERO_POSITION / 360.0;
public static final double ELBOW_ABSOLUTE_ENCODER_OFFSET = 0.57396956434 - ELBOW_ZERO_POSITION / 360.0;
public static final SupplyCurrentLimitConfiguration CURRENT_LIMIT = new SupplyCurrentLimitConfiguration(true, 50, 0, 0);
katzuv marked this conversation as resolved.
Show resolved Hide resolved


//PID
public static final double shoulderP = 4.0;
Expand Down
24 changes: 5 additions & 19 deletions src/main/java/frc/robot/subsystems/arm/ArmIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public interface ArmIO {
katzuv marked this conversation as resolved.
Show resolved Hide resolved


ArmKinematics armKinematics = new ArmKinematics(ArmConstants.SHOULDER_LENGTH, ArmConstants.ELBOW_LENGTH);

default void setShoulderPower(double power) {
Expand All @@ -29,27 +30,12 @@ default void setElbowP(double kP) {
default void updateInputs() {
}

String getSubsystemName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?


void updateInputs(ArmInputsLogged inputs);

enum ControlMode {
PRECENT_OUTPUT,
POSITION
}

@AutoLog
class ArmInputs {

public double shoulderAngleSetPoint = 0;
double shoulderAppliedVoltage = 0;
double elbowAppliedVoltage = 0;
double shoulderAppliedCurrent = 0;
double elbowAppliedCurrent = 0;
double[] shoulderTipPose = new double[2];
double[] endEffectorPositionSetPoint = new double[2];
double shoulderAngle = 0;
double elbowAngleSetpoint = 0;
double elbowAngleRelative = 0;
double elbowAngleAbsolute = 0;
Translation2d endEffectorPose;
ControlMode shoulderControlMode = ControlMode.PRECENT_OUTPUT;
ControlMode elbowControlMode = ControlMode.PRECENT_OUTPUT;
}
}
Loading