mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
This removes the name and subsystem from individual objects, and instead puts this data into a new singleton class, SendableRegistry. Much of LiveWindow has been refactored into SendableRegistry. In C++, a new CRTP helper class, SendableHelper, has been added to provide move and destruction functionality. Shims for GetName, SetName, GetSubsystem, and SetSubsystem have been added to Command and Subsystem (both old and new), and also to SendableHelper to prevent code breakage. This deprecates SendableBase in preparation for future removal.
66 lines
2.2 KiB
C++
66 lines
2.2 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* Copyright (c) 2008-2019 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 "frc/AnalogAccelerometer.h"
|
|
|
|
#include <hal/HAL.h>
|
|
|
|
#include "frc/WPIErrors.h"
|
|
#include "frc/smartdashboard/SendableBuilder.h"
|
|
#include "frc/smartdashboard/SendableRegistry.h"
|
|
|
|
using namespace frc;
|
|
|
|
AnalogAccelerometer::AnalogAccelerometer(int channel)
|
|
: AnalogAccelerometer(std::make_shared<AnalogInput>(channel)) {
|
|
SendableRegistry::GetInstance().AddChild(this, m_analogInput.get());
|
|
}
|
|
|
|
AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel)
|
|
: m_analogInput(channel, NullDeleter<AnalogInput>()) {
|
|
if (channel == nullptr) {
|
|
wpi_setWPIError(NullParameter);
|
|
} else {
|
|
InitAccelerometer();
|
|
}
|
|
}
|
|
|
|
AnalogAccelerometer::AnalogAccelerometer(std::shared_ptr<AnalogInput> channel)
|
|
: m_analogInput(channel) {
|
|
if (channel == nullptr) {
|
|
wpi_setWPIError(NullParameter);
|
|
} else {
|
|
InitAccelerometer();
|
|
}
|
|
}
|
|
|
|
double AnalogAccelerometer::GetAcceleration() const {
|
|
return (m_analogInput->GetAverageVoltage() - m_zeroGVoltage) / m_voltsPerG;
|
|
}
|
|
|
|
void AnalogAccelerometer::SetSensitivity(double sensitivity) {
|
|
m_voltsPerG = sensitivity;
|
|
}
|
|
|
|
void AnalogAccelerometer::SetZero(double zero) { m_zeroGVoltage = zero; }
|
|
|
|
double AnalogAccelerometer::PIDGet() { return GetAcceleration(); }
|
|
|
|
void AnalogAccelerometer::InitSendable(SendableBuilder& builder) {
|
|
builder.SetSmartDashboardType("Accelerometer");
|
|
builder.AddDoubleProperty("Value", [=]() { return GetAcceleration(); },
|
|
nullptr);
|
|
}
|
|
|
|
void AnalogAccelerometer::InitAccelerometer() {
|
|
HAL_Report(HALUsageReporting::kResourceType_Accelerometer,
|
|
m_analogInput->GetChannel());
|
|
|
|
SendableRegistry::GetInstance().AddLW(this, "Accelerometer",
|
|
m_analogInput->GetChannel());
|
|
}
|