WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
XRPGyro.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
9#include "wpi/units/angle.hpp"
10#include "wpi/units/angular_velocity.hpp"
11
12namespace wpi::xrp {
13
14/**
15 * @ingroup xrp_api
16 * @{
17 */
18
19/**
20 * Use a rate gyro to return the robots heading relative to a starting position.
21 *
22 * This class is for the XRP onboard gyro, and will only work in
23 * simulation/XRP mode. Only one instance of a XRPGyro is supported.
24 */
25class XRPGyro {
26 public:
27 /**
28 * Constructs an XRPGyro.
29 *
30 * <p>Only one instance of a XRPGyro is supported.
31 */
33
34 /**
35 * Return the actual angle in radians that the robot is currently facing.
36 *
37 * The angle is based on integration of the returned rate form the gyro.
38 * The angle is continuous, that is, it will continue from 2π->2.1π.
39 * This allows algorithms that wouldn't want to see a discontinuity in the
40 * gyro output as it sweeps from 2π to 0 radians on the second time around.
41 *
42 * @return the current heading of the robot in radians.
43 */
44 wpi::units::radian_t GetAngle() const;
45
46 /**
47 * Gets the angle the robot is facing.
48 *
49 * @return A wpi::math::Rotation2d with the current heading.
50 */
52
53 /**
54 * Return the rate of rotation of the gyro
55 *
56 * The rate is based on the most recent reading of the gyro.
57 *
58 * @return the current rate in radians per second
59 */
60 wpi::units::radians_per_second_t GetRate() const;
61
62 /**
63 * Gets the rate of turn in radians-per-second around the X-axis.
64 *
65 * @return rate of turn in radians-per-second
66 */
67 wpi::units::radians_per_second_t GetRateX() const;
68
69 /**
70 * Gets the rate of turn in radians-per-second around the Y-axis.
71 *
72 * @return rate of turn in radians-per-second
73 */
74 wpi::units::radians_per_second_t GetRateY() const;
75
76 /**
77 * Gets the rate of turn in radians-per-second around the Z-axis.
78 *
79 * @return rate of turn in radians-per-second
80 */
81 wpi::units::radians_per_second_t GetRateZ() const;
82
83 /**
84 * Gets the currently reported angle around the X-axis.
85 *
86 * @return current angle around X-axis in radians
87 */
88 wpi::units::radian_t GetAngleX() const;
89
90 /**
91 * Gets the currently reported angle around the Y-axis.
92 *
93 * @return current angle around Y-axis in radians
94 */
95 wpi::units::radian_t GetAngleY() const;
96
97 /**
98 * Gets the currently reported angle around the Z-axis.
99 *
100 * @return current angle around Z-axis in radians
101 */
102 wpi::units::radian_t GetAngleZ() const;
103
104 /**
105 * Reset the gyro angles to 0.
106 */
107 void Reset();
108
109 private:
110 hal::SimDevice m_simDevice;
111 hal::SimDouble m_simRateX;
112 hal::SimDouble m_simRateY;
113 hal::SimDouble m_simRateZ;
114 hal::SimDouble m_simAngleX;
115 hal::SimDouble m_simAngleY;
116 hal::SimDouble m_simAngleZ;
117
118 wpi::units::radian_t m_angleXOffset = 0_rad;
119 wpi::units::radian_t m_angleYOffset = 0_rad;
120 wpi::units::radian_t m_angleZOffset = 0_rad;
121};
122
123/** @} */
124
125} // namespace wpi::xrp
A move-only C++ wrapper around a HAL simulator device handle.
Definition SimDevice.hpp:278
C++ wrapper around a HAL simulator double value handle.
Definition SimDevice.hpp:169
A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
Definition Rotation2d.hpp:26
wpi::units::radians_per_second_t GetRateZ() const
Gets the rate of turn in radians-per-second around the Z-axis.
wpi::units::radians_per_second_t GetRateY() const
Gets the rate of turn in radians-per-second around the Y-axis.
wpi::units::radian_t GetAngleY() const
Gets the currently reported angle around the Y-axis.
void Reset()
Reset the gyro angles to 0.
wpi::units::radians_per_second_t GetRateX() const
Gets the rate of turn in radians-per-second around the X-axis.
wpi::units::radian_t GetAngleX() const
Gets the currently reported angle around the X-axis.
wpi::units::radian_t GetAngle() const
Return the actual angle in radians that the robot is currently facing.
wpi::units::radian_t GetAngleZ() const
Gets the currently reported angle around the Z-axis.
wpi::math::Rotation2d GetRotation2d() const
Gets the angle the robot is facing.
wpi::units::radians_per_second_t GetRate() const
Return the rate of rotation of the gyro.
XRPGyro()
Constructs an XRPGyro.
Definition XRPOnBoardIO.hpp:13