15 #include <hal/SimDevice.h>
17 #include "frc/Counter.h"
18 #include "frc/ErrorBase.h"
19 #include "frc/PIDSource.h"
20 #include "frc/smartdashboard/Sendable.h"
21 #include "frc/smartdashboard/SendableHelper.h"
45 enum DistanceUnit { kInches = 0, kMilliMeters = 1 };
59 Ultrasonic(
int pingChannel,
int echoChannel, DistanceUnit units = kInches);
72 DistanceUnit units = kInches);
85 DistanceUnit units = kInches);
97 Ultrasonic(std::shared_ptr<DigitalOutput> pingChannel,
98 std::shared_ptr<DigitalInput> echoChannel,
99 DistanceUnit units = kInches);
158 bool IsEnabled()
const;
160 void SetEnabled(
bool enable);
209 static void UltrasonicChecker();
212 static constexpr
double kPingTime = 10 * 1e-6;
215 static constexpr
int kPriority = 64;
218 static constexpr
double kMaxUltrasonicTime = 0.1;
219 static constexpr
double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0;
222 static std::thread m_thread;
225 static std::vector<Ultrasonic*> m_sensors;
228 static std::atomic<bool> m_automaticEnabled;
230 std::shared_ptr<DigitalOutput> m_pingChannel;
231 std::shared_ptr<DigitalInput> m_echoChannel;
232 bool m_enabled =
false;
234 DistanceUnit m_units;
236 hal::SimDevice m_simDevice;
237 hal::SimBoolean m_simRangeValid;
238 hal::SimDouble m_simRange;
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
void Ping()
Single ping to ultrasonic sensor.
Class to write to digital outputs.
Definition: DigitalOutput.h:27
double GetRangeMM() const
Get the range in millimeters from the ultrasonic sensor.
Ultrasonic rangefinder class.
Definition: Ultrasonic.h:40
void SetDistanceUnits(DistanceUnit units)
Set the current DistanceUnit that should be used for the PIDSource base object.
double GetRangeInches() const
Get the range in inches from the ultrasonic sensor.
Ultrasonic(int pingChannel, int echoChannel, DistanceUnit units=kInches)
Create an instance of the Ultrasonic Sensor.
static void SetAutomaticMode(bool enabling)
Turn Automatic mode on/off.
Base class for most objects.
Definition: ErrorBase.h:104
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
bool IsRangeValid() const
Check if there is a valid range measurement.
Interface for Sendable objects.
Definition: Sendable.h:17
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:37
double PIDGet() override
Get the range in the current DistanceUnit for the PIDSource base object.
DistanceUnit GetDistanceUnits() const
Get the current DistanceUnit that is used for the PIDSource base object.
void SetPIDSourceType(PIDSourceType pidSource) override
Set which parameter you are using as a process control variable.
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
Definition: SendableBuilder.h:23