-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from 20 commits
29607bf
3391e5f
3b19694
893d53b
693a41f
71c1971
edcb9a8
7f455bf
8e12c73
700f911
3ead9e7
38d3357
a0e58c8
b51421d
76c0dde
7da4eee
30b28f2
19dbdff
4d60400
9dc2d35
f06bf8d
0f4c619
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,15 @@ | |
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj.util.Color; | ||
import edu.wpi.first.wpilibj.util.Color8Bit; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Robot; | ||
import frc.robot.subsystems.arm.commands.ArmXboxControl; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Arm extends SubsystemBase { | ||
private static final ArmInputsAutoLogged inputs = new ArmInputsAutoLogged(); | ||
private static Arm INSTANCE; | ||
private final ArmInputs inputs = new ArmInputs(); | ||
private final ArmIO io; | ||
private final Mechanism2d mechanism = new Mechanism2d( | ||
3, 3 | ||
|
@@ -28,24 +26,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() { | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -94,7 +92,7 @@ public Translation2d getEndPosition() { | |
return ArmIO.armKinematics.forwardKinematics(shoulderAngle, shoulderAngle + elbowAngle - Math.PI); | ||
} | ||
|
||
public ArmIO.ArmInputs getInputs() { | ||
public ArmInputs getInputs() { | ||
return inputs; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package frc.robot.subsystems.arm; | ||
|
||
import com.ctre.phoenix.motorcontrol.SupplyCurrentLimitConfiguration; | ||
import com.ctre.phoenix.motorcontrol.TalonFXInvertType; | ||
import com.ctre.phoenix6.configs.CurrentLimitsConfigs; | ||
import com.ctre.phoenix6.configs.Slot0Configs; | ||
import com.ctre.phoenix6.configs.Slot1Configs; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.math.geometry.Translation3d; | ||
|
||
|
@@ -34,8 +39,32 @@ public class ArmConstants { | |
public static final double TICKS_PER_RADIAN_SHOULDER = SHOULDER_FALCON_TICKS_PER_REVOLUTION / (Math.PI * 2); | ||
public static final double ELBOW_FALCON_TICKS_PER_REVOLUTION = 2048 * ELBOW_GEARING; | ||
public static final double TICKS_PER_RADIAN_ELBOW = ELBOW_FALCON_TICKS_PER_REVOLUTION / (Math.PI * 2); | ||
public static final TalonFXInvertType MAIN_CLOCKWISE = TalonFXInvertType.Clockwise; | ||
public static final boolean MAIN_CLOCKWISE = true; | ||
public static final TalonFXInvertType AUX_CLOCKWISE = TalonFXInvertType.Clockwise; | ||
public static final TalonFXConfiguration shoulderMainMotorConfig = new TalonFXConfiguration(); | ||
public static final TalonFXConfiguration shoulderAuxMotorConfig = new TalonFXConfiguration(); | ||
public static final TalonFXConfiguration elbowMainMotorConfig = new TalonFXConfiguration(); | ||
public static final TalonFXConfiguration elbowAuxMotorConfig = new TalonFXConfiguration(); | ||
public static final double SHOULDER_FEED_FORWARD_MULTIPLIER = 0; | ||
public static final double ELBOW_FEED_FORWARD_MULTIPLIER = 0; | ||
public static final int SHOULDER_VELOCITY = 0; | ||
public static final int ELBOW_VELOCITY = 0; | ||
|
||
public static final Slot0Configs SHOULDER_PID= new Slot0Configs() | ||
.withKP(ArmConstants.shoulderP) | ||
.withKI(ArmConstants.shoulderI) | ||
.withKD(ArmConstants.shoulderD); | ||
Comment on lines
+53
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to create the gains as separate gains. Just write them directly here. |
||
|
||
public static final Slot1Configs ELBOW_PID = new Slot1Configs() | ||
.withKP(ArmConstants.elbowP) | ||
.withKI(ArmConstants.elbowI) | ||
.withKD(ArmConstants.elbowD); | ||
|
||
public static final double SENSOR_TO_MECHANISM_RATIO= 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used to calculate gear ratio in the motor. When using the |
||
public static final double ROTOR_TO_SENSOR_RATIO= 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used when defining an external sensor for the TalonFX. I think it's only CANCoders. |
||
|
||
|
||
|
||
|
||
public static final double ELBOW_ZERO_POSITION = 360 - 53.33; //[degrees] | ||
public static final double SHOULDER_ZERO_POSITION = 180 - 65.53; //[degrees] | ||
|
@@ -45,6 +74,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 double CURRENT_LIMIT = 10; | ||
|
||
|
||
//PID | ||
public static final double shoulderP = 4.0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package frc.robot.subsystems.arm; | ||
|
||
import edu.wpi.first.math.geometry.Translation2d; | ||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface ArmIO { | ||
katzuv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
double currentShoulderAngle = 0; | ||
double currentElbowAngle = 0; | ||
|
||
ArmKinematics armKinematics = new ArmKinematics(ArmConstants.SHOULDER_LENGTH, ArmConstants.ELBOW_LENGTH); | ||
|
||
|
@@ -29,27 +30,12 @@ default void setElbowP(double kP) { | |
default void updateInputs() { | ||
} | ||
|
||
String getSubsystemName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? |
||
|
||
void updateInputs(ArmInputs 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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.