CTRE Phoenix 6 C++ 26.70.0-alpha-2
Loading...
Searching...
No Matches
Pigeon2.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
10
11#include <wpi/hal/SimDevice.hpp>
12#include <wpi/math/geometry/Rotation2d.hpp>
13#include <wpi/math/geometry/Rotation3d.hpp>
14#include <wpi/telemetry/TelemetryLoggable.hpp>
15
16namespace ctre {
17namespace phoenix6 {
18namespace hardware {
19
20#if defined(_WIN32) || defined(_WIN64)
21#pragma warning(push)
22#pragma warning(disable : 4250)
23#endif
24
25/**
26 * Class description for the Pigeon 2 IMU sensor that measures orientation.
27 */
28class Pigeon2 : public core::CorePigeon2, public wpi::telemetry::TelemetryLoggable {
29 /*
30 * The StatusSignal getters are copies so that calls
31 * to the WPI interface do not update any references
32 *
33 * These are also mutable so the const getter methods are
34 * properly managed.
35 */
36 mutable StatusSignal<wpi::units::degree_t> m_yaw = GetYaw(false);
37 mutable StatusSignal<wpi::units::degree_t> m_pitch = GetPitch(false);
38 mutable StatusSignal<wpi::units::degree_t> m_roll = GetRoll(false);
39 mutable StatusSignal<wpi::units::scalar_t> m_quatW = GetQuatW(false);
40 mutable StatusSignal<wpi::units::scalar_t> m_quatX = GetQuatX(false);
41 mutable StatusSignal<wpi::units::scalar_t> m_quatY = GetQuatY(false);
42 mutable StatusSignal<wpi::units::scalar_t> m_quatZ = GetQuatZ(false);
43
44 wpi::hal::SimDevice m_simPigeon;
45 wpi::hal::SimDouble m_simSupplyVoltage;
46 wpi::hal::SimDouble m_simYaw;
47 wpi::hal::SimDouble m_simRawYaw;
48 wpi::hal::SimDouble m_simPitch;
49 wpi::hal::SimDouble m_simRoll;
50 wpi::hal::SimDouble m_simAngularVelocityX;
51 wpi::hal::SimDouble m_simAngularVelocityY;
52 wpi::hal::SimDouble m_simAngularVelocityZ;
53
54 int32_t m_simPeriodicUid{-1};
55 std::vector<int32_t> m_simValueChangedUids;
56
57 static void OnValueChanged(
58 const char* name, void* param, HAL_SimValueHandle handle,
59 HAL_Bool readonly, const struct HAL_Value* value
60 );
61 static void OnPeriodic(void* param);
62
63public:
64 /**
65 * Constructs a new Pigeon 2 sensor object.
66 *
67 * \param deviceId ID of the device, as configured in Phoenix Tuner
68 * \param canbus The CAN bus this device is on
69 */
70 Pigeon2(int deviceId, CANBus canbus);
71
73
74 /**
75 * \brief Constructs a stubbed-out Pigeon2, where all status signals, controls,
76 * configs, etc. perform no action and immediately return OK. This can be used to
77 * silence error messages for devices that have been completely removed from the robot.
78 *
79 * \returns Stubbed-out Pigeon2
80 */
81 static Pigeon2 None()
82 {
83 return Pigeon2{-1, CANBus{}};
84 }
85
86 /**
87 * \brief Resets the Pigeon 2 to a heading of zero.
88 *
89 * \details This can be used if there is significant drift in the gyro,
90 * and it needs to be recalibrated after it has been running.
91 */
92 void Reset()
93 {
94 SetYaw(0_deg);
95 }
96 /**
97 * \brief Returns the heading of the Pigeon 2 as a wpi#math#Rotation2d.
98 *
99 * The angle increases as the Pigeon 2 turns counterclockwise when
100 * looked at from the top. This follows the NWU axis convention.
101 *
102 * \returns The current heading of the Pigeon 2 as a wpi#math#Rotation2d
103 */
104 wpi::math::Rotation2d GetRotation2d() const
105 {
106 /* Rotation2d and Pigeon2 are both ccw+ */
107 return wpi::math::Rotation2d{m_yaw.Refresh().GetValue()};
108 }
109 /**
110 * \brief Returns the orientation of the Pigeon 2 as a wpi#math#Rotation3d
111 * created from the quaternion signals.
112 *
113 * \returns The current orientation of the Pigeon 2 as a wpi#math#Rotation3d
114 */
115 wpi::math::Rotation3d GetRotation3d() const
116 {
117 return wpi::math::Rotation3d{GetQuaternion()};
118 }
119 /**
120 * \brief Returns the orientation of the Pigeon 2 as a wpi#math#Quaternion.
121 *
122 * \returns The current orientation of the Pigeon 2 as a wpi#math#Quaternion
123 */
124 wpi::math::Quaternion GetQuaternion() const
125 {
126 BaseStatusSignal::RefreshAll(m_quatW, m_quatX, m_quatY, m_quatZ);
127 return wpi::math::Quaternion{m_quatW.GetValue(), m_quatX.GetValue(), m_quatY.GetValue(), m_quatZ.GetValue()};
128 }
129
130 /**
131 * \brief Logs the object to a wpi::telemetry::TelemetryTable.
132 *
133 * \param table Telemetry table
134 */
135 void LogTo(wpi::telemetry::TelemetryTable &table) const override;
136
137 /**
138 * \brief Gets the telemetry table type.
139 *
140 * \returns Table type
141 */
142 std::string_view GetTelemetryType() const override { return "Gyro"; }
143};
144
145#if defined(_WIN32) || defined(_WIN64)
146#pragma warning(pop)
147#endif
148
149}
150}
151}
static ctre::phoenix::StatusCode RefreshAll(Signals &... signals)
Performs a non-blocking refresh on all provided signals.
Definition StatusSignal.hpp:391
Class for getting information about an available CAN bus.
Definition CANBus.hpp:142
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:523
wpi::math::Rotation2d GetRotation2d() const
Returns the heading of the Pigeon 2 as a wpi::math::Rotation2d.
Definition Pigeon2.hpp:104
Pigeon2(int deviceId, CANBus canbus)
Constructs a new Pigeon 2 sensor object.
void Reset()
Resets the Pigeon 2 to a heading of zero.
Definition Pigeon2.hpp:92
std::string_view GetTelemetryType() const override
Gets the telemetry table type.
Definition Pigeon2.hpp:142
wpi::math::Rotation3d GetRotation3d() const
Returns the orientation of the Pigeon 2 as a wpi::math::Rotation3d created from the quaternion signal...
Definition Pigeon2.hpp:115
void LogTo(wpi::telemetry::TelemetryTable &table) const override
Logs the object to a wpi::telemetry::TelemetryTable.
static Pigeon2 None()
Constructs a stubbed-out Pigeon2, where all status signals, controls, configs, etc.
Definition Pigeon2.hpp:81
wpi::math::Quaternion GetQuaternion() const
Returns the orientation of the Pigeon 2 as a wpi::math::Quaternion.
Definition Pigeon2.hpp:124
Class for the Pigeon 2 IMU sensor that measures orientation.
Definition CorePigeon2.hpp:1058
StatusSignal< wpi::units::scalar_t > & GetQuatX(bool refresh=true)
The X component of the reported Quaternion.
StatusSignal< wpi::units::degree_t > & GetRoll(bool refresh=true)
Current reported roll of the Pigeon2.
ctre::phoenix::StatusCode SetYaw(wpi::units::degree_t newValue, wpi::units::second_t timeoutSeconds)
The yaw to set the Pigeon2 to right now.
Definition CorePigeon2.hpp:2449
StatusSignal< wpi::units::scalar_t > & GetQuatW(bool refresh=true)
The W component of the reported Quaternion.
StatusSignal< wpi::units::scalar_t > & GetQuatY(bool refresh=true)
The Y component of the reported Quaternion.
StatusSignal< wpi::units::degree_t > & GetYaw(bool refresh=true)
Current reported yaw of the Pigeon2.
StatusSignal< wpi::units::scalar_t > & GetQuatZ(bool refresh=true)
The Z component of the reported Quaternion.
StatusSignal< wpi::units::degree_t > & GetPitch(bool refresh=true)
Current reported pitch of the Pigeon2.
Definition ExternalFeedbackConfigs.hpp:17
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14