mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Simulate ADX* family of accelerometers and gyros (#688)
This commit is contained in:
committed by
Peter Johnson
parent
cd1dbb1e3a
commit
303c259b89
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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"
|
||||
|
||||
namespace hal {
|
||||
class ADXL345_I2CData : public ThreeAxisAccelerometerData {
|
||||
public:
|
||||
explicit ADXL345_I2CData(int port);
|
||||
virtual ~ADXL345_I2CData();
|
||||
|
||||
void HandleWrite(const uint8_t* buffer, uint32_t count);
|
||||
void HandleRead(uint8_t* buffer, uint32_t count);
|
||||
|
||||
private:
|
||||
int m_lastWriteAddress;
|
||||
|
||||
static const double LSB;
|
||||
};
|
||||
} // namespace hal
|
||||
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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"
|
||||
|
||||
namespace hal {
|
||||
class ADXL345_SpiAccelerometer : public ThreeAxisAccelerometerData {
|
||||
public:
|
||||
explicit ADXL345_SpiAccelerometer(int port);
|
||||
virtual ~ADXL345_SpiAccelerometer();
|
||||
|
||||
void HandleWrite(const uint8_t* buffer, uint32_t count);
|
||||
void HandleRead(uint8_t* buffer, uint32_t count);
|
||||
|
||||
private:
|
||||
int m_lastWriteAddress;
|
||||
|
||||
static const double LSB;
|
||||
};
|
||||
} // namespace hal
|
||||
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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"
|
||||
|
||||
namespace hal {
|
||||
class ADXL362_SpiAccelerometer : public ThreeAxisAccelerometerData {
|
||||
public:
|
||||
explicit ADXL362_SpiAccelerometer(int port);
|
||||
virtual ~ADXL362_SpiAccelerometer();
|
||||
|
||||
void HandleWrite(const uint8_t* buffer, uint32_t count);
|
||||
void HandleRead(uint8_t* buffer, uint32_t count);
|
||||
|
||||
private:
|
||||
int m_lastWriteAddress;
|
||||
|
||||
static const double LSB;
|
||||
};
|
||||
} // namespace hal
|
||||
@@ -0,0 +1,43 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class ADXRS450_SpiGyroWrapper {
|
||||
public:
|
||||
explicit ADXRS450_SpiGyroWrapper(int port);
|
||||
virtual ~ADXRS450_SpiGyroWrapper();
|
||||
|
||||
void HandleRead(uint8_t* buffer, uint32_t count);
|
||||
|
||||
virtual void ResetData();
|
||||
|
||||
int32_t RegisterAngleCallback(HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void CancelAngleCallback(int32_t uid);
|
||||
void InvokeAngleCallback(HAL_Value value);
|
||||
double GetAngle();
|
||||
void SetAngle(double angle);
|
||||
|
||||
private:
|
||||
const int m_port;
|
||||
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<double> m_angle{0.0};
|
||||
std::shared_ptr<NotifyListenerVector> m_angleCallbacks = nullptr;
|
||||
|
||||
static const double ANGLE_LSB;
|
||||
};
|
||||
} // namespace hal
|
||||
@@ -0,0 +1,55 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 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 <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
namespace hal {
|
||||
class ThreeAxisAccelerometerData {
|
||||
public:
|
||||
ThreeAxisAccelerometerData();
|
||||
virtual ~ThreeAxisAccelerometerData();
|
||||
|
||||
int32_t RegisterXCallback(HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void CancelXCallback(int32_t uid);
|
||||
void InvokeXCallback(HAL_Value value);
|
||||
double GetX();
|
||||
void SetX(double x);
|
||||
|
||||
int32_t RegisterYCallback(HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void CancelYCallback(int32_t uid);
|
||||
void InvokeYCallback(HAL_Value value);
|
||||
double GetY();
|
||||
void SetY(double y);
|
||||
|
||||
int32_t RegisterZCallback(HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void CancelZCallback(int32_t uid);
|
||||
void InvokeZCallback(HAL_Value value);
|
||||
double GetZ();
|
||||
void SetZ(double z);
|
||||
|
||||
virtual void ResetData();
|
||||
|
||||
protected:
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<double> m_x{0.0};
|
||||
std::shared_ptr<NotifyListenerVector> m_xCallbacks = nullptr;
|
||||
std::atomic<double> m_y{0.0};
|
||||
std::shared_ptr<NotifyListenerVector> m_yCallbacks = nullptr;
|
||||
std::atomic<double> m_z{0.0};
|
||||
std::shared_ptr<NotifyListenerVector> m_zCallbacks = nullptr;
|
||||
};
|
||||
} // namespace hal
|
||||
Reference in New Issue
Block a user