-
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.
Wrist now fully works(excluding talon, haven't calibrated its PID or …
…tested it at all), along with MoveWristToAngle command
- Loading branch information
Showing
10 changed files
with
213 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package subsystems.wrist; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
|
||
public interface IWrist { | ||
|
||
public void updateInputs(WristInputsAutoLogged inputs); | ||
|
||
public void goToPosition(Rotation2d position); | ||
|
||
public void setPower(double power); | ||
|
||
} |
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 |
---|---|---|
@@ -1,13 +1,35 @@ | ||
package subsystems.wrist; | ||
|
||
import com.ctre.phoenix.motorcontrol.TalonSRXControlMode; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
|
||
public class WristConstants { | ||
|
||
protected static final int MOTOR_ID = 11; | ||
|
||
protected static final TalonSRXControlMode PID_CONTROL_MODE = TalonSRXControlMode.Position; | ||
public enum PresetPositions { | ||
|
||
protected static final int FULL_CIRCLE_ENCODER_TICKS = 168; | ||
STARTING(Rotation2d.fromDegrees(90)), | ||
SCORE(Rotation2d.fromDegrees(190)), | ||
SCORE_TRAP(Rotation2d.fromDegrees(390)), // find | ||
TRANSFER(Rotation2d.fromDegrees(185)), | ||
SAFE(Rotation2d.fromDegrees(180)), | ||
INTAKE(Rotation2d.fromDegrees(180)); | ||
|
||
public final Rotation2d ANGLE; | ||
|
||
PresetPositions(Rotation2d angle) { | ||
this.ANGLE = angle; | ||
} | ||
|
||
} | ||
|
||
public static final double LENGTH_OF_ENDEFFECTOR = 0.1; | ||
|
||
public static final double WRIST_MASS_KG = 0.5; | ||
|
||
public static final Rotation2d BACKWARD_ANGLE_LIMIT = Rotation2d.fromDegrees(-50); | ||
|
||
public static final Rotation2d FORWARD_ANGLE_LIMIT = Rotation2d.fromDegrees(200); | ||
|
||
public static final Rotation2d ANGLE_TOLERANCE = Rotation2d.fromRotations(0.05); | ||
|
||
} |
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,17 @@ | ||
package subsystems.wrist; | ||
|
||
import subsystems.wrist.simulationWrist.SimulationWrist; | ||
import subsystems.wrist.talonWrist.TalonWrist; | ||
import training.Robot; | ||
|
||
public class WristFactory { | ||
|
||
public static IWrist create() { | ||
return switch (Robot.ROBOT_TYPE) { | ||
case REAL -> new TalonWrist(); | ||
case SIMULATION -> new SimulationWrist(); | ||
}; | ||
} | ||
|
||
|
||
} |
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,11 @@ | ||
package subsystems.wrist; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
@AutoLog | ||
public class WristInputs { | ||
|
||
public Rotation2d angle; | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/subsystems/wrist/simulationWrist/SimulationWrist.java
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,57 @@ | ||
package subsystems.wrist.simulationWrist; | ||
|
||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim; | ||
import subsystems.GlobalConstants; | ||
import subsystems.elbow.simulationElbow.SimulationElbowConstants; | ||
import subsystems.wrist.IWrist; | ||
import subsystems.wrist.WristConstants; | ||
import subsystems.wrist.WristInputsAutoLogged; | ||
|
||
public class SimulationWrist implements IWrist { | ||
|
||
private final SingleJointedArmSim motor; | ||
|
||
private final PIDController controller; | ||
|
||
public SimulationWrist() { | ||
motor = new SingleJointedArmSim( | ||
DCMotor.getNEO(SimulationWristConstants.NUMBER_OF_MOTORS), | ||
SimulationWristConstants.GEAR_RATIO, | ||
SingleJointedArmSim.estimateMOI(WristConstants.LENGTH_OF_ENDEFFECTOR, WristConstants.WRIST_MASS_KG), | ||
WristConstants.LENGTH_OF_ENDEFFECTOR, | ||
WristConstants.BACKWARD_ANGLE_LIMIT.getRadians(), | ||
WristConstants.FORWARD_ANGLE_LIMIT.getRadians(), | ||
false, | ||
WristConstants.PresetPositions.STARTING.ANGLE.getRadians() | ||
); | ||
|
||
controller = new PIDController(SimulationWristConstants.KP, SimulationWristConstants.KI, SimulationWristConstants.KD); | ||
} | ||
|
||
|
||
@Override | ||
public void setPower(double power) { | ||
setVoltage(power * GlobalConstants.SIMULATION_BATTERY_VOLTAGE); | ||
} | ||
|
||
private void setVoltage(double voltage) { | ||
double limited_voltage = Math | ||
.min((Math.max(voltage, -GlobalConstants.SIMULATION_BATTERY_VOLTAGE)), GlobalConstants.SIMULATION_BATTERY_VOLTAGE); | ||
motor.setInputVoltage(limited_voltage); | ||
} | ||
|
||
@Override | ||
public void updateInputs(WristInputsAutoLogged inputs) { | ||
inputs.angle = Rotation2d.fromRadians(motor.getAngleRads()); | ||
motor.update(SimulationElbowConstants.MOTOR_UPDATE_PERIOD); | ||
} | ||
|
||
@Override | ||
public void goToPosition(Rotation2d position) { | ||
setVoltage(controller.calculate(motor.getAngleRads(), position.getRadians())); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/subsystems/wrist/simulationWrist/SimulationWristConstants.java
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,15 @@ | ||
package subsystems.wrist.simulationWrist; | ||
|
||
public class SimulationWristConstants { | ||
|
||
public static final int NUMBER_OF_MOTORS = 1; | ||
|
||
public static final double GEAR_RATIO = 1; | ||
|
||
public static final double KP = 0.12; | ||
|
||
public static final double KI = 0; | ||
|
||
public static final double KD = 0.025; | ||
|
||
} |
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,35 @@ | ||
package subsystems.wrist.talonWrist; | ||
|
||
import com.ctre.phoenix.motorcontrol.TalonSRXControlMode; | ||
import com.ctre.phoenix.motorcontrol.can.TalonSRX; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import subsystems.wrist.IWrist; | ||
import subsystems.wrist.WristInputsAutoLogged; | ||
|
||
public class TalonWrist implements IWrist { | ||
|
||
private static TalonSRX motor; | ||
|
||
public TalonWrist() { | ||
this.motor = new TalonSRX(TalonWristConstants.MOTOR_ID); | ||
} | ||
|
||
|
||
public void goToPosition(Rotation2d position) { | ||
motor.set( | ||
TalonWristConstants.PID_CONTROL_MODE, | ||
position.getRotations() % 1 * TalonWristConstants.FULL_CIRCLE_ENCODER_TICKS | ||
); | ||
} | ||
|
||
@Override | ||
public void setPower(double power) { | ||
motor.set(TalonSRXControlMode.PercentOutput, power); | ||
} | ||
|
||
@Override | ||
public void updateInputs(WristInputsAutoLogged inputs) { | ||
inputs.angle = Rotation2d.fromRotations(motor.getSelectedSensorPosition()); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/subsystems/wrist/talonWrist/TalonWristConstants.java
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,13 @@ | ||
package subsystems.wrist.talonWrist; | ||
|
||
import com.ctre.phoenix.motorcontrol.TalonSRXControlMode; | ||
|
||
public class TalonWristConstants { | ||
|
||
protected static final int MOTOR_ID = 11; | ||
|
||
protected static final TalonSRXControlMode PID_CONTROL_MODE = TalonSRXControlMode.Position; | ||
|
||
protected static final int FULL_CIRCLE_ENCODER_TICKS = 168; | ||
|
||
} |