mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal] Add a unified PCM object (#3331)
This commit is contained in:
139
wpilibc/src/main/native/cpp/simulation/CTREPCMSim.cpp
Normal file
139
wpilibc/src/main/native/cpp/simulation/CTREPCMSim.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/simulation/CTREPCMSim.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/CTREPCMData.h>
|
||||
|
||||
#include "frc/SensorUtil.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
CTREPCMSim::CTREPCMSim() : m_index{SensorUtil::GetDefaultCTREPCMModule()} {}
|
||||
|
||||
CTREPCMSim::CTREPCMSim(int module) : m_index{module} {}
|
||||
|
||||
CTREPCMSim::CTREPCMSim(const PneumaticsBase& pneumatics)
|
||||
: m_index{pneumatics.GetModuleNumber()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelCTREPCMInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterCTREPCMInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool CTREPCMSim::GetInitialized() const {
|
||||
return HALSIM_GetCTREPCMInitialized(m_index);
|
||||
}
|
||||
|
||||
void CTREPCMSim::SetInitialized(bool solenoidInitialized) {
|
||||
HALSIM_SetCTREPCMInitialized(m_index, solenoidInitialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterSolenoidOutputCallback(
|
||||
int channel, NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, channel, -1, callback,
|
||||
&HALSIM_CancelCTREPCMSolenoidOutputCallback);
|
||||
store->SetUid(HALSIM_RegisterCTREPCMSolenoidOutputCallback(
|
||||
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool CTREPCMSim::GetSolenoidOutput(int channel) const {
|
||||
return HALSIM_GetCTREPCMSolenoidOutput(m_index, channel);
|
||||
}
|
||||
|
||||
void CTREPCMSim::SetSolenoidOutput(int channel, bool solenoidOutput) {
|
||||
HALSIM_SetCTREPCMSolenoidOutput(m_index, channel, solenoidOutput);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterCompressorOnCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelCTREPCMCompressorOnCallback);
|
||||
store->SetUid(HALSIM_RegisterCTREPCMCompressorOnCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool CTREPCMSim::GetCompressorOn() const {
|
||||
return HALSIM_GetCTREPCMCompressorOn(m_index);
|
||||
}
|
||||
|
||||
void CTREPCMSim::SetCompressorOn(bool compressorOn) {
|
||||
HALSIM_SetCTREPCMCompressorOn(m_index, compressorOn);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterClosedLoopEnabledCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelCTREPCMClosedLoopEnabledCallback);
|
||||
store->SetUid(HALSIM_RegisterCTREPCMClosedLoopEnabledCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool CTREPCMSim::GetClosedLoopEnabled() const {
|
||||
return HALSIM_GetCTREPCMClosedLoopEnabled(m_index);
|
||||
}
|
||||
|
||||
void CTREPCMSim::SetClosedLoopEnabled(bool closedLoopEnabled) {
|
||||
HALSIM_SetCTREPCMClosedLoopEnabled(m_index, closedLoopEnabled);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterPressureSwitchCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelCTREPCMPressureSwitchCallback);
|
||||
store->SetUid(HALSIM_RegisterCTREPCMPressureSwitchCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool CTREPCMSim::GetPressureSwitch() const {
|
||||
return HALSIM_GetCTREPCMPressureSwitch(m_index);
|
||||
}
|
||||
|
||||
void CTREPCMSim::SetPressureSwitch(bool pressureSwitch) {
|
||||
HALSIM_SetCTREPCMPressureSwitch(m_index, pressureSwitch);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterCompressorCurrentCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelCTREPCMCompressorCurrentCallback);
|
||||
store->SetUid(HALSIM_RegisterCTREPCMCompressorCurrentCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double CTREPCMSim::GetCompressorCurrent() const {
|
||||
return HALSIM_GetCTREPCMCompressorCurrent(m_index);
|
||||
}
|
||||
|
||||
void CTREPCMSim::SetCompressorCurrent(double compressorCurrent) {
|
||||
HALSIM_SetCTREPCMCompressorCurrent(m_index, compressorCurrent);
|
||||
}
|
||||
|
||||
uint8_t CTREPCMSim::GetAllSolenoidOutputs() const {
|
||||
uint8_t ret = 0;
|
||||
HALSIM_GetCTREPCMAllSolenoids(m_index, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CTREPCMSim::SetAllSolenoidOutputs(uint8_t outputs) {
|
||||
HALSIM_SetCTREPCMAllSolenoids(m_index, outputs);
|
||||
}
|
||||
|
||||
void CTREPCMSim::ResetData() {
|
||||
HALSIM_ResetCTREPCMData(m_index);
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/simulation/DoubleSolenoidSim.h"
|
||||
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
DoubleSolenoidSim::DoubleSolenoidSim(int fwd, int rev)
|
||||
: m_fwd{fwd}, m_rev{rev} {}
|
||||
|
||||
DoubleSolenoidSim::DoubleSolenoidSim(int module, int fwd, int rev)
|
||||
: m_pcm{module}, m_fwd{fwd}, m_rev{rev} {}
|
||||
|
||||
DoubleSolenoidSim::DoubleSolenoidSim(PCMSim& pcm, int fwd, int rev)
|
||||
: m_pcm{pcm}, m_fwd{fwd}, m_rev{rev} {}
|
||||
|
||||
DoubleSolenoidSim::DoubleSolenoidSim(DoubleSolenoid& solenoid)
|
||||
: m_pcm{solenoid.GetModuleNumber()},
|
||||
m_fwd{solenoid.GetFwdChannel()},
|
||||
m_rev{solenoid.GetRevChannel()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
DoubleSolenoidSim::RegisterFwdInitializedCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
return m_pcm.RegisterSolenoidInitializedCallback(m_fwd, callback,
|
||||
initialNotify);
|
||||
}
|
||||
|
||||
bool DoubleSolenoidSim::GetFwdInitialized() const {
|
||||
return m_pcm.GetSolenoidInitialized(m_fwd);
|
||||
}
|
||||
|
||||
void DoubleSolenoidSim::SetFwdInitialized(bool initialized) {
|
||||
m_pcm.SetSolenoidInitialized(m_fwd, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
DoubleSolenoidSim::RegisterRevInitializedCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
return m_pcm.RegisterSolenoidInitializedCallback(m_rev, callback,
|
||||
initialNotify);
|
||||
}
|
||||
|
||||
bool DoubleSolenoidSim::GetRevInitialized() const {
|
||||
return m_pcm.GetSolenoidInitialized(m_rev);
|
||||
}
|
||||
|
||||
void DoubleSolenoidSim::SetRevInitialized(bool initialized) {
|
||||
m_pcm.SetSolenoidInitialized(m_rev, initialized);
|
||||
}
|
||||
|
||||
void DoubleSolenoidSim::Set(DoubleSolenoid::Value value) {
|
||||
bool forward = false;
|
||||
bool reverse = false;
|
||||
|
||||
switch (value) {
|
||||
case DoubleSolenoid::Value::kOff:
|
||||
forward = false;
|
||||
reverse = false;
|
||||
break;
|
||||
case DoubleSolenoid::Value::kForward:
|
||||
forward = true;
|
||||
reverse = false;
|
||||
break;
|
||||
case DoubleSolenoid::Value::kReverse:
|
||||
forward = false;
|
||||
reverse = true;
|
||||
break;
|
||||
}
|
||||
|
||||
m_pcm.SetSolenoidOutput(m_fwd, forward);
|
||||
m_pcm.SetSolenoidOutput(m_rev, reverse);
|
||||
}
|
||||
|
||||
DoubleSolenoid::Value DoubleSolenoidSim::Get() const {
|
||||
bool valueForward = m_pcm.GetSolenoidOutput(m_fwd);
|
||||
bool valueReverse = m_pcm.GetSolenoidOutput(m_rev);
|
||||
|
||||
if (valueForward) {
|
||||
return DoubleSolenoid::Value::kForward;
|
||||
} else if (valueReverse) {
|
||||
return DoubleSolenoid::Value::kReverse;
|
||||
} else {
|
||||
return DoubleSolenoid::Value::kOff;
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/PCMData.h>
|
||||
|
||||
#include "frc/Compressor.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
PCMSim::PCMSim() : m_index{SensorUtil::GetDefaultSolenoidModule()} {}
|
||||
|
||||
PCMSim::PCMSim(int module) : m_index{module} {}
|
||||
|
||||
PCMSim::PCMSim(const Compressor& compressor)
|
||||
: m_index{compressor.GetModule()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> PCMSim::RegisterSolenoidInitializedCallback(
|
||||
int channel, NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, channel, -1, callback,
|
||||
&HALSIM_CancelPCMSolenoidInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterPCMSolenoidInitializedCallback(
|
||||
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PCMSim::GetSolenoidInitialized(int channel) const {
|
||||
return HALSIM_GetPCMSolenoidInitialized(m_index, channel);
|
||||
}
|
||||
|
||||
void PCMSim::SetSolenoidInitialized(int channel, bool solenoidInitialized) {
|
||||
HALSIM_SetPCMSolenoidInitialized(m_index, channel, solenoidInitialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PCMSim::RegisterSolenoidOutputCallback(
|
||||
int channel, NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, channel, -1, callback, &HALSIM_CancelPCMSolenoidOutputCallback);
|
||||
store->SetUid(HALSIM_RegisterPCMSolenoidOutputCallback(
|
||||
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PCMSim::GetSolenoidOutput(int channel) const {
|
||||
return HALSIM_GetPCMSolenoidOutput(m_index, channel);
|
||||
}
|
||||
|
||||
void PCMSim::SetSolenoidOutput(int channel, bool solenoidOutput) {
|
||||
HALSIM_SetPCMSolenoidOutput(m_index, channel, solenoidOutput);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPCMCompressorInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterPCMCompressorInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PCMSim::GetCompressorInitialized() const {
|
||||
return HALSIM_GetPCMCompressorInitialized(m_index);
|
||||
}
|
||||
|
||||
void PCMSim::SetCompressorInitialized(bool compressorInitialized) {
|
||||
HALSIM_SetPCMCompressorInitialized(m_index, compressorInitialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorOnCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPCMCompressorOnCallback);
|
||||
store->SetUid(HALSIM_RegisterPCMCompressorOnCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PCMSim::GetCompressorOn() const {
|
||||
return HALSIM_GetPCMCompressorOn(m_index);
|
||||
}
|
||||
|
||||
void PCMSim::SetCompressorOn(bool compressorOn) {
|
||||
HALSIM_SetPCMCompressorOn(m_index, compressorOn);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PCMSim::RegisterClosedLoopEnabledCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPCMClosedLoopEnabledCallback);
|
||||
store->SetUid(HALSIM_RegisterPCMClosedLoopEnabledCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PCMSim::GetClosedLoopEnabled() const {
|
||||
return HALSIM_GetPCMClosedLoopEnabled(m_index);
|
||||
}
|
||||
|
||||
void PCMSim::SetClosedLoopEnabled(bool closedLoopEnabled) {
|
||||
HALSIM_SetPCMClosedLoopEnabled(m_index, closedLoopEnabled);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PCMSim::RegisterPressureSwitchCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPCMPressureSwitchCallback);
|
||||
store->SetUid(HALSIM_RegisterPCMPressureSwitchCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PCMSim::GetPressureSwitch() const {
|
||||
return HALSIM_GetPCMPressureSwitch(m_index);
|
||||
}
|
||||
|
||||
void PCMSim::SetPressureSwitch(bool pressureSwitch) {
|
||||
HALSIM_SetPCMPressureSwitch(m_index, pressureSwitch);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorCurrentCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPCMCompressorCurrentCallback);
|
||||
store->SetUid(HALSIM_RegisterPCMCompressorCurrentCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double PCMSim::GetCompressorCurrent() const {
|
||||
return HALSIM_GetPCMCompressorCurrent(m_index);
|
||||
}
|
||||
|
||||
void PCMSim::SetCompressorCurrent(double compressorCurrent) {
|
||||
HALSIM_SetPCMCompressorCurrent(m_index, compressorCurrent);
|
||||
}
|
||||
|
||||
uint8_t PCMSim::GetAllSolenoidOutputs() const {
|
||||
uint8_t ret = 0;
|
||||
HALSIM_GetPCMAllSolenoids(m_index, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void PCMSim::SetAllSolenoidOutputs(uint8_t outputs) {
|
||||
HALSIM_SetPCMAllSolenoids(m_index, outputs);
|
||||
}
|
||||
|
||||
void PCMSim::ResetData() {
|
||||
HALSIM_ResetPCMData(m_index);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/simulation/SolenoidSim.h"
|
||||
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
SolenoidSim::SolenoidSim(int channel) : m_channel{channel} {}
|
||||
|
||||
SolenoidSim::SolenoidSim(int module, int channel)
|
||||
: m_pcm{module}, m_channel{channel} {}
|
||||
|
||||
SolenoidSim::SolenoidSim(PCMSim& pcm, int channel)
|
||||
: m_pcm{pcm}, m_channel{channel} {}
|
||||
|
||||
SolenoidSim::SolenoidSim(Solenoid& solenoid)
|
||||
: m_pcm{solenoid.GetModuleNumber()}, m_channel{solenoid.GetChannel()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> SolenoidSim::RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
return m_pcm.RegisterSolenoidInitializedCallback(m_channel, callback,
|
||||
initialNotify);
|
||||
}
|
||||
|
||||
bool SolenoidSim::GetInitialized() const {
|
||||
return m_pcm.GetSolenoidInitialized(m_channel);
|
||||
}
|
||||
|
||||
void SolenoidSim::SetInitialized(bool initialized) {
|
||||
m_pcm.SetSolenoidInitialized(m_channel, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> SolenoidSim::RegisterOutputCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
return m_pcm.RegisterSolenoidOutputCallback(m_channel, callback,
|
||||
initialNotify);
|
||||
}
|
||||
|
||||
bool SolenoidSim::GetOutput() const {
|
||||
return m_pcm.GetSolenoidOutput(m_channel);
|
||||
}
|
||||
|
||||
void SolenoidSim::SetOutput(bool output) {
|
||||
m_pcm.SetSolenoidOutput(m_channel, output);
|
||||
}
|
||||
Reference in New Issue
Block a user