|
23 | 23 | import com.ctre.phoenix6.hardware.Pigeon2; |
24 | 24 |
|
25 | 25 | import edu.wpi.first.math.geometry.Rotation2d; |
26 | | -import edu.wpi.first.math.util.Units; |
27 | 26 | import edu.wpi.first.units.measure.Angle; |
28 | | -import edu.wpi.first.units.measure.AngularVelocity; |
29 | 27 |
|
30 | 28 | /** IO implementation for Pigeon 2. */ |
31 | 29 | public class GyroIOPigeon2 implements GyroIO { |
32 | 30 | private final Pigeon2 pigeon; |
33 | 31 | private final Queue<Double> yawPositionQueue; |
34 | 32 | private final Queue<Double> yawTimestampQueue; |
35 | 33 | private final StatusSignal<Angle> yaw; |
36 | | - private final StatusSignal<AngularVelocity> yawVelocity; |
37 | 34 |
|
38 | 35 | public GyroIOPigeon2(int Pigeon2Id, CANBus bus) { |
39 | 36 |
|
40 | 37 | // Init Pigeon and Statuses |
41 | 38 | pigeon = new Pigeon2(Pigeon2Id, bus); |
42 | 39 | yaw = pigeon.getYaw(); |
43 | | - yawVelocity = pigeon.getAngularVelocityZWorld(); |
44 | 40 |
|
45 | 41 | pigeon.getConfigurator().apply(new Pigeon2Configuration()); |
46 | 42 | pigeon.getConfigurator().setYaw(0.0); |
47 | 43 | yaw.setUpdateFrequency(Drive.ODOMETRY_FREQUENCY); |
48 | | - yawVelocity.setUpdateFrequency(50.0); |
49 | 44 | pigeon.optimizeBusUtilization(); |
50 | 45 | yawTimestampQueue = PhoenixOdometryThread.getInstance().makeTimestampQueue(); |
51 | | - yawPositionQueue = PhoenixOdometryThread.getInstance().registerSignal(pigeon.getYaw()); |
| 46 | + yawPositionQueue = PhoenixOdometryThread.getInstance().registerSignal(yaw.clone()); |
52 | 47 | } |
53 | 48 |
|
54 | 49 | @Override |
55 | 50 | public void updateInputs(GyroIOInputs inputs) { |
56 | | - inputs.connected = BaseStatusSignal.refreshAll(yaw, yawVelocity).equals(StatusCode.OK); |
| 51 | + inputs.connected = BaseStatusSignal.refreshAll(yaw).equals(StatusCode.OK); |
57 | 52 | inputs.yawPosition = Rotation2d.fromDegrees(yaw.getValueAsDouble()); |
58 | | - inputs.yawVelocityRadPerSec = Units.degreesToRadians(yawVelocity.getValueAsDouble()); |
59 | 53 |
|
60 | 54 | inputs.odometryYawTimestamps = |
61 | 55 | yawTimestampQueue.stream().mapToDouble((Double value) -> value).toArray(); |
|
0 commit comments