10 #include "SensorBase.h"
13 #include "PIDSource.h"
14 #include "LiveWindow/LiveWindowSendable.h"
42 enum DistanceUnit { kInches = 0, kMilliMeters = 1 };
45 DistanceUnit units = kInches);
48 DistanceUnit units = kInches);
50 Ultrasonic(std::shared_ptr<DigitalOutput> pingChannel,
51 std::shared_ptr<DigitalInput> echoChannel,
52 DistanceUnit units = kInches);
53 Ultrasonic(uint32_t pingChannel, uint32_t echoChannel,
54 DistanceUnit units = kInches);
62 bool IsEnabled()
const {
return m_enabled; }
63 void SetEnabled(
bool enable) { m_enabled = enable; }
74 void InitTable(std::shared_ptr<ITable> subTable)
override;
75 std::shared_ptr<ITable>
GetTable()
const override;
80 static void UltrasonicChecker();
83 static constexpr
double kPingTime = 10 * 1e-6;
85 static const uint32_t kPriority = 64;
87 static constexpr
double kMaxUltrasonicTime = 0.1;
88 static constexpr
double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0;
91 static std::set<Ultrasonic*> m_sensors;
92 static std::atomic<bool> m_automaticEnabled;
94 std::shared_ptr<DigitalOutput> m_pingChannel;
95 std::shared_ptr<DigitalInput> m_echoChannel;
96 bool m_enabled =
false;
100 std::shared_ptr<ITable> m_table;
std::shared_ptr< ITable > GetTable() const override
Definition: Ultrasonic.cpp:333
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Ultrasonic.cpp:316
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
virtual ~Ultrasonic()
Destructor for the ultrasonic sensor.
Definition: Ultrasonic.cpp:175
Class to write to digital outputs.
Definition: DigitalOutput.h:22
Ultrasonic(DigitalOutput *pingChannel, DigitalInput *echoChannel, DistanceUnit units=kInches)
Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo channel and a DigitalOutp...
Definition: Ultrasonic.cpp:114
static void SetAutomaticMode(bool enabling)
Turn Automatic mode on/off.
Definition: Ultrasonic.cpp:199
std::string GetSmartDashboardType() const override
Definition: Ultrasonic.cpp:326
bool IsRangeValid() const
Check if there is a valid range measurement.
Definition: Ultrasonic.cpp:253
void SetPIDSourceType(PIDSourceType pidSource) override
Set which parameter you are using as a process control variable.
Definition: Ultrasonic.cpp:293
Base class for all sensors.
Definition: SensorBase.h:20
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Ultrasonic.cpp:324
double GetRangeMM() const
Get the range in millimeters from the ultrasonic sensor.
Definition: Ultrasonic.cpp:275
double PIDGet() override
Get the range in the current DistanceUnit for the PIDSource base object.
Definition: Ultrasonic.cpp:282
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:31
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:18
Ultrasonic rangefinder class.
Definition: Ultrasonic.h:38
DistanceUnit GetDistanceUnits() const
Get the current DistanceUnit that is used for the PIDSource base object.
Definition: Ultrasonic.cpp:312
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: Ultrasonic.cpp:328
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Ultrasonic.cpp:322
void Ping()
Single ping to ultrasonic sensor.
Definition: Ultrasonic.cpp:239
void SetDistanceUnits(DistanceUnit units)
Set the current DistanceUnit that should be used for the PIDSource base object.
Definition: Ultrasonic.cpp:305
Wrapper class around std::thread that allows changing thread priority.
Definition: Task.h:19
double GetRangeInches() const
Get the range in inches from the ultrasonic sensor.
Definition: Ultrasonic.cpp:261