Made SensorBase a utility class and renamed it to SensorUtil (#813)

This commit is contained in:
Tyler Veness
2018-05-23 20:22:30 -07:00
committed by Peter Johnson
parent ba93f79d8b
commit ecfe95383c
72 changed files with 210 additions and 240 deletions

View File

@@ -12,6 +12,7 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "Timer.h"
#include "WPIErrors.h"
@@ -25,7 +26,7 @@ using namespace frc;
* on-board 4-7 are on the MXP port.
*/
AnalogInput::AnalogInput(int channel) {
if (!SensorBase::CheckAnalogInputChannel(channel)) {
if (!SensorUtil::CheckAnalogInputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Analog Input " + wpi::Twine(channel));
return;

View File

@@ -12,7 +12,7 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include "SensorBase.h"
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -26,7 +26,7 @@ using namespace frc;
* @param channel The channel number on the roboRIO to represent.
*/
AnalogOutput::AnalogOutput(int channel) {
if (!SensorBase::CheckAnalogOutputChannel(channel)) {
if (!SensorUtil::CheckAnalogOutputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"analog output " + wpi::Twine(channel));
m_channel = std::numeric_limits<int>::max();

View File

@@ -16,6 +16,7 @@
#include "Counter.h"
#include "Encoder.h"
#include "SensorUtil.h"
#include "Utility.h"
#include "WPIErrors.h"

View File

@@ -13,6 +13,7 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -26,7 +27,7 @@ using namespace frc;
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
*/
DigitalInput::DigitalInput(int channel) {
if (!CheckDigitalChannel(channel)) {
if (!SensorUtil::CheckDigitalChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Digital Channel " + wpi::Twine(channel));
m_channel = std::numeric_limits<int>::max();

View File

@@ -13,7 +13,7 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include "SensorBase.h"
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -29,7 +29,7 @@ using namespace frc;
*/
DigitalOutput::DigitalOutput(int channel) {
m_pwmGenerator = HAL_kInvalidHandle;
if (!SensorBase::CheckDigitalChannel(channel)) {
if (!SensorUtil::CheckDigitalChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Digital Channel " + wpi::Twine(channel));
m_channel = std::numeric_limits<int>::max();
@@ -187,7 +187,7 @@ void DigitalOutput::DisablePWM() {
int32_t status = 0;
// Disable the output by routing to a dead bit.
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, SensorBase::kDigitalChannels,
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, SensorUtil::kDigitalChannels,
&status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));

View File

@@ -11,7 +11,7 @@
#include <HAL/Ports.h>
#include <HAL/Solenoid.h>
#include "SensorBase.h"
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -26,7 +26,7 @@ using namespace frc;
* @param reverseChannel The reverse channel number on the PCM (0..7).
*/
DoubleSolenoid::DoubleSolenoid(int forwardChannel, int reverseChannel)
: DoubleSolenoid(SensorBase::GetDefaultSolenoidModule(), forwardChannel,
: DoubleSolenoid(SensorUtil::GetDefaultSolenoidModule(), forwardChannel,
reverseChannel) {}
/**
@@ -41,18 +41,18 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
: SolenoidBase(moduleNumber),
m_forwardChannel(forwardChannel),
m_reverseChannel(reverseChannel) {
if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) {
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange,
"Solenoid Module " + wpi::Twine(m_moduleNumber));
return;
}
if (!SensorBase::CheckSolenoidChannel(m_forwardChannel)) {
if (!SensorUtil::CheckSolenoidChannel(m_forwardChannel)) {
wpi_setWPIErrorWithContext(
ChannelIndexOutOfRange,
"Solenoid Channel " + wpi::Twine(m_forwardChannel));
return;
}
if (!SensorBase::CheckSolenoidChannel(m_reverseChannel)) {
if (!SensorUtil::CheckSolenoidChannel(m_reverseChannel)) {
wpi_setWPIErrorWithContext(
ChannelIndexOutOfRange,
"Solenoid Channel " + wpi::Twine(m_reverseChannel));

View File

@@ -186,7 +186,7 @@ void LiveWindow::AddActuator(const wpi::Twine& subsystem,
/**
* Meant for internal use in other WPILib classes.
* @deprecated Use SensorBase::SetName() instead.
* @deprecated Use SendableBase::SetName() instead.
*/
void LiveWindow::AddSensor(const wpi::Twine& type, int channel,
Sendable* component) {
@@ -197,7 +197,7 @@ void LiveWindow::AddSensor(const wpi::Twine& type, int channel,
/**
* Meant for internal use in other WPILib classes.
* @deprecated Use SensorBase::SetName() instead.
* @deprecated Use SendableBase::SetName() instead.
*/
void LiveWindow::AddActuator(const wpi::Twine& type, int channel,
Sendable* component) {
@@ -208,7 +208,7 @@ void LiveWindow::AddActuator(const wpi::Twine& type, int channel,
/**
* Meant for internal use in other WPILib classes.
* @deprecated Use SensorBase::SetName() instead.
* @deprecated Use SendableBase::SetName() instead.
*/
void LiveWindow::AddActuator(const wpi::Twine& type, int module, int channel,
Sendable* component) {

View File

@@ -11,7 +11,7 @@
#include <HAL/PWM.h>
#include <HAL/Ports.h>
#include "SensorBase.h"
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "Utility.h"
#include "WPIErrors.h"
@@ -29,7 +29,7 @@ using namespace frc;
* MXP port
*/
PWM::PWM(int channel) {
if (!SensorBase::CheckPWMChannel(channel)) {
if (!SensorUtil::CheckPWMChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"PWM Channel " + wpi::Twine(channel));
return;

View File

@@ -13,6 +13,7 @@
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -77,7 +78,7 @@ double PowerDistributionPanel::GetTemperature() const {
double PowerDistributionPanel::GetCurrent(int channel) const {
int32_t status = 0;
if (!CheckPDPChannel(channel)) {
if (!SensorUtil::CheckPDPChannel(channel)) {
wpi::SmallString<32> str;
wpi::raw_svector_ostream buf(str);
buf << "PDP Channel " << channel;
@@ -174,7 +175,7 @@ void PowerDistributionPanel::ClearStickyFaults() {
void PowerDistributionPanel::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("PowerDistributionPanel");
for (int i = 0; i < kPDPChannels; ++i) {
for (int i = 0; i < SensorUtil::kPDPChannels; ++i) {
builder.AddDoubleProperty("Chan" + wpi::Twine(i),
[=]() { return GetCurrent(i); }, nullptr);
}

View File

@@ -13,7 +13,7 @@
#include <wpi/raw_ostream.h>
#include "MotorSafetyHelper.h"
#include "SensorBase.h"
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -30,7 +30,7 @@ using namespace frc;
*/
Relay::Relay(int channel, Relay::Direction direction)
: m_channel(channel), m_direction(direction) {
if (!SensorBase::CheckRelayChannel(m_channel)) {
if (!SensorUtil::CheckRelayChannel(m_channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Relay Channel " + wpi::Twine(m_channel));
return;

View File

@@ -5,7 +5,7 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include "SensorBase.h"
#include "SensorUtil.h"
#include <HAL/AnalogInput.h>
#include <HAL/AnalogOutput.h>
@@ -17,24 +17,22 @@
#include <HAL/Relay.h>
#include <HAL/Solenoid.h>
#include "WPIErrors.h"
using namespace frc;
const int SensorBase::kDigitalChannels = HAL_GetNumDigitalChannels();
const int SensorBase::kAnalogInputs = HAL_GetNumAnalogInputs();
const int SensorBase::kSolenoidChannels = HAL_GetNumSolenoidChannels();
const int SensorBase::kSolenoidModules = HAL_GetNumPCMModules();
const int SensorBase::kPwmChannels = HAL_GetNumPWMChannels();
const int SensorBase::kRelayChannels = HAL_GetNumRelayHeaders();
const int SensorBase::kPDPChannels = HAL_GetNumPDPChannels();
const int SensorUtil::kDigitalChannels = HAL_GetNumDigitalChannels();
const int SensorUtil::kAnalogInputs = HAL_GetNumAnalogInputs();
const int SensorUtil::kSolenoidChannels = HAL_GetNumSolenoidChannels();
const int SensorUtil::kSolenoidModules = HAL_GetNumPCMModules();
const int SensorUtil::kPwmChannels = HAL_GetNumPWMChannels();
const int SensorUtil::kRelayChannels = HAL_GetNumRelayHeaders();
const int SensorUtil::kPDPChannels = HAL_GetNumPDPChannels();
/**
* Check that the solenoid module number is valid.
*
* @return Solenoid module is valid and present
*/
bool SensorBase::CheckSolenoidModule(int moduleNumber) {
bool SensorUtil::CheckSolenoidModule(int moduleNumber) {
return HAL_CheckSolenoidModule(moduleNumber);
}
@@ -46,7 +44,7 @@ bool SensorBase::CheckSolenoidModule(int moduleNumber) {
*
* @return Digital channel is valid
*/
bool SensorBase::CheckDigitalChannel(int channel) {
bool SensorUtil::CheckDigitalChannel(int channel) {
return HAL_CheckDIOChannel(channel);
}
@@ -58,7 +56,7 @@ bool SensorBase::CheckDigitalChannel(int channel) {
*
* @return Relay channel is valid
*/
bool SensorBase::CheckRelayChannel(int channel) {
bool SensorUtil::CheckRelayChannel(int channel) {
return HAL_CheckRelayChannel(channel);
}
@@ -70,7 +68,7 @@ bool SensorBase::CheckRelayChannel(int channel) {
*
* @return PWM channel is valid
*/
bool SensorBase::CheckPWMChannel(int channel) {
bool SensorUtil::CheckPWMChannel(int channel) {
return HAL_CheckPWMChannel(channel);
}
@@ -82,7 +80,7 @@ bool SensorBase::CheckPWMChannel(int channel) {
*
* @return Analog channel is valid
*/
bool SensorBase::CheckAnalogInputChannel(int channel) {
bool SensorUtil::CheckAnalogInputChannel(int channel) {
return HAL_CheckAnalogInputChannel(channel);
}
@@ -94,7 +92,7 @@ bool SensorBase::CheckAnalogInputChannel(int channel) {
*
* @return Analog channel is valid
*/
bool SensorBase::CheckAnalogOutputChannel(int channel) {
bool SensorUtil::CheckAnalogOutputChannel(int channel) {
return HAL_CheckAnalogOutputChannel(channel);
}
@@ -103,7 +101,7 @@ bool SensorBase::CheckAnalogOutputChannel(int channel) {
*
* @return Solenoid channel is valid
*/
bool SensorBase::CheckSolenoidChannel(int channel) {
bool SensorUtil::CheckSolenoidChannel(int channel) {
return HAL_CheckSolenoidChannel(channel);
}
@@ -112,6 +110,6 @@ bool SensorBase::CheckSolenoidChannel(int channel) {
*
* @return PDP channel is valid
*/
bool SensorBase::CheckPDPChannel(int channel) {
bool SensorUtil::CheckPDPChannel(int channel) {
return HAL_CheckPDPModule(channel);
}

View File

@@ -11,7 +11,7 @@
#include <HAL/Ports.h>
#include <HAL/Solenoid.h>
#include "SensorBase.h"
#include "SensorUtil.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -23,7 +23,7 @@ using namespace frc;
* @param channel The channel on the PCM to control (0..7).
*/
Solenoid::Solenoid(int channel)
: Solenoid(SensorBase::GetDefaultSolenoidModule(), channel) {}
: Solenoid(SensorUtil::GetDefaultSolenoidModule(), channel) {}
/**
* Constructor.
@@ -33,12 +33,12 @@ Solenoid::Solenoid(int channel)
*/
Solenoid::Solenoid(int moduleNumber, int channel)
: SolenoidBase(moduleNumber), m_channel(channel) {
if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) {
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange,
"Solenoid Module " + wpi::Twine(m_moduleNumber));
return;
}
if (!SensorBase::CheckSolenoidChannel(m_channel)) {
if (!SensorUtil::CheckSolenoidChannel(m_channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Solenoid Channel " + wpi::Twine(m_channel));
return;