mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Add names to simulator components (#1268)
Makes configuration easier when you can associate the items with a name instead of just a port number. Important if there is a GUI added at some point.
This commit is contained in:
committed by
Peter Johnson
parent
8d8f120cc3
commit
de212a9dd0
@@ -0,0 +1,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "lowfisim/SimulatorComponentBase.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
const std::string& SimulatorComponentBase::GetDisplayName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void SimulatorComponentBase::SetDisplayName(const std::string& displayName) {
|
||||
m_name = displayName;
|
||||
}
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -14,21 +14,30 @@ namespace lowfi {
|
||||
ADXLThreeAxisAccelerometerSim::ADXLThreeAxisAccelerometerSim(
|
||||
hal::ThreeAxisAccelerometerData& accelerometerWrapper)
|
||||
: m_accelerometerWrapper(accelerometerWrapper),
|
||||
m_xWrapper(std::function<void(double)>(
|
||||
m_xWrapper(std::function<bool(void)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::GetInitialized,
|
||||
&m_accelerometerWrapper)),
|
||||
std::function<void(double)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::SetX,
|
||||
&m_accelerometerWrapper, std::placeholders::_1)),
|
||||
std::function<double(void)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::GetX,
|
||||
&m_accelerometerWrapper))),
|
||||
|
||||
m_yWrapper(std::function<void(double)>(
|
||||
m_yWrapper(std::function<bool(void)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::GetInitialized,
|
||||
&m_accelerometerWrapper)),
|
||||
std::function<void(double)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::SetY,
|
||||
&m_accelerometerWrapper, std::placeholders::_1)),
|
||||
std::function<double(void)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::GetY,
|
||||
&m_accelerometerWrapper))),
|
||||
|
||||
m_zWrapper(std::function<void(double)>(
|
||||
m_zWrapper(std::function<bool(void)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::GetInitialized,
|
||||
&m_accelerometerWrapper)),
|
||||
std::function<void(double)>(
|
||||
std::bind(&hal::ThreeAxisAccelerometerData::SetZ,
|
||||
&m_accelerometerWrapper, std::placeholders::_1)),
|
||||
std::function<double(void)>(
|
||||
|
||||
@@ -14,6 +14,10 @@ namespace lowfi {
|
||||
ADXRS450_SpiGyroSim::ADXRS450_SpiGyroSim(int spiPort)
|
||||
: m_gyroWrapper(spiPort) {}
|
||||
|
||||
bool ADXRS450_SpiGyroSim::IsWrapperInitialized() const {
|
||||
return m_gyroWrapper.GetInitialized();
|
||||
}
|
||||
|
||||
void ADXRS450_SpiGyroSim::SetAngle(double angle) {
|
||||
m_gyroWrapper.SetAngle(angle);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace lowfi {
|
||||
|
||||
WpiAnalogGyroSim::WpiAnalogGyroSim(int index) : m_gyroSimulator(index) {}
|
||||
|
||||
bool WpiAnalogGyroSim::IsWrapperInitialized() const {
|
||||
return m_gyroSimulator.GetInitialized();
|
||||
}
|
||||
|
||||
void WpiAnalogGyroSim::SetAngle(double angle) {
|
||||
m_gyroSimulator.SetAngle(angle);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace lowfi {
|
||||
|
||||
WpiEncoderSim::WpiEncoderSim(int index) : m_encoderSimulator(index) {}
|
||||
|
||||
bool WpiEncoderSim::IsWrapperInitialized() const {
|
||||
return m_encoderSimulator.GetInitialized();
|
||||
}
|
||||
|
||||
void WpiEncoderSim::SetPosition(double position) {
|
||||
m_encoderSimulator.SetCount(
|
||||
static_cast<int>(position / m_encoderSimulator.GetDistancePerPulse()));
|
||||
|
||||
@@ -20,6 +20,10 @@ void WpiMotorSim::Update(double elapsedTime) {
|
||||
m_motorModelSimulation.Update(elapsedTime);
|
||||
}
|
||||
|
||||
bool WpiMotorSim::IsWrapperInitialized() const {
|
||||
return m_pwmSimulator.GetInitialized();
|
||||
}
|
||||
|
||||
double WpiMotorSim::GetPosition() const {
|
||||
return m_motorModelSimulation.GetPosition();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user