WPILibC++ 2024.3.2
DutyCycleEncoderSim.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 <hal/SimDevice.h>
8#include <units/angle.h>
9
10namespace frc {
11
12class DutyCycleEncoder;
13
14namespace sim {
15
16/**
17 * Class to control a simulated duty cycle encoder.
18 */
20 public:
21 /**
22 * Constructs from a DutyCycleEncoder object.
23 *
24 * @param encoder DutyCycleEncoder to simulate
25 */
26 explicit DutyCycleEncoderSim(const DutyCycleEncoder& encoder);
27
28 /**
29 * Constructs from a digital input channel.
30 *
31 * @param channel digital input channel
32 */
33 explicit DutyCycleEncoderSim(int channel);
34
35 /**
36 * Get the position in turns.
37 *
38 * @return The position.
39 */
40 double Get();
41
42 /**
43 * Set the position in turns.
44 *
45 * @param turns The position.
46 */
47 void Set(units::turn_t turns);
48
49 /**
50 * Get the distance.
51 *
52 * @return The distance.
53 */
54
55 double GetDistance();
56
57 /**
58 * Set the distance.
59 *
60 * @param distance The distance.
61 */
62 void SetDistance(double distance);
63
64 /**
65 * Get the absolute position.
66 *
67 * @return The absolute position
68 */
70
71 /**
72 * Set the absolute position.
73 *
74 * @param position The absolute position
75 */
76 void SetAbsolutePosition(double position);
77
78 /**
79 * Get the distance per rotation for this encoder.
80 *
81 * @return The scale factor that will be used to convert rotation to useful
82 * units.
83 */
85
86 /**
87 * Get if the encoder is connected.
88 *
89 * @return true if the encoder is connected.
90 */
92
93 /**
94 * Set if the encoder is connected.
95 *
96 * @param isConnected Whether or not the sensor is connected.
97 */
98 void SetConnected(bool isConnected);
99
100 private:
101 hal::SimDouble m_simPosition;
102 hal::SimDouble m_simDistancePerRotation;
103 hal::SimDouble m_simAbsolutePosition;
104 hal::SimBoolean m_simIsConnected;
105};
106
107} // namespace sim
108} // namespace frc
Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with PWM Output,...
Definition: DutyCycleEncoder.h:28
Class to control a simulated duty cycle encoder.
Definition: DutyCycleEncoderSim.h:19
DutyCycleEncoderSim(int channel)
Constructs from a digital input channel.
double GetDistance()
Get the distance.
void Set(units::turn_t turns)
Set the position in turns.
void SetConnected(bool isConnected)
Set if the encoder is connected.
double Get()
Get the position in turns.
void SetDistance(double distance)
Set the distance.
DutyCycleEncoderSim(const DutyCycleEncoder &encoder)
Constructs from a DutyCycleEncoder object.
void SetAbsolutePosition(double position)
Set the absolute position.
double GetAbsolutePosition()
Get the absolute position.
bool IsConnected()
Get if the encoder is connected.
double GetDistancePerRotation()
Get the distance per rotation for this encoder.
C++ wrapper around a HAL simulator boolean value handle.
Definition: SimDevice.h:608
C++ wrapper around a HAL simulator double value handle.
Definition: SimDevice.h:533
Definition: AprilTagPoseEstimator.h:15