WPILibC++ 2025.0.0-alpha-1-9-ga2beb75
AnalogGyroSim.h
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
7#include <memory>
8
10
11namespace frc {
12
13class AnalogGyro;
14
15namespace sim {
16
17/**
18 * Class to control a simulated analog gyro.
19 */
21 public:
22 /**
23 * Constructs from an AnalogGyro object.
24 *
25 * @param gyro AnalogGyro to simulate
26 */
27 explicit AnalogGyroSim(const AnalogGyro& gyro);
28
29 /**
30 * Constructs from an analog input channel number.
31 *
32 * @param channel Channel number
33 */
34 explicit AnalogGyroSim(int channel);
35
36 /**
37 * Register a callback on the angle.
38 *
39 * @param callback the callback that will be called whenever the angle changes
40 * @param initialNotify if true, the callback will be run on the initial value
41 * @return the CallbackStore object associated with this callback
42 */
43 [[nodiscard]]
44 std::unique_ptr<CallbackStore> RegisterAngleCallback(NotifyCallback callback,
45 bool initialNotify);
46
47 /**
48 * Get the current angle of the gyro.
49 *
50 * @return the angle measured by the gyro
51 */
52 double GetAngle() const;
53
54 /**
55 * Change the angle measured by the gyro.
56 *
57 * @param angle the new value
58 */
59 void SetAngle(double angle);
60
61 /**
62 * Register a callback on the rate.
63 *
64 * @param callback the callback that will be called whenever the rate changes
65 * @param initialNotify if true, the callback will be run on the initial value
66 * @return the CallbackStore object associated with this callback
67 */
68 [[nodiscard]]
69 std::unique_ptr<CallbackStore> RegisterRateCallback(NotifyCallback callback,
70 bool initialNotify);
71
72 /**
73 * Get the rate of angle change on this gyro.
74 *
75 * @return the rate
76 */
77 double GetRate() const;
78
79 /**
80 * Change the rate of the gyro.
81 *
82 * @param rate the new rate
83 */
84 void SetRate(double rate);
85
86 /**
87 * Register a callback on whether the gyro is initialized.
88 *
89 * @param callback the callback that will be called whenever the gyro is
90 * initialized
91 * @param initialNotify if true, the callback will be run on the initial value
92 * @return the CallbackStore object associated with this callback
93 */
94 [[nodiscard]]
95 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
96 NotifyCallback callback, bool initialNotify);
97
98 /**
99 * Check if the gyro is initialized.
100 *
101 * @return true if initialized
102 */
103 bool GetInitialized() const;
104
105 /**
106 * Set whether this gyro is initialized.
107 *
108 * @param initialized the new value
109 */
110 void SetInitialized(bool initialized);
111
112 /**
113 * Reset all simulation data for this object.
114 */
115 void ResetData();
116
117 private:
118 int m_index;
119};
120} // namespace sim
121} // namespace frc
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:33
Class to control a simulated analog gyro.
Definition: AnalogGyroSim.h:20
bool GetInitialized() const
Check if the gyro is initialized.
void SetInitialized(bool initialized)
Set whether this gyro is initialized.
void SetRate(double rate)
Change the rate of the gyro.
void SetAngle(double angle)
Change the angle measured by the gyro.
void ResetData()
Reset all simulation data for this object.
double GetAngle() const
Get the current angle of the gyro.
std::unique_ptr< CallbackStore > RegisterRateCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the rate.
double GetRate() const
Get the rate of angle change on this gyro.
AnalogGyroSim(const AnalogGyro &gyro)
Constructs from an AnalogGyro object.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the gyro is initialized.
AnalogGyroSim(int channel)
Constructs from an analog input channel number.
std::unique_ptr< CallbackStore > RegisterAngleCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the angle.
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagDetector_cv.h:11