[wpilib] Add Pneumatics sim classes (#4033)

This commit is contained in:
Starlight220
2022-05-22 17:21:40 +03:00
committed by GitHub
parent 046c2c8972
commit 816aa4e465
15 changed files with 946 additions and 546 deletions

View File

@@ -14,12 +14,13 @@
using namespace frc;
using namespace frc::sim;
CTREPCMSim::CTREPCMSim() : m_index{SensorUtil::GetDefaultCTREPCMModule()} {}
CTREPCMSim::CTREPCMSim()
: PneumaticsBaseSim{SensorUtil::GetDefaultCTREPCMModule()} {}
CTREPCMSim::CTREPCMSim(int module) : m_index{module} {}
CTREPCMSim::CTREPCMSim(int module) : PneumaticsBaseSim{module} {}
CTREPCMSim::CTREPCMSim(const PneumaticsBase& pneumatics)
: m_index{pneumatics.GetModuleNumber()} {}
: PneumaticsBaseSim{pneumatics.GetModuleNumber()} {}
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {

View File

@@ -0,0 +1,48 @@
// 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/PneumaticsBase.h"
using namespace frc;
using namespace frc::sim;
DoubleSolenoidSim::DoubleSolenoidSim(
std::shared_ptr<PneumaticsBaseSim> moduleSim, int fwd, int rev)
: m_module{std::move(moduleSim)}, m_fwd{fwd}, m_rev{rev} {}
DoubleSolenoidSim::DoubleSolenoidSim(int module, PneumaticsModuleType type,
int fwd, int rev)
: m_module{PneumaticsBaseSim::GetForType(module, type)},
m_fwd{fwd},
m_rev{rev} {}
DoubleSolenoidSim::DoubleSolenoidSim(PneumaticsModuleType type, int fwd,
int rev)
: m_module{PneumaticsBaseSim::GetForType(
PneumaticsBase::GetDefaultForType(type), type)},
m_fwd{fwd},
m_rev{rev} {}
DoubleSolenoid::Value DoubleSolenoidSim::Get() const {
bool fwdState = m_module->GetSolenoidOutput(m_fwd);
bool revState = m_module->GetSolenoidOutput(m_rev);
if (fwdState && !revState) {
return DoubleSolenoid::Value::kForward;
} else if (!fwdState && revState) {
return DoubleSolenoid::Value::kReverse;
} else {
return DoubleSolenoid::Value::kOff;
}
}
void DoubleSolenoidSim::Set(DoubleSolenoid::Value output) {
m_module->SetSolenoidOutput(m_fwd, output == DoubleSolenoid::Value::kForward);
m_module->SetSolenoidOutput(m_rev, output == DoubleSolenoid::Value::kReverse);
}
std::shared_ptr<PneumaticsBaseSim> DoubleSolenoidSim::GetModuleSim() const {
return m_module;
}

View File

@@ -0,0 +1,33 @@
// 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/PneumaticsBaseSim.h"
#include "frc/Errors.h"
#include "frc/PneumaticsModuleType.h"
#include "frc/simulation/CTREPCMSim.h"
#include "frc/simulation/REVPHSim.h"
using namespace frc;
using namespace frc::sim;
PneumaticsBaseSim::PneumaticsBaseSim(int module) : m_index{module} {}
PneumaticsBaseSim::PneumaticsBaseSim(const PneumaticsBase& module)
: m_index{module.GetModuleNumber()} {}
std::shared_ptr<PneumaticsBaseSim> PneumaticsBaseSim::GetForType(
int module, PneumaticsModuleType type) {
switch (type) {
case PneumaticsModuleType::REVPH:
return std::make_shared<REVPHSim>(module);
case PneumaticsModuleType::CTREPCM:
return std::make_shared<CTREPCMSim>(module);
default:
throw FRC_MakeError(err::InvalidParameter, "{}",
static_cast<int>(module));
}
}

View File

@@ -14,12 +14,12 @@
using namespace frc;
using namespace frc::sim;
REVPHSim::REVPHSim() : m_index{SensorUtil::GetDefaultREVPHModule()} {}
REVPHSim::REVPHSim() : PneumaticsBaseSim{SensorUtil::GetDefaultREVPHModule()} {}
REVPHSim::REVPHSim(int module) : m_index{module} {}
REVPHSim::REVPHSim(int module) : PneumaticsBaseSim{module} {}
REVPHSim::REVPHSim(const PneumaticsBase& pneumatics)
: m_index{pneumatics.GetModuleNumber()} {}
: PneumaticsBaseSim{pneumatics} {}
std::unique_ptr<CallbackStore> REVPHSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {

View File

@@ -0,0 +1,41 @@
// 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/PneumaticsBase.h"
using namespace frc;
using namespace frc::sim;
SolenoidSim::SolenoidSim(std::shared_ptr<PneumaticsBaseSim> moduleSim,
int channel)
: m_module{std::move(moduleSim)}, m_channel{channel} {}
SolenoidSim::SolenoidSim(int module, PneumaticsModuleType type, int channel)
: m_module{PneumaticsBaseSim::GetForType(module, type)},
m_channel{channel} {}
SolenoidSim::SolenoidSim(PneumaticsModuleType type, int channel)
: m_module{PneumaticsBaseSim::GetForType(
PneumaticsBase::GetDefaultForType(type), type)},
m_channel{channel} {}
bool SolenoidSim::GetOutput() const {
return m_module->GetSolenoidOutput(m_channel);
}
void SolenoidSim::SetOutput(bool output) {
m_module->SetSolenoidOutput(m_channel, output);
}
std::unique_ptr<CallbackStore> SolenoidSim::RegisterOutputCallback(
NotifyCallback callback, bool initialNotify) {
return m_module->RegisterSolenoidOutputCallback(m_channel, callback,
initialNotify);
}
std::shared_ptr<PneumaticsBaseSim> SolenoidSim::GetModuleSim() const {
return m_module;
}