-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added wrist, wristio, and wristiotalonfx!! based on coco's arm code from yesterday. also added motor and encoder ports to the list * created wrist object in the robot class! * added io methods in wrist class so they can actually be called * fixed getWristDegrees method to actually get degrees instead of rotations * split position status signal into absolutePosition and relativePosition * made other changes amber suggested (thanks amber!) * deleted setWristVoltage bc it didn't do anything and wasn't used --------- Co-authored-by: amb2127 <[email protected]>
- Loading branch information
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package frc.subsystem.wrist; | ||
|
||
import edu.wpi.first.wpilibj.Timer; | ||
import frc.subsystem.AbstractSubsystem; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Wrist extends AbstractSubsystem { | ||
|
||
private final WristIO io; | ||
private final WristInputsAutoLogged inputs = new WristInputsAutoLogged(); | ||
|
||
public Wrist(WristIO wristio) { | ||
super(); | ||
this.io = wristio; | ||
} | ||
|
||
|
||
public synchronized void setWristPosition(double positionInDegrees) { | ||
//does NOT set position relative to the ground, just relative to the arm | ||
double currentTime = Timer.getFPGATimestamp(); | ||
io.setPosition(positionInDegrees); | ||
Logger.recordOutput("Wrist target position", positionInDegrees); | ||
} | ||
|
||
|
||
@Override | ||
public synchronized void update() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Wrist", inputs); | ||
} | ||
|
||
public double getWristAbsoluteDegrees() { | ||
return (inputs.wristAbsolutePosition * 360.0) % 360; | ||
} | ||
|
||
public void zeroWristEncoder() { | ||
io.zeroWristEncoder(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package frc.subsystem.wrist; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface WristIO { | ||
@AutoLog | ||
class WristInputs { | ||
double wristAbsolutePosition = 0.0; | ||
double wristRelativePosition = 0.0; | ||
double wristVelocity = 0.0; | ||
double wristCurrent = 0.0; | ||
double wristTemp = 0.0; | ||
double wristVoltage = 0.0; | ||
|
||
} | ||
|
||
default void updateInputs(WristInputs inputs) {} | ||
|
||
default void zeroWristEncoder() {} | ||
|
||
default void setPosition(double position) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package frc.subsystem.wrist; | ||
|
||
import com.ctre.phoenix6.BaseStatusSignal; | ||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.configs.FeedbackConfigs; | ||
import com.ctre.phoenix6.configs.MotionMagicConfigs; | ||
import com.ctre.phoenix6.configs.Slot0Configs; | ||
import com.ctre.phoenix6.controls.MotionMagicVoltage; | ||
import com.ctre.phoenix6.hardware.CANcoder; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.signals.GravityTypeValue; | ||
import com.ctre.phoenix6.signals.FeedbackSensorSourceValue; | ||
|
||
import static frc.robot.Constants.Ports.*; | ||
|
||
public class WristIOTalonFX implements WristIO { | ||
|
||
private final TalonFX wristMotor; | ||
private final CANcoder absoluteEncoder; | ||
|
||
|
||
private final StatusSignal<Double> wristAbsolutePosition; | ||
private final StatusSignal<Double> wristRelativePosition; | ||
private final StatusSignal<Double> wristVelocity; | ||
private final StatusSignal<Double> wristCurrent; | ||
private final StatusSignal<Double> wristTemp; | ||
private final StatusSignal<Double> wristVoltage; | ||
private final MotionMagicVoltage motionMagicControl = new MotionMagicVoltage(0); | ||
|
||
|
||
|
||
public WristIOTalonFX() { | ||
|
||
wristMotor = new TalonFX(WRIST_MOTOR); | ||
absoluteEncoder = new CANcoder(WRIST_ENCODER); | ||
|
||
TalonFXConfiguration configs = new TalonFXConfiguration(); | ||
|
||
FeedbackConfigs wristFeedBackConfigs = configs.Feedback; | ||
wristFeedBackConfigs.FeedbackRemoteSensorID = absoluteEncoder.getDeviceID(); | ||
wristFeedBackConfigs.FeedbackSensorSource = FeedbackSensorSourceValue.FusedCANcoder; | ||
//ask amber about below | ||
wristFeedBackConfigs.SensorToMechanismRatio = 1; | ||
wristFeedBackConfigs.RotorToSensorRatio = 1.0 / 81; | ||
|
||
MotionMagicConfigs wristMotionMagicConfig = configs.MotionMagic; | ||
wristMotionMagicConfig.MotionMagicAcceleration = 1; //TODO change motion magic values | ||
wristMotionMagicConfig.MotionMagicCruiseVelocity = 10; | ||
wristMotionMagicConfig.MotionMagicJerk = 50; | ||
|
||
|
||
Slot0Configs slot0 = configs.Slot0; | ||
slot0.kP = 0; | ||
slot0.kI = 0; | ||
slot0.kD = 0; | ||
slot0.kV = 0; | ||
slot0.kS = 0; // Approximately 0.25V to get the mechanism moving | ||
slot0.kG = 0; | ||
slot0.GravityType = GravityTypeValue.Arm_Cosine; | ||
|
||
wristMotor.getConfigurator().apply(configs); | ||
|
||
wristAbsolutePosition = absoluteEncoder.getAbsolutePosition(); | ||
wristRelativePosition = wristMotor.getPosition(); | ||
wristVelocity = wristMotor.getVelocity(); | ||
wristCurrent = wristMotor.getSupplyCurrent(); | ||
wristTemp = wristMotor.getDeviceTemp(); | ||
wristVoltage = wristMotor.getMotorVoltage(); | ||
|
||
BaseStatusSignal.setUpdateFrequencyForAll(50, wristAbsolutePosition, wristRelativePosition, wristVelocity, wristVoltage, wristCurrent, wristTemp); | ||
|
||
wristMotor.optimizeBusUtilization(); | ||
absoluteEncoder.optimizeBusUtilization(); | ||
} | ||
|
||
public void setPosition(double position){ | ||
wristMotor.setControl(motionMagicControl.withPosition(position).withSlot(0).withEnableFOC(true).withOverrideBrakeDurNeutral(true)); | ||
} | ||
|
||
public void updateInputs(WristInputs inputs) { | ||
BaseStatusSignal.refreshAll(wristAbsolutePosition, wristRelativePosition, wristVelocity, wristCurrent, | ||
wristTemp, wristVoltage); | ||
//Not sure if this is the fastest way to get encoder pos | ||
//needs optimization!!!!!! | ||
inputs.wristAbsolutePosition = absoluteEncoder.getPosition().getValue(); | ||
inputs.wristRelativePosition = wristRelativePosition.getValue(); | ||
inputs.wristVelocity = wristVelocity.getValue(); | ||
inputs.wristCurrent = wristCurrent.getValue(); | ||
inputs.wristTemp = wristTemp.getValue(); | ||
inputs.wristVoltage = wristVoltage.getValue(); | ||
} | ||
|
||
|
||
public void zeroWristEncoder() { | ||
absoluteEncoder.setPosition(0); | ||
} | ||
} |