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:
PJ Reiniger
2018-08-23 20:59:09 -04:00
committed by Peter Johnson
parent 8d8f120cc3
commit de212a9dd0
30 changed files with 207 additions and 24 deletions

View File

@@ -7,11 +7,13 @@
#pragma once
#include "lowfisim/SimulatorComponent.h"
namespace frc {
namespace sim {
namespace lowfi {
class AccelerometerSim {
class AccelerometerSim : public virtual SimulatorComponent {
public:
virtual double GetAcceleration() = 0;
virtual void SetAcceleration(double acceleration) = 0;

View File

@@ -7,11 +7,13 @@
#pragma once
#include "lowfisim/SimulatorComponent.h"
namespace frc {
namespace sim {
namespace lowfi {
class EncoderSim {
class EncoderSim : public virtual SimulatorComponent {
public:
virtual void SetPosition(double position) = 0;
virtual void SetVelocity(double velocity) = 0;

View File

@@ -7,11 +7,13 @@
#pragma once
#include "lowfisim/SimulatorComponent.h"
namespace frc {
namespace sim {
namespace lowfi {
class GyroSim {
class GyroSim : public virtual SimulatorComponent {
public:
virtual void SetAngle(double angle) = 0;
virtual double GetAngle() = 0;

View File

@@ -7,11 +7,13 @@
#pragma once
#include "lowfisim/SimulatorComponent.h"
namespace frc {
namespace sim {
namespace lowfi {
class MotorSim {
class MotorSim : public virtual SimulatorComponent {
public:
virtual double GetPosition() const = 0;
virtual double GetVelocity() const = 0;

View File

@@ -10,16 +10,22 @@
#include <functional>
#include "lowfisim/AccelerometerSim.h"
#include "lowfisim/SimulatorComponentBase.h"
namespace frc {
namespace sim {
namespace lowfi {
class SimpleAccelerometerSim : public AccelerometerSim {
class SimpleAccelerometerSim : public SimulatorComponentBase,
public AccelerometerSim {
public:
SimpleAccelerometerSim(const std::function<void(double)>& setterFunction,
using SimulatorComponentBase::GetDisplayName;
SimpleAccelerometerSim(const std::function<bool(void)>& initializedFunction,
const std::function<void(double)>& setterFunction,
const std::function<double(void)>& getterFunction)
: m_setAccelerationFunction(setterFunction),
: m_isInitializedFunction(initializedFunction),
m_setAccelerationFunction(setterFunction),
m_getAccelerationFunction(getterFunction) {}
double GetAcceleration() override { return m_getAccelerationFunction(); }
@@ -27,7 +33,12 @@ class SimpleAccelerometerSim : public AccelerometerSim {
m_setAccelerationFunction(acceleration);
}
bool IsWrapperInitialized() const override {
return m_isInitializedFunction();
}
private:
std::function<bool(void)> m_isInitializedFunction;
std::function<void(double)> m_setAccelerationFunction;
std::function<double(void)> m_getAccelerationFunction;
};

View File

@@ -0,0 +1,29 @@
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <string>
namespace frc {
namespace sim {
namespace lowfi {
class SimulatorComponent {
public:
virtual ~SimulatorComponent() = default;
virtual bool IsWrapperInitialized() const = 0;
virtual const std::string& GetDisplayName() const = 0;
virtual void SetDisplayName(const std::string& displayName) = 0;
};
} // namespace lowfi
} // namespace sim
} // namespace frc

View File

@@ -0,0 +1,33 @@
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <string>
#include "lowfisim/SimulatorComponent.h"
namespace frc {
namespace sim {
namespace lowfi {
class SimulatorComponentBase : public virtual SimulatorComponent {
public:
SimulatorComponentBase() = default;
virtual ~SimulatorComponentBase() = default;
const std::string& GetDisplayName() const override;
void SetDisplayName(const std::string& displayName) override;
private:
std::string m_name;
};
} // namespace lowfi
} // namespace sim
} // namespace frc

View File

@@ -9,15 +9,18 @@
#include "ADXRS450_SpiGyroWrapperData.h"
#include "lowfisim/GyroSim.h"
#include "lowfisim/SimulatorComponentBase.h"
namespace frc {
namespace sim {
namespace lowfi {
class ADXRS450_SpiGyroSim : public GyroSim {
class ADXRS450_SpiGyroSim : public SimulatorComponentBase, public GyroSim {
public:
explicit ADXRS450_SpiGyroSim(int spiPort);
bool IsWrapperInitialized() const override;
void SetAngle(double angle) override;
double GetAngle() override;

View File

@@ -8,16 +8,19 @@
#pragma once
#include "lowfisim/GyroSim.h"
#include "lowfisim/SimulatorComponentBase.h"
#include "simulation/AnalogGyroSim.h"
namespace frc {
namespace sim {
namespace lowfi {
class WpiAnalogGyroSim : public GyroSim {
class WpiAnalogGyroSim : public SimulatorComponentBase, public GyroSim {
public:
explicit WpiAnalogGyroSim(int index);
bool IsWrapperInitialized() const override;
void SetAngle(double angle) override;
double GetAngle() override;

View File

@@ -8,15 +8,17 @@
#pragma once
#include "lowfisim/EncoderSim.h"
#include "lowfisim/SimulatorComponentBase.h"
#include "simulation/EncoderSim.h"
namespace frc {
namespace sim {
namespace lowfi {
class WpiEncoderSim : public EncoderSim {
class WpiEncoderSim : public SimulatorComponentBase, public EncoderSim {
public:
explicit WpiEncoderSim(int index);
bool IsWrapperInitialized() const override;
void SetPosition(double position) override;
void SetVelocity(double velocity) override;

View File

@@ -8,6 +8,7 @@
#pragma once
#include "lowfisim/MotorSim.h"
#include "lowfisim/SimulatorComponentBase.h"
#include "lowfisim/motormodel/MotorModel.h"
#include "simulation/PWMSim.h"
@@ -15,9 +16,10 @@ namespace frc {
namespace sim {
namespace lowfi {
class WpiMotorSim : public MotorSim {
class WpiMotorSim : public SimulatorComponentBase, public MotorSim {
public:
explicit WpiMotorSim(int index, MotorModel& motorModelSimulator);
bool IsWrapperInitialized() const override;
void Update(double elapsedTime);
double GetPosition() const override;