mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
This makes code easier to read and more consistent between C++ and Java. Also update clang-format settings to always add a line break (even if no braces are used).
50 lines
1.8 KiB
C++
50 lines
1.8 KiB
C++
// 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/AnalogPotentiometer.h"
|
|
|
|
#include "frc/Base.h"
|
|
#include "frc/RobotController.h"
|
|
#include "frc/smartdashboard/SendableBuilder.h"
|
|
#include "frc/smartdashboard/SendableRegistry.h"
|
|
|
|
using namespace frc;
|
|
|
|
AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
|
|
double offset)
|
|
: AnalogPotentiometer(std::make_shared<AnalogInput>(channel), fullRange,
|
|
offset) {
|
|
SendableRegistry::GetInstance().AddChild(this, m_analog_input.get());
|
|
}
|
|
|
|
AnalogPotentiometer::AnalogPotentiometer(AnalogInput* input, double fullRange,
|
|
double offset)
|
|
: AnalogPotentiometer(
|
|
std::shared_ptr<AnalogInput>(input, NullDeleter<AnalogInput>()),
|
|
fullRange, offset) {}
|
|
|
|
AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
|
|
double fullRange, double offset)
|
|
: m_analog_input(input), m_fullRange(fullRange), m_offset(offset) {
|
|
SendableRegistry::GetInstance().AddLW(this, "AnalogPotentiometer",
|
|
m_analog_input->GetChannel());
|
|
}
|
|
|
|
double AnalogPotentiometer::Get() const {
|
|
return (m_analog_input->GetAverageVoltage() /
|
|
RobotController::GetVoltage5V()) *
|
|
m_fullRange +
|
|
m_offset;
|
|
}
|
|
|
|
double AnalogPotentiometer::PIDGet() {
|
|
return Get();
|
|
}
|
|
|
|
void AnalogPotentiometer::InitSendable(SendableBuilder& builder) {
|
|
builder.SetSmartDashboardType("Analog Input");
|
|
builder.AddDoubleProperty(
|
|
"Value", [=]() { return Get(); }, nullptr);
|
|
}
|