[hal, wpilib] Remove built in accelerometer (#7702)

This commit is contained in:
Thad House
2025-01-17 14:06:09 -08:00
committed by GitHub
parent 1600e773f4
commit 5a6c895b87
48 changed files with 0 additions and 2304 deletions

View File

@@ -1,47 +0,0 @@
// 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/BuiltInAccelerometer.h"
#include <hal/Accelerometer.h>
#include <hal/FRCUsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc/Errors.h"
using namespace frc;
BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
SetRange(range);
HAL_Report(HALUsageReporting::kResourceType_Accelerometer, 0, 0,
"Built-in accelerometer");
wpi::SendableRegistry::AddLW(this, "BuiltInAccel");
}
void BuiltInAccelerometer::SetRange(Range range) {
HAL_SetAccelerometerActive(false);
HAL_SetAccelerometerRange(static_cast<HAL_AccelerometerRange>(range));
HAL_SetAccelerometerActive(true);
}
double BuiltInAccelerometer::GetX() {
return HAL_GetAccelerometerX();
}
double BuiltInAccelerometer::GetY() {
return HAL_GetAccelerometerY();
}
double BuiltInAccelerometer::GetZ() {
return HAL_GetAccelerometerZ();
}
void BuiltInAccelerometer::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("3AxisAccelerometer");
builder.AddDoubleProperty("X", [=, this] { return GetX(); }, nullptr);
builder.AddDoubleProperty("Y", [=, this] { return GetY(); }, nullptr);
builder.AddDoubleProperty("Z", [=, this] { return GetZ(); }, nullptr);
}

View File

@@ -1,108 +0,0 @@
// 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/BuiltInAccelerometerSim.h"
#include <memory>
#include <hal/simulation/AccelerometerData.h>
#include "frc/BuiltInAccelerometer.h"
using namespace frc;
using namespace frc::sim;
BuiltInAccelerometerSim::BuiltInAccelerometerSim() : m_index{0} {}
BuiltInAccelerometerSim::BuiltInAccelerometerSim(const BuiltInAccelerometer&)
: m_index{0} {}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterActiveCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerActiveCallback);
store->SetUid(HALSIM_RegisterAccelerometerActiveCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool BuiltInAccelerometerSim::GetActive() const {
return HALSIM_GetAccelerometerActive(m_index);
}
void BuiltInAccelerometerSim::SetActive(bool active) {
HALSIM_SetAccelerometerActive(m_index, active);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterRangeCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerRangeCallback);
store->SetUid(HALSIM_RegisterAccelerometerRangeCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
HAL_AccelerometerRange BuiltInAccelerometerSim::GetRange() const {
return HALSIM_GetAccelerometerRange(m_index);
}
void BuiltInAccelerometerSim::SetRange(HAL_AccelerometerRange range) {
HALSIM_SetAccelerometerRange(m_index, range);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterXCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerXCallback);
store->SetUid(HALSIM_RegisterAccelerometerXCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double BuiltInAccelerometerSim::GetX() const {
return HALSIM_GetAccelerometerX(m_index);
}
void BuiltInAccelerometerSim::SetX(double x) {
HALSIM_SetAccelerometerX(m_index, x);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterYCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerYCallback);
store->SetUid(HALSIM_RegisterAccelerometerYCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double BuiltInAccelerometerSim::GetY() const {
return HALSIM_GetAccelerometerY(m_index);
}
void BuiltInAccelerometerSim::SetY(double y) {
HALSIM_SetAccelerometerY(m_index, y);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterZCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerZCallback);
store->SetUid(HALSIM_RegisterAccelerometerZCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double BuiltInAccelerometerSim::GetZ() const {
return HALSIM_GetAccelerometerZ(m_index);
}
void BuiltInAccelerometerSim::SetZ(double z) {
HALSIM_SetAccelerometerZ(m_index, z);
}
void BuiltInAccelerometerSim::ResetData() {
HALSIM_ResetAccelerometerData(m_index);
}

View File

@@ -1,68 +0,0 @@
// 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.
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
namespace frc {
/**
* Built-in accelerometer.
*
* This class allows access to the roboRIO's internal accelerometer.
*/
class BuiltInAccelerometer : public wpi::Sendable,
public wpi::SendableHelper<BuiltInAccelerometer> {
public:
/**
* Accelerometer range.
*/
enum Range {
/// 2 Gs max.
kRange_2G = 0,
/// 4 Gs max.
kRange_4G = 1,
/// 8 Gs max.
kRange_8G = 2
};
/**
* Constructor.
*
* @param range The range the accelerometer will measure
*/
explicit BuiltInAccelerometer(Range range = kRange_8G);
BuiltInAccelerometer(BuiltInAccelerometer&&) = default;
BuiltInAccelerometer& operator=(BuiltInAccelerometer&&) = default;
/**
* Set the measuring range of the accelerometer.
*
* @param range The maximum acceleration, positive or negative, that the
* accelerometer will measure.
*/
void SetRange(Range range);
/**
* @return The acceleration of the roboRIO along the X axis in g-forces
*/
double GetX();
/**
* @return The acceleration of the roboRIO along the Y axis in g-forces
*/
double GetY();
/**
* @return The acceleration of the roboRIO along the Z axis in g-forces
*/
double GetZ();
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -1,170 +0,0 @@
// 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.
#pragma once
#include <memory>
#include <hal/Accelerometer.h>
#include "frc/simulation/CallbackStore.h"
namespace frc {
class BuiltInAccelerometer;
namespace sim {
/**
* Class to control a simulated built-in accelerometer.
*/
class BuiltInAccelerometerSim {
public:
/**
* Constructs for the first built-in accelerometer.
*/
BuiltInAccelerometerSim();
/**
* Constructs from a BuiltInAccelerometer object.
*
* @param accel BuiltInAccelerometer to simulate
*/
explicit BuiltInAccelerometerSim(const BuiltInAccelerometer& accel);
/**
* Register a callback to be run when this accelerometer activates.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
bool initialNotify);
/**
* Check whether the accelerometer is active.
*
* @return true if active
*/
bool GetActive() const;
/**
* Define whether this accelerometer is active.
*
* @param active the new state
*/
void SetActive(bool active);
/**
* Register a callback to be run whenever the range changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
bool initialNotify);
/**
* Check the range of this accelerometer.
*
* @return the accelerometer range
*/
HAL_AccelerometerRange GetRange() const;
/**
* Change the range of this accelerometer.
*
* @param range the new accelerometer range
*/
void SetRange(HAL_AccelerometerRange range);
/**
* Register a callback to be run whenever the X axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
bool initialNotify);
/**
* Measure the X axis value.
*
* @return the X axis measurement
*/
double GetX() const;
/**
* Change the X axis value of the accelerometer.
*
* @param x the new reading of the X axis
*/
void SetX(double x);
/**
* Register a callback to be run whenever the Y axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
bool initialNotify);
/**
* Measure the Y axis value.
*
* @return the Y axis measurement
*/
double GetY() const;
/**
* Change the Y axis value of the accelerometer.
*
* @param y the new reading of the Y axis
*/
void SetY(double y);
/**
* Register a callback to be run whenever the Z axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
bool initialNotify);
/**
* Measure the Z axis value.
*
* @return the Z axis measurement
*/
double GetZ() const;
/**
* Change the Z axis value of the accelerometer.
*
* @param z the new reading of the Z axis
*/
void SetZ(double z);
/**
* Reset all simulation data of this object.
*/
void ResetData();
private:
int m_index;
};
} // namespace sim
} // namespace frc