mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[hal, wpilib] PWM Rewrite (#7845)
The HAL will only contain the output period and the raw microseconds. Higher level things such as SimDevice can handle everything else.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
using namespace halsimgui;
|
||||
|
||||
namespace {
|
||||
HALSIMGUI_DATASOURCE_DOUBLE_INDEXED(PWMSpeed, "PWM");
|
||||
HALSIMGUI_DATASOURCE_DOUBLE_INDEXED(PWMPulseMicrosecond, "PWM");
|
||||
|
||||
class PWMSimModel : public glass::PWMModel {
|
||||
public:
|
||||
@@ -33,12 +33,14 @@ class PWMSimModel : public glass::PWMModel {
|
||||
|
||||
glass::DoubleSource* GetSpeedData() override { return &m_speed; }
|
||||
|
||||
void SetSpeed(double val) override { HALSIM_SetPWMSpeed(m_index, val); }
|
||||
void SetSpeed(double val) override {
|
||||
HALSIM_SetPWMPulseMicrosecond(m_index, val);
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t m_index;
|
||||
int m_led = -1;
|
||||
PWMSpeedSource m_speed;
|
||||
PWMPulseMicrosecondSource m_speed;
|
||||
};
|
||||
|
||||
class PWMsSimModel : public glass::PWMsModel {
|
||||
|
||||
@@ -265,11 +265,8 @@ PWMs may be used to control either motor controllers or servos. Typically only
|
||||
| Data Key | Type | Description |
|
||||
| ------------------- | ------- | ------------------------------------------ |
|
||||
| ``"<init"`` | Boolean | If PWM is initialized in the robot program |
|
||||
| ``"<speed"`` | Float | Speed, -1.0 to 1.0 range |
|
||||
| ``"<position"`` | Float | Servo position, 0.0 to 1.0 range |
|
||||
| ``"<raw"`` | Integer | The pulse time in microseconds |
|
||||
| ``"<period_scale"`` | Integer | Scales the PWM signal by squelching setting a 2-bit mask of outputs to squelch (ex. `1` -> squelch every other value; `3` -> squelch 3 of 4 values) |
|
||||
| ``"<zero_latch"`` | Boolean | Whether the PWM should be latched to 0 |
|
||||
| ``"<output_period"``| Integer | Scales the PWM signal by squelching setting a 2-bit mask of outputs to squelch (ex. `1` -> squelch every other value; `3` -> squelch 3 of 4 values) |
|
||||
|
||||
#### Solenoid Output ("Solenoid")
|
||||
|
||||
|
||||
@@ -505,25 +505,12 @@ components:
|
||||
<init:
|
||||
type: boolean
|
||||
description: "If PWM is initialized in the robot program"
|
||||
<speed:
|
||||
type: number
|
||||
description: "Speed"
|
||||
minimum: -1.0
|
||||
maximum: 1.0
|
||||
<position:
|
||||
type: number
|
||||
description: "Servo position"
|
||||
minimum: 0.0
|
||||
maximum: 1.0
|
||||
"<raw":
|
||||
type: integer
|
||||
description: "The pulse time in microseconds"
|
||||
"<period_scale":
|
||||
"<output_period":
|
||||
type: integer
|
||||
description: "Scales the PWM signal by squelching setting a 2-bit mask of outputs to squelch (ex. `1` -> squelch every other value; `3` -> squelch 3 of 4 values)"
|
||||
"<zero_latch":
|
||||
type: boolean
|
||||
description: "Whether the PWM should be latched to 0"
|
||||
|
||||
solenoidData:
|
||||
type: object
|
||||
|
||||
@@ -28,11 +28,8 @@ HALSimWSProviderPWM::~HALSimWSProviderPWM() {
|
||||
|
||||
void HALSimWSProviderPWM::RegisterCallbacks() {
|
||||
m_initCbKey = REGISTER(Initialized, "<init", bool, boolean);
|
||||
m_speedCbKey = REGISTER(Speed, "<speed", double, double);
|
||||
m_positionCbKey = REGISTER(Position, "<position", double, double);
|
||||
m_rawCbKey = REGISTER(PulseMicrosecond, "<raw", int32_t, int);
|
||||
m_periodScaleCbKey = REGISTER(PeriodScale, "<period_scale", int32_t, int);
|
||||
m_zeroLatchCbKey = REGISTER(ZeroLatch, "<zero_latch", bool, boolean);
|
||||
m_outputPeriodCbKey = REGISTER(OutputPeriod, "<output_period", int32_t, int);
|
||||
}
|
||||
|
||||
void HALSimWSProviderPWM::CancelCallbacks() {
|
||||
@@ -41,18 +38,12 @@ void HALSimWSProviderPWM::CancelCallbacks() {
|
||||
|
||||
void HALSimWSProviderPWM::DoCancelCallbacks() {
|
||||
HALSIM_CancelPWMInitializedCallback(m_channel, m_initCbKey);
|
||||
HALSIM_CancelPWMSpeedCallback(m_channel, m_speedCbKey);
|
||||
HALSIM_CancelPWMPositionCallback(m_channel, m_positionCbKey);
|
||||
HALSIM_CancelPWMPulseMicrosecondCallback(m_channel, m_rawCbKey);
|
||||
HALSIM_CancelPWMPeriodScaleCallback(m_channel, m_periodScaleCbKey);
|
||||
HALSIM_CancelPWMZeroLatchCallback(m_channel, m_zeroLatchCbKey);
|
||||
HALSIM_CancelPWMOutputPeriodCallback(m_channel, m_outputPeriodCbKey);
|
||||
|
||||
m_initCbKey = 0;
|
||||
m_speedCbKey = 0;
|
||||
m_positionCbKey = 0;
|
||||
m_rawCbKey = 0;
|
||||
m_periodScaleCbKey = 0;
|
||||
m_zeroLatchCbKey = 0;
|
||||
m_outputPeriodCbKey = 0;
|
||||
}
|
||||
|
||||
} // namespace wpilibws
|
||||
|
||||
@@ -24,11 +24,8 @@ class HALSimWSProviderPWM : public HALSimWSHalChanProvider {
|
||||
|
||||
private:
|
||||
int32_t m_initCbKey = 0;
|
||||
int32_t m_speedCbKey = 0;
|
||||
int32_t m_positionCbKey = 0;
|
||||
int32_t m_rawCbKey = 0;
|
||||
int32_t m_periodScaleCbKey = 0;
|
||||
int32_t m_zeroLatchCbKey = 0;
|
||||
int32_t m_outputPeriodCbKey = 0;
|
||||
};
|
||||
|
||||
} // namespace wpilibws
|
||||
|
||||
Reference in New Issue
Block a user