mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Add gyro and accelerometer simulator wrappers (#1183)
This commit is contained in:
committed by
Peter Johnson
parent
0a0d9245e2
commit
c2ceebfb9c
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class AccelerometerSim {
|
||||
public:
|
||||
virtual double GetAcceleration() = 0;
|
||||
virtual void SetAcceleration(double acceleration) = 0;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class GyroSim {
|
||||
public:
|
||||
virtual void SetAngle(double angle) = 0;
|
||||
virtual double GetAngle() = 0;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,37 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 <functional>
|
||||
|
||||
#include "lowfisim/AccelerometerSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class SimpleAccelerometerSim : public AccelerometerSim {
|
||||
public:
|
||||
SimpleAccelerometerSim(const std::function<void(double)>& setterFunction,
|
||||
const std::function<double(void)>& getterFunction)
|
||||
: m_setAccelerationFunction(setterFunction),
|
||||
m_getAccelerationFunction(getterFunction) {}
|
||||
double GetAcceleration() override { return m_getAccelerationFunction(); }
|
||||
|
||||
void SetAcceleration(double acceleration) override {
|
||||
m_setAccelerationFunction(acceleration);
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void(double)> m_setAccelerationFunction;
|
||||
std::function<double(void)> m_getAccelerationFunction;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,35 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 <functional>
|
||||
|
||||
#include "lowfisim/GyroSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class SimpleGyroSim : public GyroSim {
|
||||
public:
|
||||
SimpleGyroSim(std::function<void(double)>& setterFunction,
|
||||
std::function<double(void)>& getterFunction)
|
||||
: m_setAngleFunction(setterFunction),
|
||||
m_getAngleFunction(getterFunction) {}
|
||||
double GetAngle() override { return m_getAngleFunction(); }
|
||||
|
||||
void SetAngle(double angle) override { m_setAngleFunction(angle); }
|
||||
|
||||
private:
|
||||
std::function<void(double)> m_setAngleFunction;
|
||||
std::function<double(void)> m_getAngleFunction;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,35 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-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 "ThreeAxisAccelerometerData.h"
|
||||
#include "lowfisim/SimpleAccelerometerSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class ADXLThreeAxisAccelerometerSim {
|
||||
public:
|
||||
ADXLThreeAxisAccelerometerSim(
|
||||
hal::ThreeAxisAccelerometerData& accelerometerWrapper);
|
||||
|
||||
AccelerometerSim& GetXWrapper();
|
||||
AccelerometerSim& GetYWrapper();
|
||||
AccelerometerSim& GetZWrapper();
|
||||
|
||||
protected:
|
||||
hal::ThreeAxisAccelerometerData& m_accelerometerWrapper;
|
||||
SimpleAccelerometerSim m_xWrapper;
|
||||
SimpleAccelerometerSim m_yWrapper;
|
||||
SimpleAccelerometerSim m_zWrapper;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-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 "ADXRS450_SpiGyroWrapperData.h"
|
||||
#include "lowfisim/GyroSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class ADXRS450_SpiGyroSim : public GyroSim {
|
||||
public:
|
||||
explicit ADXRS450_SpiGyroSim(int spiPort);
|
||||
|
||||
void SetAngle(double angle) override;
|
||||
double GetAngle() override;
|
||||
|
||||
protected:
|
||||
hal::ADXRS450_SpiGyroWrapper m_gyroWrapper;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-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 "lowfisim/GyroSim.h"
|
||||
#include "simulation/AnalogGyroSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class WpiAnalogGyroSim : public GyroSim {
|
||||
public:
|
||||
explicit WpiAnalogGyroSim(int index);
|
||||
|
||||
void SetAngle(double angle) override;
|
||||
double GetAngle() override;
|
||||
|
||||
protected:
|
||||
frc::sim::AnalogGyroSim m_gyroSimulator;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
Reference in New Issue
Block a user