mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Remove PWM.Period enum
Replace it with just numeric values.
This commit is contained in:
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
{{ name }}::{{ name }}(int channel) : PWMMotorController("{{ name }}", channel) {
|
||||
SetBounds({{ pulse_width_ms.max }}_ms, {{ pulse_width_ms.deadbandMax }}_ms, {{ pulse_width_ms.center }}_ms, {{ pulse_width_ms.deadbandMin }}_ms, {{ pulse_width_ms.min }}_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_{{ OutputPeriod | default("5", true)}}Ms);
|
||||
m_pwm.SetOutputPeriod({{ OutputPeriod | default("5", true)}}_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "{{ ResourceName }}");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
Koors40::Koors40(int channel) : PWMMotorController("Koors40", channel) {
|
||||
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_20Ms);
|
||||
m_pwm.SetOutputPeriod(20_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "Koors40");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
PWMSparkFlex::PWMSparkFlex(int channel) : PWMMotorController("PWMSparkFlex", channel) {
|
||||
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "RevSparkFlexPWM");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
PWMSparkMax::PWMSparkMax(int channel) : PWMMotorController("PWMSparkMax", channel) {
|
||||
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "RevSparkMaxPWM");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
PWMTalonFX::PWMTalonFX(int channel) : PWMMotorController("PWMTalonFX", channel) {
|
||||
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "TalonFX");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
PWMTalonSRX::PWMTalonSRX(int channel) : PWMMotorController("PWMTalonSRX", channel) {
|
||||
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "PWMTalonSRX");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
PWMVenom::PWMVenom(int channel) : PWMMotorController("PWMVenom", channel) {
|
||||
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "FusionVenom");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
PWMVictorSPX::PWMVictorSPX(int channel) : PWMMotorController("PWMVictorSPX", channel) {
|
||||
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "PWMVictorSPX");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
Spark::Spark(int channel) : PWMMotorController("Spark", channel) {
|
||||
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "RevSPARK");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
SparkMini::SparkMini(int channel) : PWMMotorController("SparkMini", channel) {
|
||||
SetBounds(2.5_ms, 1.51_ms, 1.5_ms, 1.49_ms, 0.5_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "RevSPARK");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
Talon::Talon(int channel) : PWMMotorController("Talon", channel) {
|
||||
SetBounds(2.037_ms, 1.539_ms, 1.513_ms, 1.487_ms, 0.989_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "Talon");
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace wpi;
|
||||
|
||||
VictorSP::VictorSP(int channel) : PWMMotorController("VictorSP", channel) {
|
||||
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
|
||||
m_pwm.SetOutputPeriod(PWM::kOutputPeriod_5Ms);
|
||||
m_pwm.SetOutputPeriod(5_ms);
|
||||
SetDutyCycle(0.0);
|
||||
|
||||
HAL_ReportUsage("IO", GetChannel(), "VictorSP");
|
||||
|
||||
@@ -60,25 +60,23 @@ void PWM::SetDisabled() {
|
||||
WPILIB_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::SetOutputPeriod(OutputPeriod mult) {
|
||||
void PWM::SetOutputPeriod(wpi::units::millisecond_t period) {
|
||||
int32_t status = 0;
|
||||
|
||||
switch (mult) {
|
||||
case kOutputPeriod_20Ms:
|
||||
HAL_SetPWMOutputPeriod(m_handle, 3,
|
||||
&status); // Squelch 3 out of 4 outputs
|
||||
switch (static_cast<int>(period.value())) {
|
||||
case 5:
|
||||
// Don't squelch any outputs
|
||||
HAL_SetPWMOutputPeriod(m_handle, 0, &status);
|
||||
break;
|
||||
case kOutputPeriod_10Ms:
|
||||
HAL_SetPWMOutputPeriod(m_handle, 1,
|
||||
&status); // Squelch 1 out of 2 outputs
|
||||
case 10:
|
||||
// Squelch 1 out of 2 outputs
|
||||
HAL_SetPWMOutputPeriod(m_handle, 1, &status);
|
||||
break;
|
||||
case kOutputPeriod_5Ms:
|
||||
HAL_SetPWMOutputPeriod(m_handle, 0,
|
||||
&status); // Don't squelch any outputs
|
||||
case 20:
|
||||
default: // default to 20ms if invalid value is given
|
||||
// Squelch 3 out of 4 outputs
|
||||
HAL_SetPWMOutputPeriod(m_handle, 3, &status);
|
||||
break;
|
||||
default:
|
||||
throw WPILIB_MakeError(err::InvalidParameter, "OutputPeriod value {}",
|
||||
static_cast<int>(mult));
|
||||
}
|
||||
|
||||
WPILIB_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
@@ -26,23 +26,6 @@ class AddressableLED;
|
||||
class PWM : public wpi::util::Sendable, public wpi::util::SendableHelper<PWM> {
|
||||
public:
|
||||
friend class AddressableLED;
|
||||
/**
|
||||
* Represents the output period in microseconds.
|
||||
*/
|
||||
enum OutputPeriod {
|
||||
/**
|
||||
* PWM pulses occur every 5 ms
|
||||
*/
|
||||
kOutputPeriod_5Ms = 1,
|
||||
/**
|
||||
* PWM pulses occur every 10 ms
|
||||
*/
|
||||
kOutputPeriod_10Ms = 2,
|
||||
/**
|
||||
* PWM pulses occur every 20 ms
|
||||
*/
|
||||
kOutputPeriod_20Ms = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocate a PWM given a channel number.
|
||||
@@ -71,7 +54,7 @@ class PWM : public wpi::util::Sendable, public wpi::util::SendableHelper<PWM> {
|
||||
*
|
||||
* Write a microsecond value to a PWM channel.
|
||||
*
|
||||
* @param time Microsecond PWM value.
|
||||
* @param time Microsecond PWM value. Range 0 - 4096.
|
||||
*/
|
||||
void SetPulseTime(wpi::units::microsecond_t time);
|
||||
|
||||
@@ -80,7 +63,7 @@ class PWM : public wpi::util::Sendable, public wpi::util::SendableHelper<PWM> {
|
||||
*
|
||||
* Read a microsecond value from a PWM channel.
|
||||
*
|
||||
* @return Microsecond PWM control value.
|
||||
* @return Microsecond PWM control value. Range 0 - 4096.
|
||||
*/
|
||||
wpi::units::microsecond_t GetPulseTime() const;
|
||||
|
||||
@@ -93,9 +76,10 @@ class PWM : public wpi::util::Sendable, public wpi::util::SendableHelper<PWM> {
|
||||
/**
|
||||
* Sets the PWM output period.
|
||||
*
|
||||
* @param mult The output period to apply to this channel
|
||||
* @param period The output period to apply to this channel, in milliseconds.
|
||||
* Valid values are 5ms, 10ms, and 20ms. Default is 20 ms.
|
||||
*/
|
||||
void SetOutputPeriod(OutputPeriod mult);
|
||||
void SetOutputPeriod(wpi::units::millisecond_t period);
|
||||
|
||||
int GetChannel() const;
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ classes:
|
||||
wpi::PWM:
|
||||
ignored_bases:
|
||||
- wpi::util::SendableHelper<PWM>
|
||||
enums:
|
||||
OutputPeriod:
|
||||
methods:
|
||||
PWM:
|
||||
SetPulseTime:
|
||||
|
||||
Reference in New Issue
Block a user