mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Add simple motor simulation classes (#1117)
This commit is contained in:
committed by
Peter Johnson
parent
57fc614074
commit
76c901ce78
@@ -81,6 +81,13 @@ void HALSIM_CancelEncoderSamplesToAverageCallback(int32_t index, int32_t uid);
|
||||
int32_t HALSIM_GetEncoderSamplesToAverage(int32_t index);
|
||||
void HALSIM_SetEncoderSamplesToAverage(int32_t index, int32_t samplesToAverage);
|
||||
|
||||
int32_t HALSIM_RegisterEncoderDistancePerPulseCallback(
|
||||
int32_t index, HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelEncoderDistancePerPulseCallback(int32_t index, int32_t uid);
|
||||
double HALSIM_GetEncoderDistancePerPulse(int32_t index);
|
||||
void HALSIM_SetEncoderDistancePerPulse(int32_t index, double distancePerPulse);
|
||||
|
||||
void HALSIM_RegisterEncoderAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
@@ -123,6 +123,21 @@ class EncoderSim {
|
||||
HALSIM_SetEncoderSamplesToAverage(m_index, samplesToAverage);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterDistancePerPulseCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderDistancePerPulseCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderDistancePerPulseCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
double GetDistancePerPulse() {
|
||||
return HALSIM_GetEncoderDistancePerPulse(m_index);
|
||||
}
|
||||
void SetDistancePerPulse(double distancePerPulse) {
|
||||
HALSIM_SetEncoderDistancePerPulse(m_index, distancePerPulse);
|
||||
}
|
||||
|
||||
void ResetData() { HALSIM_ResetEncoderData(m_index); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -39,7 +39,7 @@ void EncoderData::ResetData() {
|
||||
m_reverseDirectionCallbacks = nullptr;
|
||||
m_samplesToAverage = 0;
|
||||
m_samplesToAverageCallbacks = nullptr;
|
||||
m_distancePerPulse = 0;
|
||||
m_distancePerPulse = 1;
|
||||
m_distancePerPulseCallbacks = nullptr;
|
||||
}
|
||||
|
||||
@@ -544,6 +544,25 @@ void HALSIM_SetEncoderSamplesToAverage(int32_t index,
|
||||
SimEncoderData[index].SetSamplesToAverage(samplesToAverage);
|
||||
}
|
||||
|
||||
int32_t HALSIM_RegisterEncoderDistancePerPulseCallback(
|
||||
int32_t index, HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return SimEncoderData[index].RegisterDistancePerPulseCallback(callback, param,
|
||||
initialNotify);
|
||||
}
|
||||
|
||||
void HALSIM_CancelEncoderDistancePerPulseCallback(int32_t index, int32_t uid) {
|
||||
SimEncoderData[index].CancelDistancePerPulseCallback(uid);
|
||||
}
|
||||
|
||||
double HALSIM_GetEncoderDistancePerPulse(int32_t index) {
|
||||
return SimEncoderData[index].GetDistancePerPulse();
|
||||
}
|
||||
|
||||
void HALSIM_SetEncoderDistancePerPulse(int32_t index, double distancePerPulse) {
|
||||
SimEncoderData[index].SetDistancePerPulse(distancePerPulse);
|
||||
}
|
||||
|
||||
void HALSIM_RegisterEncoderAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {
|
||||
|
||||
@@ -106,7 +106,7 @@ class EncoderData {
|
||||
std::shared_ptr<NotifyListenerVector> m_reverseDirectionCallbacks = nullptr;
|
||||
std::atomic<int32_t> m_samplesToAverage{0};
|
||||
std::shared_ptr<NotifyListenerVector> m_samplesToAverageCallbacks = nullptr;
|
||||
std::atomic<double> m_distancePerPulse{0};
|
||||
std::atomic<double> m_distancePerPulse{1};
|
||||
std::shared_ptr<NotifyListenerVector> m_distancePerPulseCallbacks = nullptr;
|
||||
};
|
||||
extern EncoderData* SimEncoderData;
|
||||
|
||||
Reference in New Issue
Block a user