10 #include "SensorBase.h"
11 #include "LiveWindow/LiveWindowSendable.h"
12 #include "tables/ITableListener.h"
38 enum PeriodMultiplier {
39 kPeriodMultiplier_1X = 1,
40 kPeriodMultiplier_2X = 2,
41 kPeriodMultiplier_4X = 4
44 explicit PWM(uint32_t channel);
46 virtual void SetRaw(
unsigned short value);
47 virtual unsigned short GetRaw()
const;
51 void SetBounds(int32_t max, int32_t deadbandMax, int32_t center,
52 int32_t deadbandMin, int32_t min);
53 void SetBounds(
double max,
double deadbandMax,
double center,
54 double deadbandMin,
double min);
55 uint32_t GetChannel()
const {
return m_channel; }
89 static const int32_t kPwmDisabled = 0;
96 bool m_eliminateDeadband;
98 int32_t m_deadbandMaxPwm;
100 int32_t m_deadbandMinPwm;
104 std::shared_ptr<nt::Value> value,
bool isNew)
override;
109 void InitTable(std::shared_ptr<ITable> subTable)
override;
110 std::shared_ptr<ITable>
GetTable()
const override;
112 std::shared_ptr<ITable> m_table;
116 int32_t GetMaxPositivePwm()
const {
return m_maxPwm; }
117 int32_t GetMinPositivePwm()
const {
118 return m_eliminateDeadband ? m_deadbandMaxPwm : m_centerPwm + 1;
120 int32_t GetCenterPwm()
const {
return m_centerPwm; }
121 int32_t GetMaxNegativePwm()
const {
122 return m_eliminateDeadband ? m_deadbandMinPwm : m_centerPwm - 1;
124 int32_t GetMinNegativePwm()
const {
return m_minPwm; }
125 int32_t GetPositiveScaleFactor()
const {
126 return GetMaxPositivePwm() - GetMinPositivePwm();
128 int32_t GetNegativeScaleFactor()
const {
129 return GetMaxNegativePwm() - GetMinNegativePwm();
131 int32_t GetFullRangeScaleFactor()
const {
132 return GetMaxPositivePwm() - GetMinNegativePwm();
A table whose values can be read and written to.
Definition: ITable.h:43
static const int32_t kDefaultPwmStepsDown
kDefaultPWMStepsDown is the number of PWM steps below the centerpoint
Definition: PWM.h:88
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
Class implements the PWM generation in the FPGA.
Definition: PWM.h:34
virtual float GetPosition() const
Get the PWM value in terms of a position.
Definition: PWM.cpp:182
PWM(uint32_t channel)
Allocate a PWM given a channel number.
Definition: PWM.cpp:31
Base class for all sensors.
Definition: SensorBase.h:20
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: PWM.cpp:369
static constexpr float kDefaultPwmCenter
kDefaultPwmCenter is the PWM range center in ms
Definition: PWM.h:84
virtual ~PWM()
Free the PWM channel.
Definition: PWM.cpp:59
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: PWM.cpp:347
virtual void SetPosition(float pos)
Set the PWM value based on a position.
Definition: PWM.cpp:148
virtual float GetSpeed() const
Get the PWM value in terms of speed.
Definition: PWM.cpp:250
std::string GetSmartDashboardType() const override
Definition: PWM.cpp:367
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: PWM.cpp:360
virtual unsigned short GetRaw() const
Get the PWM value directly from the hardware.
Definition: PWM.cpp:292
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: PWM.cpp:353
A listener that listens to changes in values in a ITable.
Definition: ITableListener.h:18
virtual void SetRaw(unsigned short value)
Set the PWM value directly to the hardware.
Definition: PWM.cpp:277
void SetBounds(int32_t max, int32_t deadbandMax, int32_t center, int32_t deadbandMin, int32_t min)
Set the bounds on the PWM values.
Definition: PWM.cpp:95
static constexpr float kDefaultPwmPeriod
kDefaultPwmPeriod is in ms
Definition: PWM.h:80
void ValueChanged(ITable *source, llvm::StringRef key, std::shared_ptr< nt::Value > value, bool isNew) override
Called when a key-value pair is changed in a ITable.
Definition: PWM.cpp:341
void EnableDeadbandElimination(bool eliminateDeadband)
Optionally eliminate the deadband from a speed controller.
Definition: PWM.cpp:79
virtual void SetSpeed(float speed)
Set the PWM value based on a speed.
Definition: PWM.cpp:208
void SetPeriodMultiplier(PeriodMultiplier mult)
Slow down the PWM signal for old devices.
Definition: PWM.cpp:307
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39
std::shared_ptr< ITable > GetTable() const override
Definition: PWM.cpp:374