mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilibc] Remove ErrorBase (#3306)
Replace with new exception-based error reporting, consistent with Java. This also builds stacktraces into the reporting/exceptions.
This commit is contained in:
@@ -21,10 +21,9 @@ Command::~Command() {
|
||||
CommandScheduler::GetInstance().Cancel(this);
|
||||
}
|
||||
|
||||
Command::Command(const Command& rhs) : ErrorBase(rhs) {}
|
||||
Command::Command(const Command& rhs) = default;
|
||||
|
||||
Command& Command::operator=(const Command& rhs) {
|
||||
ErrorBase::operator=(rhs);
|
||||
m_isGrouped = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -4,19 +4,15 @@
|
||||
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
|
||||
#include <frc/WPIErrors.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
bool CommandGroupBase::RequireUngrouped(Command& command) {
|
||||
if (command.IsGrouped()) {
|
||||
wpi_setGlobalWPIErrorWithContext(
|
||||
CommandIllegalUse,
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to more than one CommandGroup");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandGroupBase::RequireUngrouped(
|
||||
@@ -26,8 +22,8 @@ bool CommandGroupBase::RequireUngrouped(
|
||||
allUngrouped &= !command.get()->IsGrouped();
|
||||
}
|
||||
if (!allUngrouped) {
|
||||
wpi_setGlobalWPIErrorWithContext(
|
||||
CommandIllegalUse,
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to more than one CommandGroup");
|
||||
}
|
||||
return allUngrouped;
|
||||
@@ -40,8 +36,8 @@ bool CommandGroupBase::RequireUngrouped(
|
||||
allUngrouped &= !command->IsGrouped();
|
||||
}
|
||||
if (!allUngrouped) {
|
||||
wpi_setGlobalWPIErrorWithContext(
|
||||
CommandIllegalUse,
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to more than one CommandGroup");
|
||||
}
|
||||
return allUngrouped;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <frc/RobotBase.h>
|
||||
#include <frc/RobotState.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/WPIErrors.h>
|
||||
#include <frc/livewindow/LiveWindow.h>
|
||||
#include <frc/smartdashboard/SendableBuilder.h>
|
||||
#include <frc/smartdashboard/SendableRegistry.h>
|
||||
@@ -112,9 +111,9 @@ void CommandScheduler::Schedule(bool interruptible, Command* command) {
|
||||
}
|
||||
|
||||
if (command->IsGrouped()) {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"A command that is part of a command group "
|
||||
"cannot be independently scheduled");
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"A command that is part of a command group "
|
||||
"cannot be independently scheduled");
|
||||
return;
|
||||
}
|
||||
if (m_impl->disabled ||
|
||||
|
||||
@@ -65,9 +65,9 @@ void ParallelCommandGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
|
||||
for (auto&& command : commands) {
|
||||
@@ -77,10 +77,9 @@ void ParallelCommandGroup::AddCommands(
|
||||
m_runWhenDisabled &= command->RunsWhenDisabled();
|
||||
m_commands.emplace_back(std::move(command), false);
|
||||
} else {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
return;
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,9 @@ void ParallelDeadlineGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (!m_finished) {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
|
||||
for (auto&& command : commands) {
|
||||
@@ -72,10 +72,9 @@ void ParallelDeadlineGroup::AddCommands(
|
||||
m_runWhenDisabled &= command->RunsWhenDisabled();
|
||||
m_commands.emplace_back(std::move(command), false);
|
||||
} else {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
return;
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ void ParallelRaceGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
|
||||
for (auto&& command : commands) {
|
||||
@@ -62,10 +62,9 @@ void ParallelRaceGroup::AddCommands(
|
||||
m_runWhenDisabled &= command->RunsWhenDisabled();
|
||||
m_commands.emplace_back(std::move(command));
|
||||
} else {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
return;
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,9 @@ void SequentialCommandGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (m_currentCommandIndex != invalid_index) {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
|
||||
for (auto&& command : commands) {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/Demangle.h>
|
||||
@@ -46,10 +45,10 @@ class ProxyScheduleCommand;
|
||||
* @see CommandScheduler
|
||||
* @see CommandHelper
|
||||
*/
|
||||
class Command : public frc::ErrorBase {
|
||||
class Command {
|
||||
public:
|
||||
Command() = default;
|
||||
~Command() override;
|
||||
virtual ~Command();
|
||||
|
||||
Command(const Command&);
|
||||
Command& operator=(const Command&);
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
#include <frc/WPIErrors.h>
|
||||
#include <frc/Errors.h>
|
||||
#include <frc/Watchdog.h>
|
||||
#include <frc/smartdashboard/Sendable.h>
|
||||
#include <frc/smartdashboard/SendableHelper.h>
|
||||
@@ -29,7 +28,6 @@ class Subsystem;
|
||||
* methods to be called and for their default commands to be scheduled.
|
||||
*/
|
||||
class CommandScheduler final : public frc::Sendable,
|
||||
public frc::ErrorBase,
|
||||
public frc::SendableHelper<CommandScheduler> {
|
||||
public:
|
||||
/**
|
||||
@@ -182,14 +180,12 @@ class CommandScheduler final : public frc::Sendable,
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
void SetDefaultCommand(Subsystem* subsystem, T&& defaultCommand) {
|
||||
if (!defaultCommand.HasRequirement(subsystem)) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
CommandIllegalUse, "Default commands must require their subsystem!");
|
||||
return;
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Default commands must require their subsystem!");
|
||||
}
|
||||
if (defaultCommand.IsFinished()) {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Default commands should not end!");
|
||||
return;
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"Default commands should not end!");
|
||||
}
|
||||
SetDefaultCommandImpl(subsystem,
|
||||
std::make_unique<std::remove_reference_t<T>>(
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
#include <frc/WPIErrors.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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/Errors.h>
|
||||
|
||||
#include "CommandTestBase.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/ConditionalCommand.h"
|
||||
@@ -71,11 +73,9 @@ TEST_F(CommandRequirementsTest, RequirementUninterruptibleTest) {
|
||||
|
||||
TEST_F(CommandRequirementsTest, DefaultCommandRequirementErrorTest) {
|
||||
TestSubsystem requirement1;
|
||||
ErrorConfirmer confirmer("require");
|
||||
|
||||
MockCommand command1;
|
||||
|
||||
requirement1.SetDefaultCommand(std::move(command1));
|
||||
|
||||
EXPECT_TRUE(requirement1.GetDefaultCommand() == nullptr);
|
||||
ASSERT_THROW(requirement1.SetDefaultCommand(std::move(command1)),
|
||||
frc::RuntimeError);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <frc/simulation/DriverStationSim.h>
|
||||
|
||||
#include "ErrorConfirmer.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/SetUtilities.h"
|
||||
|
||||
@@ -1,19 +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 "ErrorConfirmer.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
ErrorConfirmer* ErrorConfirmer::instance;
|
||||
|
||||
int32_t ErrorConfirmer::HandleError(HAL_Bool isError, int32_t errorCode,
|
||||
HAL_Bool isLVCode, const char* details,
|
||||
const char* location, const char* callStack,
|
||||
HAL_Bool printMsg) {
|
||||
if (std::regex_search(details, std::regex(instance->m_msg))) {
|
||||
instance->ConfirmError();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -1,38 +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 <hal/simulation/MockHooks.h>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
class ErrorConfirmer {
|
||||
public:
|
||||
explicit ErrorConfirmer(const char* msg) : m_msg(msg) {
|
||||
if (instance != nullptr) {
|
||||
return;
|
||||
}
|
||||
HALSIM_SetSendError(HandleError);
|
||||
EXPECT_CALL(*this, ConfirmError());
|
||||
instance = this;
|
||||
}
|
||||
|
||||
~ErrorConfirmer() {
|
||||
HALSIM_SetSendError(nullptr);
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
MOCK_METHOD0(ConfirmError, void());
|
||||
|
||||
const char* m_msg;
|
||||
|
||||
static int32_t HandleError(HAL_Bool isError, int32_t errorCode,
|
||||
HAL_Bool isLVCode, const char* details,
|
||||
const char* location, const char* callStack,
|
||||
HAL_Bool printMsg);
|
||||
|
||||
private:
|
||||
static ErrorConfirmer* instance;
|
||||
};
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/RobotState.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/commands/CommandGroup.h"
|
||||
#include "frc/commands/Scheduler.h"
|
||||
#include "frc/livewindow/LiveWindow.h"
|
||||
@@ -32,7 +32,7 @@ Command::Command(Subsystem& subsystem) : Command("", -1.0) {
|
||||
Command::Command(const wpi::Twine& name, double timeout) {
|
||||
// We use -1.0 to indicate no timeout.
|
||||
if (timeout < 0.0 && timeout != -1.0) {
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
}
|
||||
|
||||
m_timeout = timeout;
|
||||
@@ -77,15 +77,15 @@ void Command::Requires(Subsystem* subsystem) {
|
||||
if (subsystem != nullptr) {
|
||||
m_requirements.insert(subsystem);
|
||||
} else {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "subsystem");
|
||||
throw FRC_MakeError(err::NullParameter, "subsystem");
|
||||
}
|
||||
}
|
||||
|
||||
void Command::Start() {
|
||||
LockChanges();
|
||||
if (m_parent != nullptr) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
CommandIllegalUse,
|
||||
throw FRC_MakeError(
|
||||
err::CommandIllegalUse,
|
||||
"Can not start a command that is part of a command group");
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ bool Command::Run() {
|
||||
|
||||
void Command::Cancel() {
|
||||
if (m_parent != nullptr) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
CommandIllegalUse,
|
||||
throw FRC_MakeError(
|
||||
err::CommandIllegalUse,
|
||||
"Can not cancel a command that is part of a command group");
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ int Command::GetID() const {
|
||||
|
||||
void Command::SetTimeout(double timeout) {
|
||||
if (timeout < 0.0) {
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
} else {
|
||||
m_timeout = timeout;
|
||||
}
|
||||
@@ -185,21 +185,22 @@ bool Command::IsTimedOut() const {
|
||||
|
||||
bool Command::AssertUnlocked(const std::string& message) {
|
||||
if (m_locked) {
|
||||
std::string buf =
|
||||
message + " after being started or being added to a command group";
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse, buf);
|
||||
return false;
|
||||
throw FRC_MakeError(
|
||||
err::CommandIllegalUse,
|
||||
message +
|
||||
wpi::Twine{
|
||||
" after being started or being added to a command group"});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Command::SetParent(CommandGroup* parent) {
|
||||
if (parent == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "parent");
|
||||
throw FRC_MakeError(err::NullParameter, "parent");
|
||||
} else if (m_parent != nullptr) {
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse,
|
||||
"Can not give command to a command group after "
|
||||
"already being put in a command group");
|
||||
throw FRC_MakeError(err::CommandIllegalUse,
|
||||
"Can not give command to a command group after "
|
||||
"already being put in a command group");
|
||||
} else {
|
||||
LockChanges();
|
||||
m_parent = parent;
|
||||
|
||||
@@ -4,16 +4,15 @@
|
||||
|
||||
#include "frc/commands/CommandGroup.h"
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
CommandGroup::CommandGroup(const wpi::Twine& name) : Command(name) {}
|
||||
|
||||
void CommandGroup::AddSequential(Command* command) {
|
||||
if (command == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "command");
|
||||
return;
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
return;
|
||||
@@ -31,16 +30,14 @@ void CommandGroup::AddSequential(Command* command) {
|
||||
}
|
||||
|
||||
void CommandGroup::AddSequential(Command* command, double timeout) {
|
||||
if (command == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "command");
|
||||
return;
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
return;
|
||||
}
|
||||
if (timeout < 0.0) {
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
|
||||
return;
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
}
|
||||
|
||||
m_commands.emplace_back(command, CommandGroupEntry::kSequence_InSequence,
|
||||
@@ -56,8 +53,8 @@ void CommandGroup::AddSequential(Command* command, double timeout) {
|
||||
}
|
||||
|
||||
void CommandGroup::AddParallel(Command* command) {
|
||||
if (command == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "command");
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
return;
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
@@ -76,16 +73,14 @@ void CommandGroup::AddParallel(Command* command) {
|
||||
}
|
||||
|
||||
void CommandGroup::AddParallel(Command* command, double timeout) {
|
||||
if (command == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "command");
|
||||
return;
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
return;
|
||||
}
|
||||
if (timeout < 0.0) {
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
|
||||
return;
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
}
|
||||
|
||||
m_commands.emplace_back(command, CommandGroupEntry::kSequence_BranchChild,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/buttons/ButtonScheduler.h"
|
||||
#include "frc/commands/Command.h"
|
||||
#include "frc/commands/Subsystem.h"
|
||||
@@ -64,9 +64,8 @@ void Scheduler::AddButton(ButtonScheduler* button) {
|
||||
}
|
||||
|
||||
void Scheduler::RegisterSubsystem(Subsystem* subsystem) {
|
||||
if (subsystem == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "subsystem");
|
||||
return;
|
||||
if (!subsystem) {
|
||||
throw FRC_MakeError(err::NullParameter, "subsystem");
|
||||
}
|
||||
m_impl->subsystems.insert(subsystem);
|
||||
}
|
||||
@@ -109,8 +108,8 @@ void Scheduler::Run() {
|
||||
for (auto& addition : m_impl->additions) {
|
||||
// Check to make sure no adding during adding
|
||||
if (m_impl->adding) {
|
||||
wpi_setWPIErrorWithContext(IncompatibleState,
|
||||
"Can not start command from cancel method");
|
||||
FRC_ReportError(warn::IncompatibleState,
|
||||
"Can not start command from cancel method");
|
||||
} else {
|
||||
m_impl->ProcessCommandAddition(addition);
|
||||
}
|
||||
@@ -122,8 +121,8 @@ void Scheduler::Run() {
|
||||
for (auto& subsystem : m_impl->subsystems) {
|
||||
if (subsystem->GetCurrentCommand() == nullptr) {
|
||||
if (m_impl->adding) {
|
||||
wpi_setWPIErrorWithContext(IncompatibleState,
|
||||
"Can not start command from cancel method");
|
||||
FRC_ReportError(warn::IncompatibleState,
|
||||
"Can not start command from cancel method");
|
||||
} else {
|
||||
m_impl->ProcessCommandAddition(subsystem->GetDefaultCommand());
|
||||
}
|
||||
@@ -133,9 +132,8 @@ void Scheduler::Run() {
|
||||
}
|
||||
|
||||
void Scheduler::Remove(Command* command) {
|
||||
if (command == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "command");
|
||||
return;
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
}
|
||||
|
||||
m_impl->Remove(command);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "frc/commands/Subsystem.h"
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/commands/Command.h"
|
||||
#include "frc/commands/Scheduler.h"
|
||||
#include "frc/livewindow/LiveWindow.h"
|
||||
@@ -24,9 +24,8 @@ void Subsystem::SetDefaultCommand(Command* command) {
|
||||
} else {
|
||||
const auto& reqs = command->GetRequirements();
|
||||
if (std::find(reqs.begin(), reqs.end(), this) == reqs.end()) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
CommandIllegalUse, "A default command must require the subsystem");
|
||||
return;
|
||||
throw FRC_MakeError(err::CommandIllegalUse,
|
||||
"A default command must require the subsystem");
|
||||
}
|
||||
|
||||
m_defaultCommand = command;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <wpi/SmallPtrSet.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/commands/Subsystem.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
@@ -43,9 +42,7 @@ class CommandGroup;
|
||||
* @see CommandGroup
|
||||
* @see Subsystem
|
||||
*/
|
||||
class Command : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Command> {
|
||||
class Command : public Sendable, public SendableHelper<Command> {
|
||||
friend class CommandGroup;
|
||||
friend class Scheduler;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -16,9 +15,7 @@ class ButtonScheduler;
|
||||
class Command;
|
||||
class Subsystem;
|
||||
|
||||
class Scheduler : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Scheduler> {
|
||||
class Scheduler : public Sendable, public SendableHelper<Scheduler> {
|
||||
public:
|
||||
/**
|
||||
* Returns the Scheduler, creating it if one does not exist.
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -18,9 +17,7 @@ namespace frc {
|
||||
|
||||
class Command;
|
||||
|
||||
class Subsystem : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Subsystem> {
|
||||
class Subsystem : public Sendable, public SendableHelper<Subsystem> {
|
||||
friend class Scheduler;
|
||||
|
||||
public:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <hal/PWM.h>
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -18,13 +18,13 @@ AddressableLED::AddressableLED(int port) {
|
||||
int32_t status = 0;
|
||||
|
||||
m_pwmHandle = HAL_InitializePWMPort(HAL_GetPort(port), &status);
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumPWMChannels(), port);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{port});
|
||||
if (m_pwmHandle == HAL_kInvalidHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_handle = HAL_InitializeAddressableLED(m_pwmHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{port});
|
||||
if (m_handle == HAL_kInvalidHandle) {
|
||||
HAL_FreePWMPort(m_pwmHandle, &status);
|
||||
}
|
||||
@@ -36,12 +36,13 @@ AddressableLED::~AddressableLED() {
|
||||
HAL_FreeAddressableLED(m_handle);
|
||||
int32_t status = 0;
|
||||
HAL_FreePWMPort(m_pwmHandle, &status);
|
||||
FRC_ReportError(status, "FreePWM");
|
||||
}
|
||||
|
||||
void AddressableLED::SetLength(int length) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAddressableLEDLength(m_handle, length, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "length " + wpi::Twine{length});
|
||||
}
|
||||
|
||||
static_assert(sizeof(AddressableLED::LEDData) == sizeof(HAL_AddressableLEDData),
|
||||
@@ -51,14 +52,14 @@ void AddressableLED::SetData(wpi::ArrayRef<LEDData> ledData) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetData");
|
||||
}
|
||||
|
||||
void AddressableLED::SetData(std::initializer_list<LEDData> ledData) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetData");
|
||||
}
|
||||
|
||||
void AddressableLED::SetBitTiming(units::nanosecond_t lowTime0,
|
||||
@@ -69,25 +70,25 @@ void AddressableLED::SetBitTiming(units::nanosecond_t lowTime0,
|
||||
HAL_SetAddressableLEDBitTiming(
|
||||
m_handle, lowTime0.to<int32_t>(), highTime0.to<int32_t>(),
|
||||
lowTime1.to<int32_t>(), highTime1.to<int32_t>(), &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetBitTiming");
|
||||
}
|
||||
|
||||
void AddressableLED::SetSyncTime(units::microsecond_t syncTime) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAddressableLEDSyncTime(m_handle, syncTime.to<int32_t>(), &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSyncTime");
|
||||
}
|
||||
|
||||
void AddressableLED::Start() {
|
||||
int32_t status = 0;
|
||||
HAL_StartAddressableLEDOutput(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Start");
|
||||
}
|
||||
|
||||
void AddressableLED::Stop() {
|
||||
int32_t status = 0;
|
||||
HAL_StopAddressableLEDOutput(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Stop");
|
||||
}
|
||||
|
||||
void AddressableLED::LEDData::SetHSV(int h, int s, int v) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/Base.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -20,20 +20,18 @@ AnalogAccelerometer::AnalogAccelerometer(int channel)
|
||||
|
||||
AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel)
|
||||
: m_analogInput(channel, NullDeleter<AnalogInput>()) {
|
||||
if (channel == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitAccelerometer();
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
}
|
||||
InitAccelerometer();
|
||||
}
|
||||
|
||||
AnalogAccelerometer::AnalogAccelerometer(std::shared_ptr<AnalogInput> channel)
|
||||
: m_analogInput(channel) {
|
||||
if (channel == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitAccelerometer();
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
}
|
||||
InitAccelerometer();
|
||||
}
|
||||
|
||||
double AnalogAccelerometer::GetAcceleration() const {
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/Base.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -31,12 +31,11 @@ AnalogGyro::AnalogGyro(AnalogInput* channel)
|
||||
|
||||
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel)
|
||||
: m_analog(channel) {
|
||||
if (channel == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitGyro();
|
||||
Calibrate();
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
}
|
||||
InitGyro();
|
||||
Calibrate();
|
||||
}
|
||||
|
||||
AnalogGyro::AnalogGyro(int channel, int center, double offset)
|
||||
@@ -47,20 +46,15 @@ AnalogGyro::AnalogGyro(int channel, int center, double offset)
|
||||
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
|
||||
double offset)
|
||||
: m_analog(channel) {
|
||||
if (channel == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitGyro();
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
|
||||
offset, center, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_gyroHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
Reset();
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
}
|
||||
InitGyro();
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
|
||||
offset, center, &status);
|
||||
FRC_CheckErrorStatus(status, "SetAnalogGyroParameters");
|
||||
Reset();
|
||||
}
|
||||
|
||||
AnalogGyro::~AnalogGyro() {
|
||||
@@ -68,42 +62,30 @@ AnalogGyro::~AnalogGyro() {
|
||||
}
|
||||
|
||||
double AnalogGyro::GetAngle() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetAngle");
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogGyro::GetRate() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetRate");
|
||||
return value;
|
||||
}
|
||||
|
||||
int AnalogGyro::GetCenter() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetCenter");
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogGyro::GetOffset() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetOffset");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -111,57 +93,35 @@ void AnalogGyro::SetSensitivity(double voltsPerDegreePerSecond) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle,
|
||||
voltsPerDegreePerSecond, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSensitivity");
|
||||
}
|
||||
|
||||
void AnalogGyro::SetDeadband(double volts) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetDeadband");
|
||||
}
|
||||
|
||||
void AnalogGyro::Reset() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetAnalogGyro(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
}
|
||||
|
||||
void AnalogGyro::InitGyro() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_gyroHandle == HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
m_gyroHandle = HAL_InitializeAnalogGyro(m_analog->m_port, &status);
|
||||
if (status == PARAMETER_OUT_OF_RANGE) {
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange,
|
||||
" channel (must be accumulator channel)");
|
||||
m_analog = nullptr;
|
||||
m_gyroHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_analog = nullptr;
|
||||
m_gyroHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
throw FRC_MakeError(err::ParameterOutOfRange,
|
||||
"channel must be accumulator channel");
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "InitializeAnalogGyro");
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetupAnalogGyro(m_gyroHandle, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_analog = nullptr;
|
||||
m_gyroHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "SetupAnalogGyro");
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel() + 1);
|
||||
|
||||
@@ -170,12 +130,9 @@ void AnalogGyro::InitGyro() {
|
||||
}
|
||||
|
||||
void AnalogGyro::Calibrate() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_CalibrateAnalogGyro(m_gyroHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Calibrate");
|
||||
}
|
||||
|
||||
std::shared_ptr<AnalogInput> AnalogGyro::GetAnalogInput() const {
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -20,9 +20,8 @@ using namespace frc;
|
||||
|
||||
AnalogInput::AnalogInput(int channel) {
|
||||
if (!SensorUtil::CheckAnalogInputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Analog Input " + wpi::Twine(channel));
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Analog Input " + wpi::Twine{channel});
|
||||
}
|
||||
|
||||
m_channel = channel;
|
||||
@@ -30,12 +29,7 @@ AnalogInput::AnalogInput(int channel) {
|
||||
HAL_PortHandle port = HAL_GetPort(channel);
|
||||
int32_t status = 0;
|
||||
m_port = HAL_InitializeAnalogInputPort(port, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumAnalogInputs(), channel);
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_port = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{channel});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogChannel, channel + 1);
|
||||
|
||||
@@ -47,210 +41,151 @@ AnalogInput::~AnalogInput() {
|
||||
}
|
||||
|
||||
int AnalogInput::GetValue() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogValue(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return value;
|
||||
}
|
||||
|
||||
int AnalogInput::GetAverageValue() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogAverageValue(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogInput::GetVoltage() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogVoltage(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double AnalogInput::GetAverageVoltage() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogAverageVoltage(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return voltage;
|
||||
}
|
||||
|
||||
int AnalogInput::GetChannel() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void AnalogInput::SetAverageBits(int bits) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogAverageBits(m_port, bits, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
int AnalogInput::GetAverageBits() const {
|
||||
int32_t status = 0;
|
||||
int averageBits = HAL_GetAnalogAverageBits(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return averageBits;
|
||||
}
|
||||
|
||||
void AnalogInput::SetOversampleBits(int bits) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOversampleBits(m_port, bits, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
int AnalogInput::GetOversampleBits() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return oversampleBits;
|
||||
}
|
||||
|
||||
int AnalogInput::GetLSBWeight() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return lsbWeight;
|
||||
}
|
||||
|
||||
int AnalogInput::GetOffset() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int offset = HAL_GetAnalogOffset(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return offset;
|
||||
}
|
||||
|
||||
bool AnalogInput::IsAccumulatorChannel() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool isAccum = HAL_IsAccumulatorChannel(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return isAccum;
|
||||
}
|
||||
|
||||
void AnalogInput::InitAccumulator() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_accumulatorOffset = 0;
|
||||
int32_t status = 0;
|
||||
HAL_InitAccumulator(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_accumulatorOffset = initialValue;
|
||||
}
|
||||
|
||||
void AnalogInput::ResetAccumulator() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetAccumulator(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
|
||||
if (!StatusIsFatal()) {
|
||||
// Wait until the next sample, so the next call to GetAccumulator*()
|
||||
// won't have old values.
|
||||
const double sampleTime = 1.0 / GetSampleRate();
|
||||
const double overSamples = 1 << GetOversampleBits();
|
||||
const double averageSamples = 1 << GetAverageBits();
|
||||
Wait(sampleTime * overSamples * averageSamples);
|
||||
}
|
||||
// Wait until the next sample, so the next call to GetAccumulator*()
|
||||
// won't have old values.
|
||||
const double sampleTime = 1.0 / GetSampleRate();
|
||||
const double overSamples = 1 << GetOversampleBits();
|
||||
const double averageSamples = 1 << GetAverageBits();
|
||||
Wait(sampleTime * overSamples * averageSamples);
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorCenter(int center) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorCenter(m_port, center, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorDeadband(int deadband) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorDeadband(m_port, deadband, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int64_t value = HAL_GetAccumulatorValue(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return value + m_accumulatorOffset;
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int64_t count = HAL_GetAccumulatorCount(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
return count;
|
||||
}
|
||||
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_GetAccumulatorOutput(m_port, &value, &count, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
value += m_accumulatorOffset;
|
||||
}
|
||||
|
||||
void AnalogInput::SetSampleRate(double samplesPerSecond) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogSampleRate(samplesPerSecond, &status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSampleRate");
|
||||
}
|
||||
|
||||
double AnalogInput::GetSampleRate() {
|
||||
int32_t status = 0;
|
||||
double sampleRate = HAL_GetAnalogSampleRate(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetSampleRate");
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -21,11 +21,8 @@ using namespace frc;
|
||||
|
||||
AnalogOutput::AnalogOutput(int channel) {
|
||||
if (!SensorUtil::CheckAnalogOutputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"analog output " + wpi::Twine(channel));
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_port = HAL_kInvalidHandle;
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"analog output " + wpi::Twine(channel));
|
||||
}
|
||||
|
||||
m_channel = channel;
|
||||
@@ -33,12 +30,7 @@ AnalogOutput::AnalogOutput(int channel) {
|
||||
HAL_PortHandle port = HAL_GetPort(m_channel);
|
||||
int32_t status = 0;
|
||||
m_port = HAL_InitializeAnalogOutputPort(port, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumAnalogOutputs(), channel);
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_port = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "analog output " + wpi::Twine(channel));
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogOutput, m_channel + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "AnalogOutput", m_channel);
|
||||
@@ -51,16 +43,13 @@ AnalogOutput::~AnalogOutput() {
|
||||
void AnalogOutput::SetVoltage(double voltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOutput(m_port, voltage, &status);
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetVoltage");
|
||||
}
|
||||
|
||||
double AnalogOutput::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogOutput(m_port, &status);
|
||||
|
||||
wpi_setHALError(status);
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetVoltage");
|
||||
return voltage;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/Base.h"
|
||||
#include "frc/DutyCycle.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -26,11 +26,7 @@ AnalogTrigger::AnalogTrigger(AnalogInput* input) {
|
||||
m_analogInput = input;
|
||||
int32_t status = 0;
|
||||
m_trigger = HAL_InitializeAnalogTrigger(input->m_port, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_trigger = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "InitializeAnalogTrigger");
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
@@ -41,11 +37,7 @@ AnalogTrigger::AnalogTrigger(DutyCycle* input) {
|
||||
m_dutyCycle = input;
|
||||
int32_t status = 0;
|
||||
m_trigger = HAL_InitializeAnalogTriggerDutyCycle(input->m_handle, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_trigger = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "InitializeAnalogTriggerDutyCycle");
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
@@ -55,6 +47,7 @@ AnalogTrigger::AnalogTrigger(DutyCycle* input) {
|
||||
AnalogTrigger::~AnalogTrigger() {
|
||||
int32_t status = 0;
|
||||
HAL_CleanAnalogTrigger(m_trigger, &status);
|
||||
FRC_ReportError(status, "CleanAnalogTrigger");
|
||||
|
||||
if (m_ownsAnalog) {
|
||||
delete m_analogInput;
|
||||
@@ -62,16 +55,13 @@ AnalogTrigger::~AnalogTrigger() {
|
||||
}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(AnalogTrigger&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableHelper(std::move(rhs)),
|
||||
m_trigger(std::move(rhs.m_trigger)) {
|
||||
: SendableHelper(std::move(rhs)), m_trigger(std::move(rhs.m_trigger)) {
|
||||
std::swap(m_analogInput, rhs.m_analogInput);
|
||||
std::swap(m_dutyCycle, rhs.m_dutyCycle);
|
||||
std::swap(m_ownsAnalog, rhs.m_ownsAnalog);
|
||||
}
|
||||
|
||||
AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableHelper::operator=(std::move(rhs));
|
||||
|
||||
m_trigger = std::move(rhs.m_trigger);
|
||||
@@ -83,85 +73,58 @@ AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) {
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsVoltage(double lower, double upper) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetLimitsVoltage");
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsDutyCycle(double lower, double upper) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsDutyCycle(m_trigger, lower, upper, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetLimitsDutyCycle");
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsRaw(int lower, int upper) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetLimitsRaw");
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetAveraged(bool useAveragedValue) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetAveraged");
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetFiltered(bool useFilteredValue) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetFiltered");
|
||||
}
|
||||
|
||||
int AnalogTrigger::GetIndex() const {
|
||||
if (StatusIsFatal()) {
|
||||
return -1;
|
||||
}
|
||||
int32_t status = 0;
|
||||
auto ret = HAL_GetAnalogTriggerFPGAIndex(m_trigger, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetIndex");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetInWindow() {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetInWindow");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetTriggerState() {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetTriggerState");
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<AnalogTriggerOutput> AnalogTrigger::CreateOutput(
|
||||
AnalogTriggerType type) const {
|
||||
if (StatusIsFatal()) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::shared_ptr<AnalogTriggerOutput>(
|
||||
new AnalogTriggerOutput(*this, type), NullDeleter<AnalogTriggerOutput>());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/AnalogTrigger.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -16,7 +16,7 @@ bool AnalogTriggerOutput::Get() const {
|
||||
bool result = HAL_GetAnalogTriggerOutput(
|
||||
m_trigger->m_trigger, static_cast<HAL_AnalogTriggerType>(m_outputType),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <hal/Accelerometer.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -23,8 +23,8 @@ BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
|
||||
|
||||
void BuiltInAccelerometer::SetRange(Range range) {
|
||||
if (range == kRange_16G) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ParameterOutOfRange, "16G range not supported (use k2G, k4G, or k8G)");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange,
|
||||
"16G range not supported (use k2G, k4G, or k8G)");
|
||||
}
|
||||
|
||||
HAL_SetAccelerometerActive(false);
|
||||
|
||||
@@ -11,17 +11,15 @@
|
||||
#include <hal/Errors.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
CAN::CAN(int deviceId) {
|
||||
int32_t status = 0;
|
||||
m_handle =
|
||||
HAL_InitializeCAN(kTeamManufacturer, deviceId, kTeamDeviceType, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_handle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "device id " + wpi::Twine{deviceId});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_CAN, deviceId + 1);
|
||||
}
|
||||
@@ -31,19 +29,14 @@ CAN::CAN(int deviceId, int deviceManufacturer, int deviceType) {
|
||||
m_handle = HAL_InitializeCAN(
|
||||
static_cast<HAL_CANManufacturer>(deviceManufacturer), deviceId,
|
||||
static_cast<HAL_CANDeviceType>(deviceType), &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_handle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "device id " + wpi::Twine{deviceId} + " mfg " +
|
||||
wpi::Twine{deviceManufacturer} + " type " +
|
||||
wpi::Twine{deviceType});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_CAN, deviceId + 1);
|
||||
}
|
||||
|
||||
CAN::~CAN() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_handle != HAL_kInvalidHandle) {
|
||||
HAL_CleanCAN(m_handle);
|
||||
m_handle = HAL_kInvalidHandle;
|
||||
@@ -53,20 +46,20 @@ CAN::~CAN() {
|
||||
void CAN::WritePacket(const uint8_t* data, int length, int apiId) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteCANPacket(m_handle, data, length, apiId, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "WritePacket");
|
||||
}
|
||||
|
||||
void CAN::WritePacketRepeating(const uint8_t* data, int length, int apiId,
|
||||
int repeatMs) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteCANPacketRepeating(m_handle, data, length, apiId, repeatMs, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "WritePacketRepeating");
|
||||
}
|
||||
|
||||
void CAN::WriteRTRFrame(int length, int apiId) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteCANRTRFrame(m_handle, length, apiId, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "WriteRTRFrame");
|
||||
}
|
||||
|
||||
int CAN::WritePacketNoError(const uint8_t* data, int length, int apiId) {
|
||||
@@ -91,7 +84,7 @@ int CAN::WriteRTRFrameNoError(int length, int apiId) {
|
||||
void CAN::StopPacketRepeating(int apiId) {
|
||||
int32_t status = 0;
|
||||
HAL_StopCANPacketRepeating(m_handle, apiId, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "StopPacketRepeating");
|
||||
}
|
||||
|
||||
bool CAN::ReadPacketNew(int apiId, CANData* data) {
|
||||
@@ -102,7 +95,7 @@ bool CAN::ReadPacketNew(int apiId, CANData* data) {
|
||||
return false;
|
||||
}
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ReadPacketNew");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -117,7 +110,7 @@ bool CAN::ReadPacketLatest(int apiId, CANData* data) {
|
||||
return false;
|
||||
}
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ReadPacketLatest");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -133,7 +126,7 @@ bool CAN::ReadPacketTimeout(int apiId, int timeoutMs, CANData* data) {
|
||||
return false;
|
||||
}
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ReadPacketTimeout");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/Solenoid.h>
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -18,10 +18,7 @@ using namespace frc;
|
||||
Compressor::Compressor(int pcmID) : m_module(pcmID) {
|
||||
int32_t status = 0;
|
||||
m_compressorHandle = HAL_InitializeCompressor(m_module, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumPCMModules(), pcmID);
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
SetClosedLoopControl(true);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Compressor, pcmID + 1);
|
||||
@@ -29,204 +26,96 @@ Compressor::Compressor(int pcmID) : m_module(pcmID) {
|
||||
}
|
||||
|
||||
void Compressor::Start() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetClosedLoopControl(true);
|
||||
}
|
||||
|
||||
void Compressor::Stop() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetClosedLoopControl(false);
|
||||
}
|
||||
|
||||
bool Compressor::Enabled() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressor(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value = HAL_GetCompressor(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetPressureSwitchValue() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressorPressureSwitch(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value = HAL_GetCompressorPressureSwitch(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
double Compressor::GetCompressorCurrent() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value;
|
||||
|
||||
value = HAL_GetCompressorCurrent(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
double value = HAL_GetCompressorCurrent(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
void Compressor::SetClosedLoopControl(bool on) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_SetCompressorClosedLoopControl(m_compressorHandle, on, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
}
|
||||
|
||||
bool Compressor::GetClosedLoopControl() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressorClosedLoopControl(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value = HAL_GetCompressorClosedLoopControl(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorCurrentTooHighFault() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value =
|
||||
HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value =
|
||||
bool value =
|
||||
HAL_GetCompressorCurrentTooHighStickyFault(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorShortedStickyFault() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorShortedFault() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressorShortedFault(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value = HAL_GetCompressorShortedFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorNotConnectedStickyFault() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value =
|
||||
HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorNotConnectedFault() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
bool value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
return value;
|
||||
}
|
||||
|
||||
void Compressor::ClearAllPCMStickyFaults() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_ClearAllPCMStickyFaults(m_module, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
}
|
||||
|
||||
int Compressor::GetModule() const {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "frc/AnalogTrigger.h"
|
||||
#include "frc/Base.h"
|
||||
#include "frc/DigitalInput.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -22,7 +22,7 @@ Counter::Counter(Mode mode) {
|
||||
int32_t status = 0;
|
||||
m_counter = HAL_InitializeCounter(static_cast<HAL_Counter_Mode>(mode),
|
||||
&m_index, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitializeCounter");
|
||||
|
||||
SetMaxPeriod(0.5);
|
||||
|
||||
@@ -64,10 +64,8 @@ Counter::Counter(EncodingType encodingType,
|
||||
std::shared_ptr<DigitalSource> downSource, bool inverted)
|
||||
: Counter(kExternalDirection) {
|
||||
if (encodingType != k1X && encodingType != k2X) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ParameterOutOfRange,
|
||||
"Counter only supports 1X and 2X quadrature decoding.");
|
||||
return;
|
||||
throw FRC_MakeError(err::ParameterOutOfRange,
|
||||
"Counter only supports 1X and 2X quadrature decoding.");
|
||||
}
|
||||
SetUpSource(upSource);
|
||||
SetDownSource(downSource);
|
||||
@@ -81,22 +79,23 @@ Counter::Counter(EncodingType encodingType,
|
||||
HAL_SetCounterAverageSize(m_counter, 2, &status);
|
||||
}
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Counter constructor");
|
||||
SetDownSourceEdge(inverted, true);
|
||||
}
|
||||
|
||||
Counter::~Counter() {
|
||||
SetUpdateWhenEmpty(true);
|
||||
try {
|
||||
SetUpdateWhenEmpty(true);
|
||||
} catch (const RuntimeError& e) {
|
||||
e.Report();
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_FreeCounter(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_ReportError(status, "Counter destructor");
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(int channel) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetUpSource(std::make_shared<DigitalInput>(channel));
|
||||
SendableRegistry::GetInstance().AddChild(this, m_upSource.get());
|
||||
}
|
||||
@@ -110,9 +109,6 @@ void Counter::SetUpSource(AnalogTrigger* analogTrigger,
|
||||
|
||||
void Counter::SetUpSource(std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetUpSource(analogTrigger->CreateOutput(triggerType));
|
||||
}
|
||||
|
||||
@@ -122,20 +118,13 @@ void Counter::SetUpSource(DigitalSource* source) {
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(std::shared_ptr<DigitalSource> source) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_upSource = source;
|
||||
if (m_upSource->StatusIsFatal()) {
|
||||
CloneError(*m_upSource);
|
||||
} else {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpSource(m_counter, source->GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpSource(m_counter, source->GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetUpSource");
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(DigitalSource& source) {
|
||||
@@ -144,33 +133,24 @@ void Counter::SetUpSource(DigitalSource& source) {
|
||||
}
|
||||
|
||||
void Counter::SetUpSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_upSource == nullptr) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
NullParameter,
|
||||
throw FRC_MakeError(
|
||||
err::NullParameter,
|
||||
"Must set non-nullptr UpSource before setting UpSourceEdge");
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpSourceEdge(m_counter, risingEdge, fallingEdge, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetUpSourceEdge");
|
||||
}
|
||||
|
||||
void Counter::ClearUpSource() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_upSource.reset();
|
||||
int32_t status = 0;
|
||||
HAL_ClearCounterUpSource(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ClearUpSource");
|
||||
}
|
||||
|
||||
void Counter::SetDownSource(int channel) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetDownSource(std::make_shared<DigitalInput>(channel));
|
||||
SendableRegistry::GetInstance().AddChild(this, m_downSource.get());
|
||||
}
|
||||
@@ -184,9 +164,6 @@ void Counter::SetDownSource(AnalogTrigger* analogTrigger,
|
||||
|
||||
void Counter::SetDownSource(std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
SetDownSource(analogTrigger->CreateOutput(triggerType));
|
||||
}
|
||||
|
||||
@@ -201,106 +178,82 @@ void Counter::SetDownSource(DigitalSource& source) {
|
||||
}
|
||||
|
||||
void Counter::SetDownSource(std::shared_ptr<DigitalSource> source) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_downSource = source;
|
||||
if (m_downSource->StatusIsFatal()) {
|
||||
CloneError(*m_downSource);
|
||||
} else {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterDownSource(m_counter, source->GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterDownSource(m_counter, source->GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetDownSource");
|
||||
}
|
||||
|
||||
void Counter::SetDownSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_downSource == nullptr) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
NullParameter,
|
||||
throw FRC_MakeError(
|
||||
err::NullParameter,
|
||||
"Must set non-nullptr DownSource before setting DownSourceEdge");
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterDownSourceEdge(m_counter, risingEdge, fallingEdge, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetDownSourceEdge");
|
||||
}
|
||||
|
||||
void Counter::ClearDownSource() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_downSource.reset();
|
||||
int32_t status = 0;
|
||||
HAL_ClearCounterDownSource(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ClearDownSource");
|
||||
}
|
||||
|
||||
void Counter::SetUpDownCounterMode() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpDownMode(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetUpDownCounterMode");
|
||||
}
|
||||
|
||||
void Counter::SetExternalDirectionMode() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterExternalDirectionMode(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetExternalDirectionMode");
|
||||
}
|
||||
|
||||
void Counter::SetSemiPeriodMode(bool highSemiPeriod) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterSemiPeriodMode(m_counter, highSemiPeriod, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status,
|
||||
"SetSemiPeriodMode to " + wpi::Twine{highSemiPeriod ? "true" : "false"});
|
||||
}
|
||||
|
||||
void Counter::SetPulseLengthMode(double threshold) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterPulseLengthMode(m_counter, threshold, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetPulseLengthMode");
|
||||
}
|
||||
|
||||
void Counter::SetReverseDirection(bool reverseDirection) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterReverseDirection(m_counter, reverseDirection, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status,
|
||||
"SetReverseDirection to " +
|
||||
wpi::Twine{reverseDirection ? "true" : "false"});
|
||||
}
|
||||
|
||||
void Counter::SetSamplesToAverage(int samplesToAverage) {
|
||||
if (samplesToAverage < 1 || samplesToAverage > 127) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ParameterOutOfRange,
|
||||
"Average counter values must be between 1 and 127");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange,
|
||||
"Average counter values must be between 1 and 127");
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterSamplesToAverage(m_counter, samplesToAverage, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSamplesToAverage to " + wpi::Twine{samplesToAverage});
|
||||
}
|
||||
|
||||
int Counter::GetSamplesToAverage() const {
|
||||
int32_t status = 0;
|
||||
int samples = HAL_GetCounterSamplesToAverage(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetSamplesToAverage");
|
||||
return samples;
|
||||
}
|
||||
|
||||
@@ -309,69 +262,48 @@ int Counter::GetFPGAIndex() const {
|
||||
}
|
||||
|
||||
int Counter::Get() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetCounter(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Counter::Reset() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetCounter(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
}
|
||||
|
||||
double Counter::GetPeriod() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetCounterPeriod(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetPeriod");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Counter::SetMaxPeriod(double maxPeriod) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterMaxPeriod(m_counter, maxPeriod, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetMaxPeriod");
|
||||
}
|
||||
|
||||
void Counter::SetUpdateWhenEmpty(bool enabled) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpdateWhenEmpty(m_counter, enabled, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetUpdateWhenEmpty");
|
||||
}
|
||||
|
||||
bool Counter::GetStopped() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCounterStopped(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetStopped");
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Counter::GetDirection() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCounterDirection(m_counter, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetDirection");
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,21 +4,22 @@
|
||||
|
||||
#include "frc/DMA.h"
|
||||
|
||||
#include <frc/AnalogInput.h>
|
||||
#include <frc/Counter.h>
|
||||
#include <frc/DigitalSource.h>
|
||||
#include <frc/DutyCycle.h>
|
||||
#include <frc/Encoder.h>
|
||||
|
||||
#include <hal/DMA.h>
|
||||
#include <hal/HALBase.h>
|
||||
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/DutyCycle.h"
|
||||
#include "frc/Encoder.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
DMA::DMA() {
|
||||
int32_t status = 0;
|
||||
dmaHandle = HAL_InitializeDMA(&status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "InitializeDMA");
|
||||
}
|
||||
|
||||
DMA::~DMA() {
|
||||
@@ -28,68 +29,68 @@ DMA::~DMA() {
|
||||
void DMA::SetPause(bool pause) {
|
||||
int32_t status = 0;
|
||||
HAL_SetDMAPause(dmaHandle, pause, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "SetPause");
|
||||
}
|
||||
|
||||
void DMA::SetRate(int cycles) {
|
||||
int32_t status = 0;
|
||||
HAL_SetDMARate(dmaHandle, cycles, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "SetRate");
|
||||
}
|
||||
|
||||
void DMA::AddEncoder(const Encoder* encoder) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAEncoder(dmaHandle, encoder->m_encoder, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddEncoder");
|
||||
}
|
||||
|
||||
void DMA::AddEncoderPeriod(const Encoder* encoder) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAEncoderPeriod(dmaHandle, encoder->m_encoder, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddEncoderPeriod");
|
||||
}
|
||||
|
||||
void DMA::AddCounter(const Counter* counter) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMACounter(dmaHandle, counter->m_counter, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddCounter");
|
||||
}
|
||||
|
||||
void DMA::AddCounterPeriod(const Counter* counter) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMACounterPeriod(dmaHandle, counter->m_counter, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddCounterPeriod");
|
||||
}
|
||||
|
||||
void DMA::AddDigitalSource(const DigitalSource* digitalSource) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMADigitalSource(dmaHandle, digitalSource->GetPortHandleForRouting(),
|
||||
&status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddDigitalSource");
|
||||
}
|
||||
|
||||
void DMA::AddDutyCycle(const DutyCycle* dutyCycle) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMADutyCycle(dmaHandle, dutyCycle->m_handle, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddDutyCycle");
|
||||
}
|
||||
|
||||
void DMA::AddAnalogInput(const AnalogInput* analogInput) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAAnalogInput(dmaHandle, analogInput->m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddAnalogInput");
|
||||
}
|
||||
|
||||
void DMA::AddAveragedAnalogInput(const AnalogInput* analogInput) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAAveragedAnalogInput(dmaHandle, analogInput->m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddAveragedAnalogInput");
|
||||
}
|
||||
|
||||
void DMA::AddAnalogAccumulator(const AnalogInput* analogInput) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAAnalogAccumulator(dmaHandle, analogInput->m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "AddAnalogAccumulator");
|
||||
}
|
||||
|
||||
void DMA::SetExternalTrigger(DigitalSource* source, bool rising, bool falling) {
|
||||
@@ -98,17 +99,17 @@ void DMA::SetExternalTrigger(DigitalSource* source, bool rising, bool falling) {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
rising, falling, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "SetExternalTrigger");
|
||||
}
|
||||
|
||||
void DMA::StartDMA(int queueDepth) {
|
||||
int32_t status = 0;
|
||||
HAL_StartDMA(dmaHandle, queueDepth, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "StartDMA");
|
||||
}
|
||||
|
||||
void DMA::StopDMA() {
|
||||
int32_t status = 0;
|
||||
HAL_StopDMA(dmaHandle, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
FRC_CheckErrorStatus(status, "StopDMA");
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/Encoder.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -29,7 +29,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
auto index =
|
||||
std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false);
|
||||
wpi_assert(index != m_filterAllocated.end());
|
||||
FRC_Assert(index != m_filterAllocated.end());
|
||||
|
||||
m_channelIndex = std::distance(m_filterAllocated.begin(), index);
|
||||
*index = true;
|
||||
@@ -48,12 +48,11 @@ DigitalGlitchFilter::~DigitalGlitchFilter() {
|
||||
}
|
||||
|
||||
DigitalGlitchFilter::DigitalGlitchFilter(DigitalGlitchFilter&& rhs)
|
||||
: ErrorBase(std::move(rhs)), SendableHelper(std::move(rhs)) {
|
||||
: SendableHelper(std::move(rhs)) {
|
||||
std::swap(m_channelIndex, rhs.m_channelIndex);
|
||||
}
|
||||
|
||||
DigitalGlitchFilter& DigitalGlitchFilter::operator=(DigitalGlitchFilter&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableHelper::operator=(std::move(rhs));
|
||||
|
||||
std::swap(m_channelIndex, rhs.m_channelIndex);
|
||||
@@ -71,35 +70,31 @@ void DigitalGlitchFilter::DoAdd(DigitalSource* input, int requestedIndex) {
|
||||
if (input) {
|
||||
// We don't support GlitchFilters on AnalogTriggers.
|
||||
if (input->IsAnalogTrigger()) {
|
||||
wpi_setErrorWithContext(
|
||||
throw FRC_MakeError(
|
||||
-1, "Analog Triggers not supported for DigitalGlitchFilters");
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetFilterSelect(input->GetPortHandleForRouting(), requestedIndex,
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status,
|
||||
"requested index " + wpi::Twine{requestedIndex});
|
||||
|
||||
// Validate that we set it correctly.
|
||||
int actualIndex =
|
||||
HAL_GetFilterSelect(input->GetPortHandleForRouting(), &status);
|
||||
wpi_assertEqual(actualIndex, requestedIndex);
|
||||
FRC_CheckErrorStatus(status,
|
||||
"requested index " + wpi::Twine{requestedIndex});
|
||||
FRC_Assert(actualIndex == requestedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::Add(Encoder* input) {
|
||||
Add(input->m_aSource.get());
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
Add(input->m_bSource.get());
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::Add(Counter* input) {
|
||||
Add(input->m_upSource.get());
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
Add(input->m_downSource.get());
|
||||
}
|
||||
|
||||
@@ -109,24 +104,18 @@ void DigitalGlitchFilter::Remove(DigitalSource* input) {
|
||||
|
||||
void DigitalGlitchFilter::Remove(Encoder* input) {
|
||||
Remove(input->m_aSource.get());
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
Remove(input->m_bSource.get());
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::Remove(Counter* input) {
|
||||
Remove(input->m_upSource.get());
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
Remove(input->m_downSource.get());
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::SetPeriodCycles(int fpgaCycles) {
|
||||
int32_t status = 0;
|
||||
HAL_SetFilterPeriod(m_channelIndex, fpgaCycles, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) {
|
||||
@@ -134,25 +123,20 @@ void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) {
|
||||
int fpgaCycles =
|
||||
nanoseconds * HAL_GetSystemClockTicksPerMicrosecond() / 4 / 1000;
|
||||
HAL_SetFilterPeriod(m_channelIndex, fpgaCycles, &status);
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
}
|
||||
|
||||
int DigitalGlitchFilter::GetPeriodCycles() {
|
||||
int32_t status = 0;
|
||||
int fpgaCycles = HAL_GetFilterPeriod(m_channelIndex, &status);
|
||||
|
||||
wpi_setHALError(status);
|
||||
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
return fpgaCycles;
|
||||
}
|
||||
|
||||
uint64_t DigitalGlitchFilter::GetPeriodNanoSeconds() {
|
||||
int32_t status = 0;
|
||||
int fpgaCycles = HAL_GetFilterPeriod(m_channelIndex, &status);
|
||||
|
||||
wpi_setHALError(status);
|
||||
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
return static_cast<uint64_t>(fpgaCycles) * 1000L /
|
||||
static_cast<uint64_t>(HAL_GetSystemClockTicksPerMicrosecond() / 4);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -20,40 +20,27 @@ using namespace frc;
|
||||
|
||||
DigitalInput::DigitalInput(int channel) {
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Digital Channel " + wpi::Twine(channel));
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Digital Channel " + wpi::Twine{channel});
|
||||
}
|
||||
m_channel = channel;
|
||||
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), true, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumDigitalChannels(), channel);
|
||||
m_handle = HAL_kInvalidHandle;
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{channel});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalInput, channel + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "DigitalInput", channel);
|
||||
}
|
||||
|
||||
DigitalInput::~DigitalInput() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
HAL_FreeDIOPort(m_handle);
|
||||
}
|
||||
|
||||
bool DigitalInput::Get() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetDIO(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -21,54 +21,40 @@ using namespace frc;
|
||||
DigitalOutput::DigitalOutput(int channel) {
|
||||
m_pwmGenerator = HAL_kInvalidHandle;
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Digital Channel " + wpi::Twine(channel));
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Digital Channel " + wpi::Twine{channel});
|
||||
}
|
||||
m_channel = channel;
|
||||
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), false, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumDigitalChannels(), channel);
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_handle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{channel});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalOutput, channel + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "DigitalOutput", channel);
|
||||
}
|
||||
|
||||
DigitalOutput::~DigitalOutput() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
// Disable the PWM in case it was running.
|
||||
DisablePWM();
|
||||
try {
|
||||
DisablePWM();
|
||||
} catch (const RuntimeError& e) {
|
||||
e.Report();
|
||||
}
|
||||
|
||||
HAL_FreeDIOPort(m_handle);
|
||||
}
|
||||
|
||||
void DigitalOutput::Set(bool value) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetDIO(m_handle, value, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
bool DigitalOutput::Get() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
bool val = HAL_GetDIO(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -89,34 +75,22 @@ int DigitalOutput::GetChannel() const {
|
||||
}
|
||||
|
||||
void DigitalOutput::Pulse(double length) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_Pulse(m_handle, length, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
bool DigitalOutput::IsPulsing() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
bool value = HAL_IsPulsing(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
return value;
|
||||
}
|
||||
|
||||
void DigitalOutput::SetPWMRate(double rate) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetDigitalPWMRate(rate, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
void DigitalOutput::EnablePWM(double initialDutyCycle) {
|
||||
@@ -126,29 +100,17 @@ void DigitalOutput::EnablePWM(double initialDutyCycle) {
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
m_pwmGenerator = HAL_AllocateDigitalPWM(&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, initialDutyCycle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, m_channel, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
void DigitalOutput::DisablePWM() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_pwmGenerator == HAL_kInvalidHandle) {
|
||||
return;
|
||||
}
|
||||
@@ -158,22 +120,18 @@ void DigitalOutput::DisablePWM() {
|
||||
// Disable the output by routing to a dead bit.
|
||||
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, SensorUtil::kDigitalChannels,
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
|
||||
HAL_FreeDigitalPWM(m_pwmGenerator, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
|
||||
m_pwmGenerator = HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
void DigitalOutput::UpdateDutyCycle(double dutyCycle) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, dutyCycle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
void DigitalOutput::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/Solenoid.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -28,42 +28,31 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + wpi::Twine(m_moduleNumber));
|
||||
return;
|
||||
throw FRC_MakeError(err::ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + wpi::Twine{m_moduleNumber});
|
||||
}
|
||||
if (!SensorUtil::CheckSolenoidChannel(m_forwardChannel)) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine(m_forwardChannel));
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine{m_forwardChannel});
|
||||
}
|
||||
if (!SensorUtil::CheckSolenoidChannel(m_reverseChannel)) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine(m_reverseChannel));
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine{m_reverseChannel});
|
||||
}
|
||||
int32_t status = 0;
|
||||
m_forwardHandle = HAL_InitializeSolenoidPort(
|
||||
HAL_GetPortWithModule(moduleNumber, m_forwardChannel), &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumSolenoidChannels(),
|
||||
forwardChannel);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Solenoid Module " + wpi::Twine{m_moduleNumber} +
|
||||
" Channel " + wpi::Twine{m_forwardChannel});
|
||||
|
||||
m_reverseHandle = HAL_InitializeSolenoidPort(
|
||||
HAL_GetPortWithModule(moduleNumber, m_reverseChannel), &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumSolenoidChannels(),
|
||||
reverseChannel);
|
||||
// free forward solenoid
|
||||
HAL_FreeSolenoidPort(m_forwardHandle);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
FRC_CheckErrorStatus(status, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_reverseChannel});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,10 +74,6 @@ DoubleSolenoid::~DoubleSolenoid() {
|
||||
}
|
||||
|
||||
void DoubleSolenoid::Set(Value value) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool forward = false;
|
||||
bool reverse = false;
|
||||
|
||||
@@ -112,22 +97,26 @@ void DoubleSolenoid::Set(Value value) {
|
||||
int rstatus = 0;
|
||||
HAL_SetSolenoid(m_reverseHandle, reverse, &rstatus);
|
||||
|
||||
wpi_setHALError(fstatus);
|
||||
wpi_setHALError(rstatus);
|
||||
FRC_CheckErrorStatus(fstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_forwardChannel});
|
||||
FRC_CheckErrorStatus(rstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_reverseChannel});
|
||||
}
|
||||
|
||||
DoubleSolenoid::Value DoubleSolenoid::Get() const {
|
||||
if (StatusIsFatal()) {
|
||||
return kOff;
|
||||
}
|
||||
|
||||
int fstatus = 0;
|
||||
int rstatus = 0;
|
||||
bool valueForward = HAL_GetSolenoid(m_forwardHandle, &fstatus);
|
||||
bool valueReverse = HAL_GetSolenoid(m_reverseHandle, &rstatus);
|
||||
|
||||
wpi_setHALError(fstatus);
|
||||
wpi_setHALError(rstatus);
|
||||
FRC_CheckErrorStatus(fstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_forwardChannel});
|
||||
FRC_CheckErrorStatus(rstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_reverseChannel});
|
||||
|
||||
if (valueForward) {
|
||||
return kForward;
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/MotorSafety.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
|
||||
namespace frc {
|
||||
// A simple class which caches the previous value written to an NT entry
|
||||
@@ -140,7 +140,8 @@ void DriverStation::ReportError(bool isError, int32_t code,
|
||||
|
||||
bool DriverStation::GetStickButton(int stick, int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
@@ -163,7 +164,8 @@ bool DriverStation::GetStickButton(int stick, int button) {
|
||||
|
||||
bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
@@ -192,7 +194,8 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
|
||||
bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
@@ -221,11 +224,13 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
|
||||
double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return 0.0;
|
||||
}
|
||||
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
|
||||
wpi_setWPIError(BadJoystickAxis);
|
||||
FRC_ReportError(warn::BadJoystickAxis,
|
||||
"axis " + wpi::Twine{axis} + " out of range");
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -243,11 +248,13 @@ double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
|
||||
int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return -1;
|
||||
}
|
||||
if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) {
|
||||
wpi_setWPIError(BadJoystickAxis);
|
||||
FRC_ReportError(warn::BadJoystickAxis,
|
||||
"POV " + wpi::Twine{pov} + " out of range");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -265,7 +272,8 @@ int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
|
||||
int DriverStation::GetStickButtons(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -277,7 +285,8 @@ int DriverStation::GetStickButtons(int stick) const {
|
||||
|
||||
int DriverStation::GetStickAxisCount(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -289,7 +298,8 @@ int DriverStation::GetStickAxisCount(int stick) const {
|
||||
|
||||
int DriverStation::GetStickPOVCount(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -301,7 +311,8 @@ int DriverStation::GetStickPOVCount(int stick) const {
|
||||
|
||||
int DriverStation::GetStickButtonCount(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -313,7 +324,8 @@ int DriverStation::GetStickButtonCount(int stick) const {
|
||||
|
||||
bool DriverStation::GetJoystickIsXbox(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -325,7 +337,8 @@ bool DriverStation::GetJoystickIsXbox(int stick) const {
|
||||
|
||||
int DriverStation::GetJoystickType(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -337,7 +350,8 @@ int DriverStation::GetJoystickType(int stick) const {
|
||||
|
||||
std::string DriverStation::GetJoystickName(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
}
|
||||
|
||||
HAL_JoystickDescriptor descriptor;
|
||||
@@ -348,7 +362,8 @@ std::string DriverStation::GetJoystickName(int stick) const {
|
||||
|
||||
int DriverStation::GetJoystickAxisType(int stick, int axis) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -537,7 +552,7 @@ double DriverStation::GetMatchTime() const {
|
||||
double DriverStation::GetBatteryVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetVinVoltage(&status);
|
||||
wpi_setErrorWithContext(status, "getVinVoltage");
|
||||
FRC_CheckErrorStatus(status, "getVinVoltage");
|
||||
|
||||
return voltage;
|
||||
}
|
||||
|
||||
@@ -9,18 +9,17 @@
|
||||
|
||||
#include "frc/Base.h"
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
DutyCycle::DutyCycle(DigitalSource* source)
|
||||
: m_source{source, NullDeleter<DigitalSource>()} {
|
||||
if (m_source == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitDutyCycle();
|
||||
if (!m_source) {
|
||||
throw FRC_MakeError(err::NullParameter, "source");
|
||||
}
|
||||
InitDutyCycle();
|
||||
}
|
||||
|
||||
DutyCycle::DutyCycle(DigitalSource& source)
|
||||
@@ -30,11 +29,10 @@ DutyCycle::DutyCycle(DigitalSource& source)
|
||||
|
||||
DutyCycle::DutyCycle(std::shared_ptr<DigitalSource> source)
|
||||
: m_source{std::move(source)} {
|
||||
if (m_source == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitDutyCycle();
|
||||
if (!m_source) {
|
||||
throw FRC_MakeError(err::NullParameter, "source");
|
||||
}
|
||||
InitDutyCycle();
|
||||
}
|
||||
|
||||
DutyCycle::~DutyCycle() {
|
||||
@@ -48,7 +46,7 @@ void DutyCycle::InitDutyCycle() {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
m_source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitDutyCycle");
|
||||
int index = GetFPGAIndex();
|
||||
HAL_Report(HALUsageReporting::kResourceType_DutyCycle, index + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "Duty Cycle", index);
|
||||
@@ -57,35 +55,35 @@ void DutyCycle::InitDutyCycle() {
|
||||
int DutyCycle::GetFPGAIndex() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleFPGAIndex(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGAIndex");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int DutyCycle::GetFrequency() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleFrequency(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFrequency");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double DutyCycle::GetOutput() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutput(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetOutput");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
unsigned int DutyCycle::GetOutputRaw() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutputRaw(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetOutputRaw");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
unsigned int DutyCycle::GetOutputScaleFactor() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutputScaleFactor(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetOutputScaleFactor");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "frc/Base.h"
|
||||
#include "frc/DigitalInput.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -31,11 +31,13 @@ Encoder::Encoder(DigitalSource* aSource, DigitalSource* bSource,
|
||||
bool reverseDirection, EncodingType encodingType)
|
||||
: m_aSource(aSource, NullDeleter<DigitalSource>()),
|
||||
m_bSource(bSource, NullDeleter<DigitalSource>()) {
|
||||
if (m_aSource == nullptr || m_bSource == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
if (!m_aSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "aSource");
|
||||
}
|
||||
if (!m_bSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "bSource");
|
||||
}
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
}
|
||||
|
||||
Encoder::Encoder(DigitalSource& aSource, DigitalSource& bSource,
|
||||
@@ -49,167 +51,130 @@ Encoder::Encoder(std::shared_ptr<DigitalSource> aSource,
|
||||
std::shared_ptr<DigitalSource> bSource, bool reverseDirection,
|
||||
EncodingType encodingType)
|
||||
: m_aSource(std::move(aSource)), m_bSource(std::move(bSource)) {
|
||||
if (m_aSource == nullptr || m_bSource == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
if (!m_aSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "aSource");
|
||||
}
|
||||
if (!m_bSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "bSource");
|
||||
}
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
}
|
||||
|
||||
Encoder::~Encoder() {
|
||||
int32_t status = 0;
|
||||
HAL_FreeEncoder(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_ReportError(status, "FreeEncoder");
|
||||
}
|
||||
|
||||
int Encoder::Get() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetEncoder(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Encoder::Reset() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_ResetEncoder(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
}
|
||||
|
||||
double Encoder::GetPeriod() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderPeriod(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetPeriod");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Encoder::SetMaxPeriod(double maxPeriod) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetMaxPeriod");
|
||||
}
|
||||
|
||||
bool Encoder::GetStopped() const {
|
||||
if (StatusIsFatal()) {
|
||||
return true;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetEncoderStopped(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetStopped");
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Encoder::GetDirection() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetEncoderDirection(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetDirection");
|
||||
return value;
|
||||
}
|
||||
|
||||
int Encoder::GetRaw() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetEncoderRaw(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetRaw");
|
||||
return value;
|
||||
}
|
||||
|
||||
int Encoder::GetEncodingScale() const {
|
||||
int32_t status = 0;
|
||||
int val = HAL_GetEncoderEncodingScale(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetEncodingScale");
|
||||
return val;
|
||||
}
|
||||
|
||||
double Encoder::GetDistance() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderDistance(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetDistance");
|
||||
return value;
|
||||
}
|
||||
|
||||
double Encoder::GetRate() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderRate(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetRate");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Encoder::SetMinRate(double minRate) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMinRate(m_encoder, minRate, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetMinRate");
|
||||
}
|
||||
|
||||
void Encoder::SetDistancePerPulse(double distancePerPulse) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderDistancePerPulse(m_encoder, distancePerPulse, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetDistancePerPulse");
|
||||
}
|
||||
|
||||
double Encoder::GetDistancePerPulse() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double distancePerPulse = HAL_GetEncoderDistancePerPulse(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetDistancePerPulse");
|
||||
return distancePerPulse;
|
||||
}
|
||||
|
||||
void Encoder::SetReverseDirection(bool reverseDirection) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderReverseDirection(m_encoder, reverseDirection, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetReverseDirection");
|
||||
}
|
||||
|
||||
void Encoder::SetSamplesToAverage(int samplesToAverage) {
|
||||
if (samplesToAverage < 1 || samplesToAverage > 127) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ParameterOutOfRange,
|
||||
"Average counter values must be between 1 and 127");
|
||||
return;
|
||||
throw FRC_MakeError(
|
||||
err::ParameterOutOfRange,
|
||||
"Average counter values must be between 1 and 127, got " +
|
||||
wpi::Twine{samplesToAverage});
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderSamplesToAverage(m_encoder, samplesToAverage, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSamplesToAverage");
|
||||
}
|
||||
|
||||
int Encoder::GetSamplesToAverage() const {
|
||||
int32_t status = 0;
|
||||
int result = HAL_GetEncoderSamplesToAverage(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetSamplesToAverage");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -228,7 +193,7 @@ void Encoder::SetIndexSource(const DigitalSource& source,
|
||||
source.GetAnalogTriggerTypeForRouting()),
|
||||
static_cast<HAL_EncoderIndexingType>(type),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetIndexSource");
|
||||
}
|
||||
|
||||
void Encoder::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
@@ -238,14 +203,14 @@ void Encoder::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
int Encoder::GetFPGAIndex() const {
|
||||
int32_t status = 0;
|
||||
int val = HAL_GetEncoderFPGAIndex(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGAIndex");
|
||||
return val;
|
||||
}
|
||||
|
||||
void Encoder::InitSendable(SendableBuilder& builder) {
|
||||
int32_t status = 0;
|
||||
HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetEncodingType");
|
||||
if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
||||
builder.SetSmartDashboardType("Quadrature Encoder");
|
||||
} else {
|
||||
@@ -271,7 +236,7 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
||||
m_bSource->GetAnalogTriggerTypeForRouting()),
|
||||
reverseDirection, static_cast<HAL_EncoderEncodingType>(encodingType),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitEncoder");
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex() + 1,
|
||||
encodingType);
|
||||
@@ -280,11 +245,8 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
||||
}
|
||||
|
||||
double Encoder::DecodingScaleFactor() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double val = HAL_GetEncoderDecodingScaleFactor(m_encoder, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "DecodingScaleFactor");
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -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/Error.h"
|
||||
|
||||
#include <wpi/Path.h>
|
||||
#include <wpi/StackTrace.h>
|
||||
|
||||
#include "frc/Base.h"
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Timer.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Error::Error(Code code, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function, int lineNumber,
|
||||
const ErrorBase* originatingObject) {
|
||||
Set(code, contextMessage, filename, function, lineNumber, originatingObject);
|
||||
}
|
||||
|
||||
bool Error::operator<(const Error& rhs) const {
|
||||
if (m_code < rhs.m_code) {
|
||||
return true;
|
||||
} else if (m_message < rhs.m_message) {
|
||||
return true;
|
||||
} else if (m_filename < rhs.m_filename) {
|
||||
return true;
|
||||
} else if (m_function < rhs.m_function) {
|
||||
return true;
|
||||
} else if (m_lineNumber < rhs.m_lineNumber) {
|
||||
return true;
|
||||
} else if (m_originatingObject < rhs.m_originatingObject) {
|
||||
return true;
|
||||
} else if (m_timestamp < rhs.m_timestamp) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Error::Code Error::GetCode() const {
|
||||
return m_code;
|
||||
}
|
||||
|
||||
std::string Error::GetMessage() const {
|
||||
return m_message;
|
||||
}
|
||||
|
||||
std::string Error::GetFilename() const {
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
std::string Error::GetFunction() const {
|
||||
return m_function;
|
||||
}
|
||||
|
||||
int Error::GetLineNumber() const {
|
||||
return m_lineNumber;
|
||||
}
|
||||
|
||||
const ErrorBase* Error::GetOriginatingObject() const {
|
||||
return m_originatingObject;
|
||||
}
|
||||
|
||||
double Error::GetTimestamp() const {
|
||||
return m_timestamp;
|
||||
}
|
||||
|
||||
void Error::Set(Code code, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber, const ErrorBase* originatingObject) {
|
||||
bool report = true;
|
||||
|
||||
if (code == m_code && GetTime() - m_timestamp < 1) {
|
||||
report = false;
|
||||
}
|
||||
|
||||
m_code = code;
|
||||
m_message = contextMessage.str();
|
||||
m_filename = filename;
|
||||
m_function = function;
|
||||
m_lineNumber = lineNumber;
|
||||
m_originatingObject = originatingObject;
|
||||
|
||||
if (report) {
|
||||
m_timestamp = GetTime();
|
||||
Report();
|
||||
}
|
||||
}
|
||||
|
||||
void Error::Report() {
|
||||
DriverStation::ReportError(
|
||||
true, m_code, m_message,
|
||||
m_function + wpi::Twine(" [") + wpi::sys::path::filename(m_filename) +
|
||||
wpi::Twine(':') + wpi::Twine(m_lineNumber) + wpi::Twine(']'),
|
||||
wpi::GetStackTrace(4));
|
||||
}
|
||||
|
||||
void Error::Clear() {
|
||||
m_code = 0;
|
||||
m_message = "";
|
||||
m_filename = "";
|
||||
m_function = "";
|
||||
m_lineNumber = 0;
|
||||
m_originatingObject = nullptr;
|
||||
m_timestamp = 0.0;
|
||||
}
|
||||
@@ -1,198 +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/ErrorBase.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/HALBase.h>
|
||||
#include <wpi/Format.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Base.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
namespace {
|
||||
struct GlobalErrors {
|
||||
wpi::mutex mutex;
|
||||
std::set<Error> errors;
|
||||
const Error* lastError{nullptr};
|
||||
|
||||
static GlobalErrors& GetInstance();
|
||||
static void Insert(const Error& error);
|
||||
static void Insert(Error&& error);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
GlobalErrors& GlobalErrors::GetInstance() {
|
||||
static GlobalErrors inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
void GlobalErrors::Insert(const Error& error) {
|
||||
GlobalErrors& inst = GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
inst.lastError = &(*inst.errors.insert(error).first);
|
||||
}
|
||||
|
||||
void GlobalErrors::Insert(Error&& error) {
|
||||
GlobalErrors& inst = GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
inst.lastError = &(*inst.errors.insert(std::move(error)).first);
|
||||
}
|
||||
|
||||
ErrorBase::ErrorBase() {
|
||||
HAL_Initialize(500, 0);
|
||||
}
|
||||
|
||||
Error& ErrorBase::GetError() {
|
||||
return m_error;
|
||||
}
|
||||
|
||||
const Error& ErrorBase::GetError() const {
|
||||
return m_error;
|
||||
}
|
||||
|
||||
void ErrorBase::ClearError() const {
|
||||
m_error.Clear();
|
||||
}
|
||||
|
||||
void ErrorBase::SetErrnoError(const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const {
|
||||
wpi::SmallString<128> buf;
|
||||
wpi::raw_svector_ostream err(buf);
|
||||
int errNo = errno;
|
||||
if (errNo == 0) {
|
||||
err << "OK: ";
|
||||
} else {
|
||||
err << std::strerror(errNo) << " (" << wpi::format_hex(errNo, 10, true)
|
||||
<< "): ";
|
||||
}
|
||||
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(-1, err.str() + contextMessage, filename, function, lineNumber,
|
||||
this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
GlobalErrors::Insert(m_error);
|
||||
}
|
||||
|
||||
void ErrorBase::SetImaqError(int success, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const {
|
||||
// If there was an error
|
||||
if (success <= 0) {
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(success, wpi::Twine(success) + ": " + contextMessage, filename,
|
||||
function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
GlobalErrors::Insert(m_error);
|
||||
}
|
||||
}
|
||||
|
||||
void ErrorBase::SetError(Error::Code code, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const {
|
||||
// If there was an error
|
||||
if (code != 0) {
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(code, contextMessage, filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
GlobalErrors::Insert(m_error);
|
||||
}
|
||||
}
|
||||
|
||||
void ErrorBase::SetErrorRange(Error::Code code, int32_t minRange,
|
||||
int32_t maxRange, int32_t requestedValue,
|
||||
const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const {
|
||||
// If there was an error
|
||||
if (code != 0) {
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(code,
|
||||
contextMessage + ", Minimum Value: " + wpi::Twine(minRange) +
|
||||
", MaximumValue: " + wpi::Twine(maxRange) +
|
||||
", Requested Value: " + wpi::Twine(requestedValue),
|
||||
filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
GlobalErrors::Insert(m_error);
|
||||
}
|
||||
}
|
||||
|
||||
void ErrorBase::SetWPIError(const wpi::Twine& errorMessage, Error::Code code,
|
||||
const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const {
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(code, errorMessage + ": " + contextMessage, filename, function,
|
||||
lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
GlobalErrors::Insert(m_error);
|
||||
}
|
||||
|
||||
void ErrorBase::CloneError(const ErrorBase& rhs) const {
|
||||
m_error = rhs.GetError();
|
||||
}
|
||||
|
||||
bool ErrorBase::StatusIsFatal() const {
|
||||
return m_error.GetCode() < 0;
|
||||
}
|
||||
|
||||
void ErrorBase::SetGlobalError(Error::Code code,
|
||||
const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) {
|
||||
// If there was an error
|
||||
if (code != 0) {
|
||||
// Set the current error information for this object.
|
||||
GlobalErrors::Insert(
|
||||
Error(code, contextMessage, filename, function, lineNumber, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
void ErrorBase::SetGlobalWPIError(const wpi::Twine& errorMessage,
|
||||
const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename,
|
||||
wpi::StringRef function, int lineNumber) {
|
||||
GlobalErrors::Insert(Error(-1, errorMessage + ": " + contextMessage, filename,
|
||||
function, lineNumber, nullptr));
|
||||
}
|
||||
|
||||
Error ErrorBase::GetGlobalError() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::scoped_lock mutex(inst.mutex);
|
||||
if (!inst.lastError) {
|
||||
return {};
|
||||
}
|
||||
return *inst.lastError;
|
||||
}
|
||||
|
||||
std::vector<Error> ErrorBase::GetGlobalErrors() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::scoped_lock mutex(inst.mutex);
|
||||
std::vector<Error> rv;
|
||||
for (auto&& error : inst.errors) {
|
||||
rv.push_back(error);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
void ErrorBase::ClearGlobalErrors() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::scoped_lock mutex(inst.mutex);
|
||||
inst.errors.clear();
|
||||
inst.lastError = nullptr;
|
||||
}
|
||||
78
wpilibc/src/main/native/cpp/Errors.cpp
Normal file
78
wpilibc/src/main/native/cpp/Errors.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// 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/Errors.h"
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include <hal/DriverStation.h>
|
||||
#include <hal/HALBase.h>
|
||||
#include <wpi/Path.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StackTrace.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
RuntimeError::RuntimeError(int32_t code, const wpi::Twine& message,
|
||||
const wpi::Twine& loc, wpi::StringRef stack)
|
||||
: runtime_error{message.str()}, m_data{std::make_shared<Data>()} {
|
||||
m_data->code = code;
|
||||
m_data->loc = loc.str();
|
||||
m_data->stack = stack;
|
||||
}
|
||||
|
||||
RuntimeError::RuntimeError(int32_t code, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName, wpi::StringRef stack)
|
||||
: RuntimeError{code, message,
|
||||
funcName + wpi::Twine{" ["} +
|
||||
wpi::sys::path::filename(fileName) + ":" +
|
||||
wpi::Twine{lineNumber} + "]",
|
||||
stack} {}
|
||||
|
||||
void RuntimeError::Report() const {
|
||||
HAL_SendError(m_data->code < 0, m_data->code, 0, what(), m_data->loc.c_str(),
|
||||
m_data->stack.c_str(), 1);
|
||||
}
|
||||
|
||||
const char* frc::GetErrorMessage(int32_t code) {
|
||||
using namespace err;
|
||||
using namespace warn;
|
||||
switch (code) {
|
||||
#define S(label, offset, message) \
|
||||
case label: \
|
||||
return message;
|
||||
#include "frc/WPIErrors.mac"
|
||||
#include "frc/WPIWarnings.mac"
|
||||
#undef S
|
||||
default:
|
||||
return HAL_GetErrorMessage(code);
|
||||
}
|
||||
}
|
||||
|
||||
void frc::ReportError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName) {
|
||||
if (status == 0) {
|
||||
return;
|
||||
}
|
||||
const char* statusMessage = GetErrorMessage(status);
|
||||
auto stack = wpi::GetStackTrace(2);
|
||||
wpi::SmallString<128> buf;
|
||||
HAL_SendError(status < 0, status, 0,
|
||||
(statusMessage + wpi::Twine{": "} + message)
|
||||
.toNullTerminatedStringRef(buf)
|
||||
.data(),
|
||||
funcName, stack.c_str(), 1);
|
||||
}
|
||||
|
||||
RuntimeError frc::MakeError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName) {
|
||||
const char* statusMessage = GetErrorMessage(status);
|
||||
auto stack = wpi::GetStackTrace(2);
|
||||
return RuntimeError{status, statusMessage + wpi::Twine{": "} + message,
|
||||
fileName, lineNumber,
|
||||
funcName, stack};
|
||||
}
|
||||
@@ -7,13 +7,14 @@
|
||||
#include <hal/DriverStation.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
GenericHID::GenericHID(int port) : m_ds(&DriverStation::GetInstance()) {
|
||||
if (port >= DriverStation::kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
if (port < 0 || port >= DriverStation::kJoystickPorts) {
|
||||
throw FRC_MakeError(warn::BadJoystickIndex,
|
||||
"port " + wpi::Twine{port} + "out of range");
|
||||
}
|
||||
m_port = port;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/I2C.h>
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -17,7 +17,7 @@ I2C::I2C(Port port, int deviceAddress)
|
||||
: m_port(static_cast<HAL_I2CPort>(port)), m_deviceAddress(deviceAddress) {
|
||||
int32_t status = 0;
|
||||
HAL_InitializeI2C(m_port, &status);
|
||||
// wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast<int>(port)});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_I2C, deviceAddress);
|
||||
}
|
||||
@@ -31,7 +31,6 @@ bool I2C::Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
|
||||
int32_t status = 0;
|
||||
status = HAL_TransactionI2C(m_port, m_deviceAddress, dataToSend, sendSize,
|
||||
dataReceived, receiveSize);
|
||||
// wpi_setHALError(status);
|
||||
return status < 0;
|
||||
}
|
||||
|
||||
@@ -56,12 +55,10 @@ bool I2C::WriteBulk(uint8_t* data, int count) {
|
||||
|
||||
bool I2C::Read(int registerAddress, int count, uint8_t* buffer) {
|
||||
if (count < 1) {
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "count");
|
||||
return true;
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "count " + wpi::Twine{count});
|
||||
}
|
||||
if (buffer == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "buffer");
|
||||
return true;
|
||||
if (!buffer) {
|
||||
throw FRC_MakeError(err::NullParameter, "buffer");
|
||||
}
|
||||
uint8_t regAddr = registerAddress;
|
||||
return Transaction(®Addr, sizeof(regAddr), buffer, count);
|
||||
@@ -69,12 +66,10 @@ bool I2C::Read(int registerAddress, int count, uint8_t* buffer) {
|
||||
|
||||
bool I2C::ReadOnly(int count, uint8_t* buffer) {
|
||||
if (count < 1) {
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "count");
|
||||
return true;
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "count " + wpi::Twine{count});
|
||||
}
|
||||
if (buffer == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "buffer");
|
||||
return true;
|
||||
if (!buffer) {
|
||||
throw FRC_MakeError(err::NullParameter, "buffer");
|
||||
}
|
||||
return HAL_ReadI2C(m_port, m_deviceAddress, buffer, count) < 0;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include "frc/InterruptableSensorBase.h"
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -20,15 +20,8 @@ InterruptableSensorBase::~InterruptableSensorBase() {
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts(
|
||||
HAL_InterruptHandlerFunction handler, void* param) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpi_assert(m_interrupt == HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt == HAL_kInvalidHandle);
|
||||
AllocateInterrupts(false);
|
||||
if (StatusIsFatal()) {
|
||||
return; // if allocate failed, out of interrupts
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_RequestInterrupts(
|
||||
@@ -37,19 +30,12 @@ void InterruptableSensorBase::RequestInterrupts(
|
||||
&status);
|
||||
SetUpSourceEdge(true, false);
|
||||
HAL_AttachInterruptHandler(m_interrupt, handler, param, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "AttachInterruptHandler");
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpi_assert(m_interrupt == HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt == HAL_kInvalidHandle);
|
||||
AllocateInterrupts(false);
|
||||
if (StatusIsFatal()) {
|
||||
return; // if allocate failed, out of interrupts
|
||||
}
|
||||
|
||||
m_interruptHandler =
|
||||
std::make_unique<InterruptEventHandler>(std::move(handler));
|
||||
@@ -74,34 +60,24 @@ void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) {
|
||||
(*self)(res);
|
||||
},
|
||||
m_interruptHandler.get(), &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "AttachInterruptHandler");
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpi_assert(m_interrupt == HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt == HAL_kInvalidHandle);
|
||||
AllocateInterrupts(true);
|
||||
if (StatusIsFatal()) {
|
||||
return; // if allocate failed, out of interrupts
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_RequestInterrupts(
|
||||
m_interrupt, GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "RequestInterrupts");
|
||||
SetUpSourceEdge(true, false);
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::CancelInterrupts() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_CleanInterrupts(m_interrupt, &status);
|
||||
// Ignore status, as an invalid handle just needs to be ignored.
|
||||
@@ -111,15 +87,12 @@ void InterruptableSensorBase::CancelInterrupts() {
|
||||
|
||||
InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
double timeout, bool ignorePrevious) {
|
||||
if (StatusIsFatal()) {
|
||||
return InterruptableSensorBase::kTimeout;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int result;
|
||||
|
||||
result = HAL_WaitForInterrupt(m_interrupt, timeout, ignorePrevious, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "WaitForInterrupt");
|
||||
|
||||
// Rising edge result is the interrupt bit set in the byte 0xFF
|
||||
// Falling edge result is the interrupt bit set in the byte 0xFF00
|
||||
@@ -131,69 +104,53 @@ InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::EnableInterrupts() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_EnableInterrupts(m_interrupt, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "EnableInterrupts");
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::DisableInterrupts() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_DisableInterrupts(m_interrupt, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "DisableInterrupts");
|
||||
}
|
||||
|
||||
double InterruptableSensorBase::ReadRisingTimestamp() {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int64_t timestamp = HAL_ReadInterruptRisingTimestamp(m_interrupt, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ReadRisingTimestamp");
|
||||
return timestamp * 1e-6;
|
||||
}
|
||||
|
||||
double InterruptableSensorBase::ReadFallingTimestamp() {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int64_t timestamp = HAL_ReadInterruptFallingTimestamp(m_interrupt, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ReadFallingTimestamp");
|
||||
return timestamp * 1e-6;
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::SetUpSourceEdge(bool risingEdge,
|
||||
bool fallingEdge) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
if (m_interrupt == HAL_kInvalidHandle) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
NullParameter,
|
||||
throw FRC_MakeError(
|
||||
err::NullParameter,
|
||||
"You must call RequestInterrupts before SetUpSourceEdge");
|
||||
return;
|
||||
}
|
||||
if (m_interrupt != HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
HAL_SetInterruptUpSourceEdge(m_interrupt, risingEdge, fallingEdge, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetUpSourceEdge");
|
||||
}
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::AllocateInterrupts(bool watcher) {
|
||||
wpi_assert(m_interrupt == HAL_kInvalidHandle);
|
||||
FRC_Assert(m_interrupt == HAL_kInvalidHandle);
|
||||
// Expects the calling leaf class to allocate an interrupt index.
|
||||
int32_t status = 0;
|
||||
m_interrupt = HAL_InitializeInterrupts(watcher, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "AllocateInterrupts");
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -30,16 +30,13 @@ MotorSafety::~MotorSafety() {
|
||||
}
|
||||
|
||||
MotorSafety::MotorSafety(MotorSafety&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
m_expiration(std::move(rhs.m_expiration)),
|
||||
: m_expiration(std::move(rhs.m_expiration)),
|
||||
m_enabled(std::move(rhs.m_enabled)),
|
||||
m_stopTime(std::move(rhs.m_stopTime)) {}
|
||||
|
||||
MotorSafety& MotorSafety::operator=(MotorSafety&& rhs) {
|
||||
std::scoped_lock lock(m_thisMutex, rhs.m_thisMutex);
|
||||
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
m_expiration = std::move(rhs.m_expiration);
|
||||
m_enabled = std::move(rhs.m_enabled);
|
||||
m_stopTime = std::move(rhs.m_stopTime);
|
||||
@@ -97,7 +94,7 @@ void MotorSafety::Check() {
|
||||
wpi::raw_svector_ostream desc(buf);
|
||||
GetDescription(desc);
|
||||
desc << "... Output not updated often enough.";
|
||||
wpi_setWPIErrorWithContext(Timeout, desc.str());
|
||||
FRC_ReportError(err::Timeout, desc.str());
|
||||
StopMotor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,20 +11,20 @@
|
||||
#include <hal/Threads.h>
|
||||
#include <wpi/SmallString.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Notifier::Notifier(std::function<void()> handler) {
|
||||
if (handler == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
|
||||
if (!handler) {
|
||||
throw FRC_MakeError(err::NullParameter, "handler");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitializeNotifier");
|
||||
|
||||
m_thread = std::thread([=] {
|
||||
for (;;) {
|
||||
@@ -60,13 +60,13 @@ Notifier::Notifier(std::function<void()> handler) {
|
||||
}
|
||||
|
||||
Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
if (handler == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
|
||||
if (!handler) {
|
||||
throw FRC_MakeError(err::NullParameter, "handler");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitializeNotifier");
|
||||
|
||||
m_thread = std::thread([=] {
|
||||
int32_t status = 0;
|
||||
@@ -107,7 +107,7 @@ Notifier::~Notifier() {
|
||||
// atomically set handle to 0, then clean
|
||||
HAL_NotifierHandle handle = m_notifier.exchange(0);
|
||||
HAL_StopNotifier(handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_ReportError(status, "StopNotifier");
|
||||
|
||||
// Join the thread to ensure the handler has exited.
|
||||
if (m_thread.joinable()) {
|
||||
@@ -118,8 +118,7 @@ Notifier::~Notifier() {
|
||||
}
|
||||
|
||||
Notifier::Notifier(Notifier&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
m_thread(std::move(rhs.m_thread)),
|
||||
: m_thread(std::move(rhs.m_thread)),
|
||||
m_notifier(rhs.m_notifier.load()),
|
||||
m_handler(std::move(rhs.m_handler)),
|
||||
m_expirationTime(std::move(rhs.m_expirationTime)),
|
||||
@@ -129,8 +128,6 @@ Notifier::Notifier(Notifier&& rhs)
|
||||
}
|
||||
|
||||
Notifier& Notifier::operator=(Notifier&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
m_thread = std::move(rhs.m_thread);
|
||||
m_notifier = rhs.m_notifier.load();
|
||||
rhs.m_notifier = HAL_kInvalidHandle;
|
||||
@@ -183,7 +180,7 @@ void Notifier::Stop() {
|
||||
m_periodic = false;
|
||||
int32_t status = 0;
|
||||
HAL_CancelNotifierAlarm(m_notifier, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "CancelNotifierAlarm");
|
||||
}
|
||||
|
||||
void Notifier::UpdateAlarm(uint64_t triggerTime) {
|
||||
@@ -194,7 +191,7 @@ void Notifier::UpdateAlarm(uint64_t triggerTime) {
|
||||
return;
|
||||
}
|
||||
HAL_UpdateNotifierAlarm(notifier, triggerTime, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "UpdateNotifierAlarm");
|
||||
}
|
||||
|
||||
void Notifier::UpdateAlarm() {
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include <hal/PWM.h>
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -21,27 +21,22 @@ using namespace frc;
|
||||
|
||||
PWM::PWM(int channel, bool registerSendable) {
|
||||
if (!SensorUtil::CheckPWMChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"PWM Channel " + wpi::Twine(channel));
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"PWM Channel " + wpi::Twine{channel});
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePWMPort(HAL_GetPort(channel), &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumPWMChannels(), channel);
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_handle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "PWM Channel " + wpi::Twine{channel});
|
||||
|
||||
m_channel = channel;
|
||||
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetPWMDisabled");
|
||||
status = 0;
|
||||
HAL_SetPWMEliminateDeadband(m_handle, false, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetPWMEliminateDeadband");
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PWM, channel + 1);
|
||||
if (registerSendable) {
|
||||
@@ -53,88 +48,59 @@ PWM::~PWM() {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_ReportError(status, "SetPWMDisabled");
|
||||
|
||||
HAL_FreePWMPort(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_ReportError(status, "FreePWM");
|
||||
}
|
||||
|
||||
void PWM::SetRaw(uint16_t value) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMRaw(m_handle, value, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetRaw");
|
||||
}
|
||||
|
||||
uint16_t PWM::GetRaw() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
uint16_t value = HAL_GetPWMRaw(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetRaw");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void PWM::SetPosition(double pos) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMPosition(m_handle, pos, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetPosition");
|
||||
}
|
||||
|
||||
double PWM::GetPosition() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double position = HAL_GetPWMPosition(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetPosition");
|
||||
return position;
|
||||
}
|
||||
|
||||
void PWM::SetSpeed(double speed) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMSpeed(m_handle, speed, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSpeed");
|
||||
}
|
||||
|
||||
double PWM::GetSpeed() const {
|
||||
if (StatusIsFatal()) {
|
||||
return 0.0;
|
||||
}
|
||||
int32_t status = 0;
|
||||
double speed = HAL_GetPWMSpeed(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetSpeed");
|
||||
return speed;
|
||||
}
|
||||
|
||||
void PWM::SetDisabled() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetDisabled");
|
||||
}
|
||||
|
||||
void PWM::SetPeriodMultiplier(PeriodMultiplier mult) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
switch (mult) {
|
||||
@@ -153,49 +119,35 @@ void PWM::SetPeriodMultiplier(PeriodMultiplier mult) {
|
||||
wpi_assert(false);
|
||||
}
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetPeriodMultiplier");
|
||||
}
|
||||
|
||||
void PWM::SetZeroLatch() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_LatchPWMZero(m_handle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetZeroLatch");
|
||||
}
|
||||
|
||||
void PWM::EnableDeadbandElimination(bool eliminateDeadband) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMEliminateDeadband(m_handle, eliminateDeadband, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "EnableDeadbandElimination");
|
||||
}
|
||||
|
||||
void PWM::SetBounds(double max, double deadbandMax, double center,
|
||||
double deadbandMin, double min) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMConfig(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetBounds");
|
||||
}
|
||||
|
||||
void PWM::SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
|
||||
int min) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetRawBounds");
|
||||
}
|
||||
|
||||
void PWM::GetRawBounds(int* max, int* deadbandMax, int* center,
|
||||
@@ -203,7 +155,7 @@ void PWM::GetRawBounds(int* max, int* deadbandMax, int* center,
|
||||
int32_t status = 0;
|
||||
HAL_GetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetRawBounds");
|
||||
}
|
||||
|
||||
int PWM::GetChannel() const {
|
||||
|
||||
@@ -7,11 +7,9 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/PDP.h>
|
||||
#include <hal/Ports.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -25,10 +23,7 @@ PowerDistributionPanel::PowerDistributionPanel() : PowerDistributionPanel(0) {}
|
||||
PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePDP(module, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumPDPModules(), module);
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PDP, module + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "PowerDistributionPanel", module);
|
||||
@@ -36,25 +31,15 @@ PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
|
||||
|
||||
double PowerDistributionPanel::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
|
||||
double voltage = HAL_GetPDPVoltage(m_handle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetVoltage");
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTemperature() const {
|
||||
int32_t status = 0;
|
||||
|
||||
double temperature = HAL_GetPDPTemperature(m_handle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetTemperature");
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@@ -62,75 +47,48 @@ double PowerDistributionPanel::GetCurrent(int channel) const {
|
||||
int32_t status = 0;
|
||||
|
||||
if (!SensorUtil::CheckPDPChannel(channel)) {
|
||||
wpi::SmallString<32> str;
|
||||
wpi::raw_svector_ostream buf(str);
|
||||
buf << "PDP Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
FRC_ReportError(err::ChannelIndexOutOfRange,
|
||||
"Channel " + wpi::Twine{channel});
|
||||
return 0;
|
||||
}
|
||||
|
||||
double current = HAL_GetPDPChannelCurrent(m_handle, channel, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{channel});
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalCurrent() const {
|
||||
int32_t status = 0;
|
||||
|
||||
double current = HAL_GetPDPTotalCurrent(m_handle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetTotalCurrent");
|
||||
return current;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalPower() const {
|
||||
int32_t status = 0;
|
||||
|
||||
double power = HAL_GetPDPTotalPower(m_handle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetTotalPower");
|
||||
return power;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalEnergy() const {
|
||||
int32_t status = 0;
|
||||
|
||||
double energy = HAL_GetPDPTotalEnergy(m_handle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetTotalEnergy");
|
||||
return energy;
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::ResetTotalEnergy() {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_ResetPDPTotalEnergy(m_handle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "ResetTotalEnergy");
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::ClearStickyFaults() {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_ClearPDPStickyFaults(m_handle, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "ClearStickyFaults");
|
||||
}
|
||||
|
||||
int PowerDistributionPanel::GetModule() const {
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
// The Preferences table name
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <hal/Relay.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -22,8 +22,8 @@ using namespace frc;
|
||||
Relay::Relay(int channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
if (!SensorUtil::CheckRelayChannel(m_channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Relay Channel " + wpi::Twine(m_channel));
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Relay Channel " + wpi::Twine{m_channel});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,45 +32,24 @@ Relay::Relay(int channel, Relay::Direction direction)
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
int32_t status = 0;
|
||||
m_forwardHandle = HAL_InitializeRelayPort(portHandle, true, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 1);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
int32_t status = 0;
|
||||
m_reverseHandle = HAL_InitializeRelayPort(portHandle, false, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 128);
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
if (m_forwardHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_forwardHandle, false, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
if (m_reverseHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_reverseHandle, false, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
SendableRegistry::GetInstance().AddLW(this, "Relay", m_channel);
|
||||
@@ -90,10 +69,6 @@ Relay::~Relay() {
|
||||
}
|
||||
|
||||
void Relay::Set(Relay::Value value) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
switch (value) {
|
||||
@@ -115,7 +90,7 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
case kForward:
|
||||
if (m_direction == kReverseOnly) {
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
FRC_ReportError(err::IncompatibleMode, "setting forward");
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
@@ -127,7 +102,7 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
case kReverse:
|
||||
if (m_direction == kForwardOnly) {
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
FRC_ReportError(err::IncompatibleMode, "setting reverse");
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections) {
|
||||
@@ -139,7 +114,7 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
}
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Set");
|
||||
}
|
||||
|
||||
Relay::Value Relay::Get() const {
|
||||
@@ -173,7 +148,7 @@ Relay::Value Relay::Get() const {
|
||||
}
|
||||
}
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
}
|
||||
|
||||
int Relay::GetChannel() const {
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
#include "frc/Resource.h"
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -31,19 +30,16 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
wpi_setWPIErrorWithContext(NoAvailableResources, resourceDesc);
|
||||
return std::numeric_limits<uint32_t>::max();
|
||||
throw FRC_MakeError(err::NoAvailableResources, resourceDesc);
|
||||
}
|
||||
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
std::scoped_lock lock(m_allocateMutex);
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
return std::numeric_limits<uint32_t>::max();
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, resourceDesc);
|
||||
}
|
||||
if (m_isAllocated[index]) {
|
||||
wpi_setWPIErrorWithContext(ResourceAlreadyAllocated, resourceDesc);
|
||||
return std::numeric_limits<uint32_t>::max();
|
||||
throw FRC_MakeError(err::ResourceAlreadyAllocated, resourceDesc);
|
||||
}
|
||||
m_isAllocated[index] = true;
|
||||
return index;
|
||||
@@ -55,12 +51,10 @@ void Resource::Free(uint32_t index) {
|
||||
return;
|
||||
}
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIError(NotAllocated);
|
||||
return;
|
||||
throw FRC_MakeError(err::NotAllocated, "index " + wpi::Twine{index});
|
||||
}
|
||||
if (!m_isAllocated[index]) {
|
||||
wpi_setWPIError(NotAllocated);
|
||||
return;
|
||||
throw FRC_MakeError(err::NotAllocated, "index " + wpi::Twine{index});
|
||||
}
|
||||
m_isAllocated[index] = false;
|
||||
}
|
||||
|
||||
@@ -8,156 +8,154 @@
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Power.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
int RobotController::GetFPGAVersion() {
|
||||
int32_t status = 0;
|
||||
int version = HAL_GetFPGAVersion(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGAVersion");
|
||||
return version;
|
||||
}
|
||||
|
||||
int64_t RobotController::GetFPGARevision() {
|
||||
int32_t status = 0;
|
||||
int64_t revision = HAL_GetFPGARevision(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGARevision");
|
||||
return revision;
|
||||
}
|
||||
|
||||
uint64_t RobotController::GetFPGATime() {
|
||||
int32_t status = 0;
|
||||
uint64_t time = HAL_GetFPGATime(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGATime");
|
||||
return time;
|
||||
}
|
||||
|
||||
bool RobotController::GetUserButton() {
|
||||
int32_t status = 0;
|
||||
|
||||
bool value = HAL_GetFPGAButton(&status);
|
||||
wpi_setGlobalError(status);
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetUserButton");
|
||||
return value;
|
||||
}
|
||||
|
||||
units::volt_t RobotController::GetBatteryVoltage() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinVoltage(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetBatteryVoltage");
|
||||
return units::volt_t{retVal};
|
||||
}
|
||||
|
||||
bool RobotController::IsSysActive() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetSystemActive(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "IsSysActive");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::IsBrownedOut() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetBrownedOut(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "IsBrownedOut");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetInputVoltage() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinVoltage(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetInputVoltage");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetInputCurrent() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinCurrent(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetInputCurrent");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetVoltage3V3() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage3V3(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetCurrent3V3() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent3V3(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrent3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::GetEnabled3V3() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetUserActive3V3(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetEnabled3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int RobotController::GetFaultCount3V3() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetUserCurrentFaults3V3(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFaultCount3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetVoltage5V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage5V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetCurrent5V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent5V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrent5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::GetEnabled5V() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetUserActive5V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetEnabled5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int RobotController::GetFaultCount5V() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetUserCurrentFaults5V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFaultCount5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetVoltage6V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage6V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetCurrent6V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent6V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrent6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::GetEnabled6V() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetUserActive6V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetEnabled6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int RobotController::GetFaultCount6V() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetUserCurrentFaults6V(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetFaultCount6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -170,10 +168,7 @@ CANStatus RobotController::GetCANStatus() {
|
||||
uint32_t transmitErrorCount = 0;
|
||||
HAL_CAN_GetCANStatus(&percentBusUtilization, &busOffCount, &txFullCount,
|
||||
&receiveErrorCount, &transmitErrorCount, &status);
|
||||
if (status != 0) {
|
||||
wpi_setGlobalHALError(status);
|
||||
return {};
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "GetCANStatus");
|
||||
return {percentBusUtilization, static_cast<int>(busOffCount),
|
||||
static_cast<int>(txFullCount), static_cast<int>(receiveErrorCount),
|
||||
static_cast<int>(transmitErrorCount)};
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Notifier.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -77,9 +77,7 @@ void SPI::Accumulator::Update() {
|
||||
// get amount of data available
|
||||
int32_t numToRead =
|
||||
HAL_ReadSPIAutoReceivedData(m_port, m_buf, 0, 0, &status);
|
||||
if (status != 0) {
|
||||
return; // error reading
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "ReadSPIAutoReceivedData");
|
||||
|
||||
// only get whole responses; +1 is for timestamp
|
||||
numToRead -= numToRead % m_xferSize;
|
||||
@@ -93,9 +91,7 @@ void SPI::Accumulator::Update() {
|
||||
|
||||
// read buffered data
|
||||
HAL_ReadSPIAutoReceivedData(m_port, m_buf, numToRead, 0, &status);
|
||||
if (status != 0) {
|
||||
return; // error reading
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "ReadSPIAutoReceivedData");
|
||||
|
||||
// loop over all responses
|
||||
for (int32_t off = 0; off < numToRead; off += m_xferSize) {
|
||||
@@ -162,7 +158,7 @@ void SPI::Accumulator::Update() {
|
||||
SPI::SPI(Port port) : m_port(static_cast<HAL_SPIPort>(port)) {
|
||||
int32_t status = 0;
|
||||
HAL_InitializeSPI(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitializeSPI");
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_SPI,
|
||||
static_cast<uint8_t>(port) + 1);
|
||||
@@ -219,13 +215,13 @@ void SPI::SetClockActiveHigh() {
|
||||
void SPI::SetChipSelectActiveHigh() {
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIChipSelectActiveHigh(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetChipSelectActiveHigh");
|
||||
}
|
||||
|
||||
void SPI::SetChipSelectActiveLow() {
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIChipSelectActiveLow(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetChipSelectActiveLow");
|
||||
}
|
||||
|
||||
int SPI::Write(uint8_t* data, int size) {
|
||||
@@ -255,26 +251,26 @@ int SPI::Transaction(uint8_t* dataToSend, uint8_t* dataReceived, int size) {
|
||||
void SPI::InitAuto(int bufferSize) {
|
||||
int32_t status = 0;
|
||||
HAL_InitSPIAuto(m_port, bufferSize, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitAuto");
|
||||
}
|
||||
|
||||
void SPI::FreeAuto() {
|
||||
int32_t status = 0;
|
||||
HAL_FreeSPIAuto(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "FreeAuto");
|
||||
}
|
||||
|
||||
void SPI::SetAutoTransmitData(wpi::ArrayRef<uint8_t> dataToSend, int zeroSize) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIAutoTransmitData(m_port, dataToSend.data(), dataToSend.size(),
|
||||
zeroSize, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetAutoTransmitData");
|
||||
}
|
||||
|
||||
void SPI::StartAutoRate(units::second_t period) {
|
||||
int32_t status = 0;
|
||||
HAL_StartSPIAutoRate(m_port, period.to<double>(), &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "StartAutoRate");
|
||||
}
|
||||
|
||||
void SPI::StartAutoRate(double period) {
|
||||
@@ -287,19 +283,19 @@ void SPI::StartAutoTrigger(DigitalSource& source, bool rising, bool falling) {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source.GetAnalogTriggerTypeForRouting()),
|
||||
rising, falling, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "StartAutoTrigger");
|
||||
}
|
||||
|
||||
void SPI::StopAuto() {
|
||||
int32_t status = 0;
|
||||
HAL_StopSPIAuto(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "StopAuto");
|
||||
}
|
||||
|
||||
void SPI::ForceAutoRead() {
|
||||
int32_t status = 0;
|
||||
HAL_ForceSPIAutoRead(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ForceAutoRead");
|
||||
}
|
||||
|
||||
int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead,
|
||||
@@ -307,7 +303,7 @@ int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead,
|
||||
int32_t status = 0;
|
||||
int32_t val = HAL_ReadSPIAutoReceivedData(m_port, buffer, numToRead,
|
||||
timeout.to<double>(), &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ReadAutoReceivedData");
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -318,7 +314,7 @@ int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead, double timeout) {
|
||||
int SPI::GetAutoDroppedCount() {
|
||||
int32_t status = 0;
|
||||
int32_t val = HAL_GetSPIAutoDroppedCount(m_port, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetAutoDroppedCount");
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -327,7 +323,7 @@ void SPI::ConfigureAutoStall(HAL_SPIPort port, int csToSclkTicks,
|
||||
int32_t status = 0;
|
||||
HAL_ConfigureSPIAutoStall(m_port, csToSclkTicks, stallTicks, pow2BytesPerRead,
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "ConfigureAutoStall");
|
||||
}
|
||||
|
||||
void SPI::InitAccumulator(units::second_t period, int cmd, int xferSize,
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/SerialPort.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
SerialPort::SerialPort(int baudRate, Port port, int dataBits,
|
||||
@@ -18,19 +20,17 @@ SerialPort::SerialPort(int baudRate, Port port, int dataBits,
|
||||
|
||||
m_portHandle =
|
||||
HAL_InitializeSerialPort(static_cast<HAL_SerialPort>(port), &status);
|
||||
wpi_setHALError(status);
|
||||
// Don't continue if initialization failed
|
||||
if (status < 0) {
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast<int>(port)});
|
||||
HAL_SetSerialBaudRate(m_portHandle, baudRate, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialBaudRate " + wpi::Twine{baudRate});
|
||||
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialDataBits " + wpi::Twine{dataBits});
|
||||
HAL_SetSerialParity(m_portHandle, parity, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialParity " + wpi::Twine{static_cast<int>(parity)});
|
||||
HAL_SetSerialStopBits(m_portHandle, stopBits, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialStopBits " + wpi::Twine{static_cast<int>(stopBits)});
|
||||
|
||||
// Set the default timeout to 5 seconds.
|
||||
SetTimeout(5.0);
|
||||
@@ -54,19 +54,17 @@ SerialPort::SerialPort(int baudRate, const wpi::Twine& portName, Port port,
|
||||
|
||||
m_portHandle = HAL_InitializeSerialPortDirect(
|
||||
static_cast<HAL_SerialPort>(port), portNameC, &status);
|
||||
wpi_setHALError(status);
|
||||
// Don't continue if initialization failed
|
||||
if (status < 0) {
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast<int>(port)});
|
||||
HAL_SetSerialBaudRate(m_portHandle, baudRate, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialBaudRate " + wpi::Twine{baudRate});
|
||||
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialDataBits " + wpi::Twine{dataBits});
|
||||
HAL_SetSerialParity(m_portHandle, parity, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialParity " + wpi::Twine{static_cast<int>(parity)});
|
||||
HAL_SetSerialStopBits(m_portHandle, stopBits, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialStopBits " + wpi::Twine{static_cast<int>(stopBits)});
|
||||
|
||||
// Set the default timeout to 5 seconds.
|
||||
SetTimeout(5.0);
|
||||
@@ -83,38 +81,40 @@ SerialPort::SerialPort(int baudRate, const wpi::Twine& portName, Port port,
|
||||
SerialPort::~SerialPort() {
|
||||
int32_t status = 0;
|
||||
HAL_CloseSerial(m_portHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_ReportError(status, "CloseSerial");
|
||||
}
|
||||
|
||||
void SerialPort::SetFlowControl(SerialPort::FlowControl flowControl) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialFlowControl(m_portHandle, flowControl, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetFlowControl " + wpi::Twine{static_cast<int>(flowControl)});
|
||||
}
|
||||
|
||||
void SerialPort::EnableTermination(char terminator) {
|
||||
int32_t status = 0;
|
||||
HAL_EnableSerialTermination(m_portHandle, terminator, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "EnableTermination " + wpi::Twine{static_cast<int>(terminator)});
|
||||
}
|
||||
|
||||
void SerialPort::DisableTermination() {
|
||||
int32_t status = 0;
|
||||
HAL_DisableSerialTermination(m_portHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "DisableTermination");
|
||||
}
|
||||
|
||||
int SerialPort::GetBytesReceived() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetSerialBytesReceived(m_portHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetBytesReceived");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int SerialPort::Read(char* buffer, int count) {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_ReadSerial(m_portHandle, buffer, count, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Read");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -126,42 +126,43 @@ int SerialPort::Write(wpi::StringRef buffer) {
|
||||
int32_t status = 0;
|
||||
int retVal =
|
||||
HAL_WriteSerial(m_portHandle, buffer.data(), buffer.size(), &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Write");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void SerialPort::SetTimeout(double timeout) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialTimeout(m_portHandle, timeout, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetTimeout");
|
||||
}
|
||||
|
||||
void SerialPort::SetReadBufferSize(int size) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialReadBufferSize(m_portHandle, size, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetReadBufferSize " + wpi::Twine{size});
|
||||
}
|
||||
|
||||
void SerialPort::SetWriteBufferSize(int size) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialWriteBufferSize(m_portHandle, size, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetWriteBufferSize " + wpi::Twine{size});
|
||||
}
|
||||
|
||||
void SerialPort::SetWriteBufferMode(SerialPort::WriteBufferMode mode) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialWriteMode(m_portHandle, mode, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetWriteBufferMode " + wpi::Twine{static_cast<int>(mode)});
|
||||
}
|
||||
|
||||
void SerialPort::Flush() {
|
||||
int32_t status = 0;
|
||||
HAL_FlushSerial(m_portHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Flush");
|
||||
}
|
||||
|
||||
void SerialPort::Reset() {
|
||||
int32_t status = 0;
|
||||
HAL_ClearSerial(m_portHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/Solenoid.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -24,24 +24,19 @@ Solenoid::Solenoid(int channel)
|
||||
Solenoid::Solenoid(int moduleNumber, int channel)
|
||||
: SolenoidBase(moduleNumber), m_channel(channel) {
|
||||
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + wpi::Twine(m_moduleNumber));
|
||||
return;
|
||||
throw FRC_MakeError(err::ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + wpi::Twine{m_moduleNumber});
|
||||
}
|
||||
if (!SensorUtil::CheckSolenoidChannel(m_channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine(m_channel));
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
m_solenoidHandle = HAL_InitializeSolenoidPort(
|
||||
HAL_GetPortWithModule(moduleNumber, channel), &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumSolenoidChannels(), channel);
|
||||
m_solenoidHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Solenoid Module " + wpi::Twine{m_moduleNumber} +
|
||||
" Channel " + wpi::Twine{m_channel});
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_channel + 1,
|
||||
m_moduleNumber + 1);
|
||||
@@ -54,23 +49,15 @@ Solenoid::~Solenoid() {
|
||||
}
|
||||
|
||||
void Solenoid::Set(bool on) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetSolenoid(m_solenoidHandle, on, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Set");
|
||||
}
|
||||
|
||||
bool Solenoid::Get() const {
|
||||
if (StatusIsFatal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetSolenoid(m_solenoidHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -90,21 +77,15 @@ bool Solenoid::IsBlackListed() const {
|
||||
|
||||
void Solenoid::SetPulseDuration(double durationSeconds) {
|
||||
int32_t durationMS = durationSeconds * 1000;
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetOneShotDuration(m_solenoidHandle, durationMS, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetPulseDuration");
|
||||
}
|
||||
|
||||
void Solenoid::StartPulse() {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_FireOneShot(m_solenoidHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "StartPulse");
|
||||
}
|
||||
|
||||
void Solenoid::InitSendable(SendableBuilder& builder) {
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/Solenoid.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
int SolenoidBase::GetAll(int module) {
|
||||
int value = 0;
|
||||
int32_t status = 0;
|
||||
value = HAL_GetAllSolenoids(module, &status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -23,7 +25,9 @@ int SolenoidBase::GetAll() const {
|
||||
|
||||
int SolenoidBase::GetPCMSolenoidBlackList(int module) {
|
||||
int32_t status = 0;
|
||||
return HAL_GetPCMSolenoidBlackList(module, &status);
|
||||
int rv = HAL_GetPCMSolenoidBlackList(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
return rv;
|
||||
}
|
||||
|
||||
int SolenoidBase::GetPCMSolenoidBlackList() const {
|
||||
@@ -32,7 +36,9 @@ int SolenoidBase::GetPCMSolenoidBlackList() const {
|
||||
|
||||
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) {
|
||||
int32_t status = 0;
|
||||
return HAL_GetPCMSolenoidVoltageStickyFault(module, &status);
|
||||
bool rv = HAL_GetPCMSolenoidVoltageStickyFault(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault() const {
|
||||
@@ -41,7 +47,9 @@ bool SolenoidBase::GetPCMSolenoidVoltageStickyFault() const {
|
||||
|
||||
bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) {
|
||||
int32_t status = 0;
|
||||
return HAL_GetPCMSolenoidVoltageFault(module, &status);
|
||||
bool rv = HAL_GetPCMSolenoidVoltageFault(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool SolenoidBase::GetPCMSolenoidVoltageFault() const {
|
||||
@@ -50,7 +58,8 @@ bool SolenoidBase::GetPCMSolenoidVoltageFault() const {
|
||||
|
||||
void SolenoidBase::ClearAllPCMStickyFaults(int module) {
|
||||
int32_t status = 0;
|
||||
return HAL_ClearAllPCMStickyFaults(module, &status);
|
||||
HAL_ClearAllPCMStickyFaults(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
}
|
||||
|
||||
void SolenoidBase::ClearAllPCMStickyFaults() {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/Threads.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -16,7 +16,7 @@ int GetThreadPriority(std::thread& thread, bool* isRealTime) {
|
||||
HAL_Bool rt = false;
|
||||
auto native = thread.native_handle();
|
||||
auto ret = HAL_GetThreadPriority(&native, &rt, &status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetThreadPriority");
|
||||
*isRealTime = rt;
|
||||
return ret;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ int GetCurrentThreadPriority(bool* isRealTime) {
|
||||
int32_t status = 0;
|
||||
HAL_Bool rt = false;
|
||||
auto ret = HAL_GetCurrentThreadPriority(&rt, &status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrentThreadPriority");
|
||||
*isRealTime = rt;
|
||||
return ret;
|
||||
}
|
||||
@@ -34,14 +34,14 @@ bool SetThreadPriority(std::thread& thread, bool realTime, int priority) {
|
||||
int32_t status = 0;
|
||||
auto native = thread.native_handle();
|
||||
auto ret = HAL_SetThreadPriority(&native, realTime, priority, &status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetThreadPriority");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SetCurrentThreadPriority(bool realTime, int priority) {
|
||||
int32_t status = 0;
|
||||
auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetCurrentThreadPriority");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/Notifier.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -39,7 +39,7 @@ void TimedRobot::StartCompetition() {
|
||||
HAL_UpdateNotifierAlarm(
|
||||
m_notifier, static_cast<uint64_t>(callback.expirationTime * 1e6),
|
||||
&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "UpdateNotifierAlarm");
|
||||
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(m_notifier, &status);
|
||||
if (curTime == 0 || status != 0) {
|
||||
@@ -81,7 +81,7 @@ TimedRobot::TimedRobot(units::second_t period) : IterativeRobotBase(period) {
|
||||
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "InitializeNotifier");
|
||||
HAL_SetNotifierName(m_notifier, "TimedRobot", &status);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Framework,
|
||||
@@ -92,7 +92,7 @@ TimedRobot::~TimedRobot() {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_StopNotifier(m_notifier, &status);
|
||||
wpi_setHALError(status);
|
||||
FRC_ReportError(status, "StopNotifier");
|
||||
|
||||
HAL_CleanNotifier(m_notifier, &status);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/DigitalInput.h"
|
||||
#include "frc/DigitalOutput.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -40,9 +40,11 @@ Ultrasonic::Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel)
|
||||
: m_pingChannel(pingChannel, NullDeleter<DigitalOutput>()),
|
||||
m_echoChannel(echoChannel, NullDeleter<DigitalInput>()),
|
||||
m_counter(m_echoChannel) {
|
||||
if (pingChannel == nullptr || echoChannel == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
return;
|
||||
if (!pingChannel) {
|
||||
throw FRC_MakeError(err::NullParameter, "pingChannel");
|
||||
}
|
||||
if (!echoChannel) {
|
||||
throw FRC_MakeError(err::NullParameter, "echoChannel");
|
||||
}
|
||||
Initialize();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc2/Timer.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -47,7 +48,7 @@ class Watchdog::Impl {
|
||||
Watchdog::Impl::Impl() {
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "starting watchdog notifier");
|
||||
HAL_SetNotifierName(m_notifier, "Watchdog", &status);
|
||||
|
||||
m_thread = std::thread([=] { Main(); });
|
||||
@@ -58,7 +59,7 @@ Watchdog::Impl::~Impl() {
|
||||
// atomically set handle to 0, then clean
|
||||
HAL_NotifierHandle handle = m_notifier.exchange(0);
|
||||
HAL_StopNotifier(handle, &status);
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_ReportError(status, "stopping watchdog notifier");
|
||||
|
||||
// Join the thread to ensure the handler has exited.
|
||||
if (m_thread.joinable()) {
|
||||
@@ -84,7 +85,7 @@ void Watchdog::Impl::UpdateAlarm() {
|
||||
1e6),
|
||||
&status);
|
||||
}
|
||||
wpi_setGlobalHALError(status);
|
||||
FRC_CheckErrorStatus(status, "updating watchdog notifier alarm");
|
||||
}
|
||||
|
||||
void Watchdog::Impl::Main() {
|
||||
@@ -141,7 +142,11 @@ Watchdog::Watchdog(units::second_t timeout, std::function<void()> callback)
|
||||
: m_timeout(timeout), m_callback(std::move(callback)), m_impl(GetImpl()) {}
|
||||
|
||||
Watchdog::~Watchdog() {
|
||||
Disable();
|
||||
try {
|
||||
Disable();
|
||||
} catch (const RuntimeError& e) {
|
||||
e.Report();
|
||||
}
|
||||
}
|
||||
|
||||
Watchdog::Watchdog(Watchdog&& rhs) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/shuffleboard/ComplexWidget.h"
|
||||
#include "frc/shuffleboard/ShuffleboardComponent.h"
|
||||
#include "frc/shuffleboard/ShuffleboardLayout.h"
|
||||
@@ -56,8 +57,8 @@ ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& title) {
|
||||
wpi::SmallVector<char, 16> storage;
|
||||
auto titleRef = title.toStringRef(storage);
|
||||
if (m_layouts.count(titleRef) == 0) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
InvalidParameter, "No layout with the given title has been defined");
|
||||
throw FRC_MakeError(err::InvalidParameter,
|
||||
"No layout with the given title has been defined");
|
||||
}
|
||||
return *m_layouts[titleRef];
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -85,9 +85,8 @@ nt::NetworkTableEntry SmartDashboard::GetEntry(wpi::StringRef key) {
|
||||
}
|
||||
|
||||
void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
|
||||
if (data == nullptr) {
|
||||
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
||||
return;
|
||||
if (!data) {
|
||||
throw FRC_MakeError(err::NullParameter, "value");
|
||||
}
|
||||
auto& inst = Singleton::GetInstance();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
@@ -103,9 +102,8 @@ void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
|
||||
}
|
||||
|
||||
void SmartDashboard::PutData(Sendable* value) {
|
||||
if (value == nullptr) {
|
||||
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
||||
return;
|
||||
if (!value) {
|
||||
throw FRC_MakeError(err::NullParameter, "value");
|
||||
}
|
||||
auto name = SendableRegistry::GetInstance().GetName(value);
|
||||
if (!name.empty()) {
|
||||
@@ -118,8 +116,7 @@ Sendable* SmartDashboard::GetData(wpi::StringRef key) {
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
auto it = inst.tablesToData.find(key);
|
||||
if (it == inst.tablesToData.end()) {
|
||||
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
|
||||
return nullptr;
|
||||
throw FRC_MakeError(err::SmartDashboardMissingKey, key);
|
||||
}
|
||||
return SendableRegistry::GetInstance().GetSendable(it->getValue());
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
|
||||
#include "WPILibVersion.h"
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/RobotState.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/livewindow/LiveWindow.h"
|
||||
#include "frc/smartdashboard/SmartDashboard.h"
|
||||
|
||||
@@ -54,10 +54,10 @@ class WPILibCameraServerShared : public frc::CameraServerShared {
|
||||
HAL_Report(HALUsageReporting::kResourceType_PCVideoServer, id);
|
||||
}
|
||||
void SetCameraServerError(const wpi::Twine& error) override {
|
||||
wpi_setGlobalWPIErrorWithContext(CameraServerError, error);
|
||||
FRC_ReportError(err::CameraServerError, error);
|
||||
}
|
||||
void SetVisionRunnerError(const wpi::Twine& error) override {
|
||||
wpi_setGlobalErrorWithContext(-1, error);
|
||||
FRC_ReportError(-1, error);
|
||||
}
|
||||
void ReportDriverStationError(const wpi::Twine& error) override {
|
||||
DriverStation::ReportError(error);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/I2C.h"
|
||||
#include "frc/interfaces/Accelerometer.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
@@ -23,8 +22,7 @@ class SendableBuilder;
|
||||
* an I2C bus. This class assumes the default (not alternate) sensor address of
|
||||
* 0x1D (7-bit address).
|
||||
*/
|
||||
class ADXL345_I2C : public ErrorBase,
|
||||
public Accelerometer,
|
||||
class ADXL345_I2C : public Accelerometer,
|
||||
public Sendable,
|
||||
public SendableHelper<ADXL345_I2C> {
|
||||
public:
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/SPI.h"
|
||||
#include "frc/interfaces/Accelerometer.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
@@ -20,8 +19,7 @@ namespace frc {
|
||||
* This class allows access to an Analog Devices ADXL345 3-axis accelerometer
|
||||
* via SPI. This class assumes the sensor is wired in 4-wire SPI mode.
|
||||
*/
|
||||
class ADXL345_SPI : public ErrorBase,
|
||||
public Accelerometer,
|
||||
class ADXL345_SPI : public Accelerometer,
|
||||
public Sendable,
|
||||
public SendableHelper<ADXL345_SPI> {
|
||||
public:
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/SPI.h"
|
||||
#include "frc/interfaces/Accelerometer.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
@@ -21,8 +20,7 @@ class SendableBuilder;
|
||||
*
|
||||
* This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
|
||||
*/
|
||||
class ADXL362 : public ErrorBase,
|
||||
public Accelerometer,
|
||||
class ADXL362 : public Accelerometer,
|
||||
public Sendable,
|
||||
public SendableHelper<ADXL362> {
|
||||
public:
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/SPI.h"
|
||||
#include "frc/interfaces/Gyro.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
@@ -30,7 +29,6 @@ namespace frc {
|
||||
* Only one instance of an ADXRS Gyro is supported.
|
||||
*/
|
||||
class ADXRS450_Gyro : public Gyro,
|
||||
public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<ADXRS450_Gyro> {
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <units/time.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "util/Color.h"
|
||||
#include "util/Color8Bit.h"
|
||||
|
||||
@@ -22,7 +21,7 @@ namespace frc {
|
||||
*
|
||||
* <p>Only 1 LED driver is currently supported by the roboRIO.
|
||||
*/
|
||||
class AddressableLED : public ErrorBase {
|
||||
class AddressableLED {
|
||||
public:
|
||||
class LEDData : public HAL_AddressableLEDData {
|
||||
public:
|
||||
@@ -86,7 +85,7 @@ class AddressableLED : public ErrorBase {
|
||||
*/
|
||||
explicit AddressableLED(int port);
|
||||
|
||||
~AddressableLED() override;
|
||||
~AddressableLED();
|
||||
|
||||
/**
|
||||
* Sets the length of the LED strip.
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -22,8 +21,7 @@ class SendableBuilder;
|
||||
* sensors have multiple axis and can be treated as multiple devices. Each is
|
||||
* calibrated by finding the center value over a period of time.
|
||||
*/
|
||||
class AnalogAccelerometer : public ErrorBase,
|
||||
public Sendable,
|
||||
class AnalogAccelerometer : public Sendable,
|
||||
public SendableHelper<AnalogAccelerometer> {
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "frc/AnalogTrigger.h"
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -22,9 +21,7 @@ class AnalogInput;
|
||||
/**
|
||||
* Class for supporting continuous analog encoders, such as the US Digital MA3.
|
||||
*/
|
||||
class AnalogEncoder : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<AnalogEncoder> {
|
||||
class AnalogEncoder : public Sendable, public SendableHelper<AnalogEncoder> {
|
||||
public:
|
||||
/**
|
||||
* Construct a new AnalogEncoder attached to a specific AnalogInput.
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/interfaces/Gyro.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
@@ -31,7 +30,6 @@ class AnalogInput;
|
||||
* This class is for gyro sensors that connect to an analog input.
|
||||
*/
|
||||
class AnalogGyro : public Gyro,
|
||||
public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<AnalogGyro> {
|
||||
public:
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -30,9 +29,7 @@ class DMASample;
|
||||
* are divided by the number of samples to retain the resolution, but get more
|
||||
* stable values.
|
||||
*/
|
||||
class AnalogInput : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<AnalogInput> {
|
||||
class AnalogInput : public Sendable, public SendableHelper<AnalogInput> {
|
||||
friend class AnalogTrigger;
|
||||
friend class AnalogGyro;
|
||||
friend class DMA;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -17,9 +16,7 @@ class SendableBuilder;
|
||||
/**
|
||||
* MXP analog output class.
|
||||
*/
|
||||
class AnalogOutput : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<AnalogOutput> {
|
||||
class AnalogOutput : public Sendable, public SendableHelper<AnalogOutput> {
|
||||
public:
|
||||
/**
|
||||
* Construct an analog output on the given channel.
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -21,8 +20,7 @@ class SendableBuilder;
|
||||
* units you choose, by way of the scaling and offset constants passed to the
|
||||
* constructor.
|
||||
*/
|
||||
class AnalogPotentiometer : public ErrorBase,
|
||||
public Sendable,
|
||||
class AnalogPotentiometer : public Sendable,
|
||||
public SendableHelper<AnalogPotentiometer> {
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/AnalogTriggerOutput.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -19,9 +18,7 @@ class AnalogInput;
|
||||
class DutyCycle;
|
||||
class SendableBuilder;
|
||||
|
||||
class AnalogTrigger : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<AnalogTrigger> {
|
||||
class AnalogTrigger : public Sendable, public SendableHelper<AnalogTrigger> {
|
||||
friend class AnalogTriggerOutput;
|
||||
|
||||
public:
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/interfaces/Accelerometer.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
@@ -18,8 +17,7 @@ class SendableBuilder;
|
||||
*
|
||||
* This class allows access to the roboRIO's internal accelerometer.
|
||||
*/
|
||||
class BuiltInAccelerometer : public ErrorBase,
|
||||
public Accelerometer,
|
||||
class BuiltInAccelerometer : public Accelerometer,
|
||||
public Sendable,
|
||||
public SendableHelper<BuiltInAccelerometer> {
|
||||
public:
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include <hal/CANAPITypes.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
struct CANData {
|
||||
uint8_t data[8];
|
||||
@@ -27,7 +25,7 @@ struct CANData {
|
||||
* All methods are thread save, however the buffer objects passed in
|
||||
* by the user need to not be modified for the duration of their calls.
|
||||
*/
|
||||
class CAN : public ErrorBase {
|
||||
class CAN {
|
||||
public:
|
||||
/**
|
||||
* Create a new CAN communication interface with the specific device ID.
|
||||
@@ -52,7 +50,7 @@ class CAN : public ErrorBase {
|
||||
/**
|
||||
* Closes the CAN communication.
|
||||
*/
|
||||
~CAN() override;
|
||||
~CAN();
|
||||
|
||||
CAN(CAN&&) = default;
|
||||
CAN& operator=(CAN&&) = default;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
@@ -30,9 +29,7 @@ class SendableBuilder;
|
||||
* loop control. You can only turn off closed loop control, thereby stopping
|
||||
* the compressor from operating.
|
||||
*/
|
||||
class Compressor : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Compressor> {
|
||||
class Compressor : public Sendable, public SendableHelper<Compressor> {
|
||||
public:
|
||||
/**
|
||||
* Constructor. The default PCM ID is 0.
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "frc/AnalogTrigger.h"
|
||||
#include "frc/CounterBase.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -31,8 +30,7 @@ class DMASample;
|
||||
* All counters will immediately start counting - Reset() them if you need them
|
||||
* to be zeroed before use.
|
||||
*/
|
||||
class Counter : public ErrorBase,
|
||||
public CounterBase,
|
||||
class Counter : public CounterBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Counter> {
|
||||
friend class DMA;
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
class Encoder;
|
||||
class Counter;
|
||||
@@ -16,12 +14,12 @@ class DutyCycle;
|
||||
class AnalogInput;
|
||||
class DMASample;
|
||||
|
||||
class DMA : public ErrorBase {
|
||||
class DMA {
|
||||
friend class DMASample;
|
||||
|
||||
public:
|
||||
DMA();
|
||||
~DMA() override;
|
||||
~DMA();
|
||||
|
||||
DMA& operator=(DMA&& other) = default;
|
||||
DMA(DMA&& other) = default;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -27,8 +26,7 @@ class Counter;
|
||||
* filter. The filter lets the user configure the time that an input must remain
|
||||
* high or low before it is classified as high or low.
|
||||
*/
|
||||
class DigitalGlitchFilter : public ErrorBase,
|
||||
public Sendable,
|
||||
class DigitalGlitchFilter : public Sendable,
|
||||
public SendableHelper<DigitalGlitchFilter> {
|
||||
public:
|
||||
DigitalGlitchFilter();
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class MatchDataSender;
|
||||
@@ -25,12 +23,12 @@ class MatchDataSender;
|
||||
* Provide access to the network communication data to / from the Driver
|
||||
* Station.
|
||||
*/
|
||||
class DriverStation : public ErrorBase {
|
||||
class DriverStation {
|
||||
public:
|
||||
enum Alliance { kRed, kBlue, kInvalid };
|
||||
enum MatchType { kNone, kPractice, kQualification, kElimination };
|
||||
|
||||
~DriverStation() override;
|
||||
~DriverStation();
|
||||
|
||||
DriverStation(const DriverStation&) = delete;
|
||||
DriverStation& operator=(const DriverStation&) = delete;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -29,9 +28,7 @@ class DMASample;
|
||||
* order to implement rollover checking.
|
||||
*
|
||||
*/
|
||||
class DutyCycle : public ErrorBase,
|
||||
public Sendable,
|
||||
public SendableHelper<DutyCycle> {
|
||||
class DutyCycle : public Sendable, public SendableHelper<DutyCycle> {
|
||||
friend class AnalogTrigger;
|
||||
friend class DMA;
|
||||
friend class DMASample;
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "frc/AnalogTrigger.h"
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -25,8 +24,7 @@ class DigitalSource;
|
||||
* PWM Output, the CTRE Mag Encoder, the Rev Hex Encoder, and the AM Mag
|
||||
* Encoder.
|
||||
*/
|
||||
class DutyCycleEncoder : public ErrorBase,
|
||||
public Sendable,
|
||||
class DutyCycleEncoder : public Sendable,
|
||||
public SendableHelper<DutyCycleEncoder> {
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/CounterBase.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -37,8 +36,7 @@ class DMASample;
|
||||
* All encoders will immediately start counting - Reset() them if you need them
|
||||
* to be zeroed before use.
|
||||
*/
|
||||
class Encoder : public ErrorBase,
|
||||
public CounterBase,
|
||||
class Encoder : public CounterBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Encoder> {
|
||||
friend class DMA;
|
||||
|
||||
@@ -1,63 +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 <string>
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma push_macro("GetMessage")
|
||||
#undef GetMessage
|
||||
#endif
|
||||
|
||||
namespace frc {
|
||||
|
||||
class ErrorBase;
|
||||
|
||||
/**
|
||||
* Error object represents a library error.
|
||||
*/
|
||||
class Error {
|
||||
public:
|
||||
using Code = int;
|
||||
|
||||
Error() = default;
|
||||
Error(Code code, const wpi::Twine& contextMessage, wpi::StringRef filename,
|
||||
wpi::StringRef function, int lineNumber,
|
||||
const ErrorBase* originatingObject);
|
||||
|
||||
bool operator<(const Error& rhs) const;
|
||||
|
||||
Code GetCode() const;
|
||||
std::string GetMessage() const;
|
||||
std::string GetFilename() const;
|
||||
std::string GetFunction() const;
|
||||
int GetLineNumber() const;
|
||||
const ErrorBase* GetOriginatingObject() const;
|
||||
double GetTimestamp() const;
|
||||
void Clear();
|
||||
void Set(Code code, const wpi::Twine& contextMessage, wpi::StringRef filename,
|
||||
wpi::StringRef function, int lineNumber,
|
||||
const ErrorBase* originatingObject);
|
||||
|
||||
private:
|
||||
void Report();
|
||||
|
||||
Code m_code = 0;
|
||||
std::string m_message;
|
||||
std::string m_filename;
|
||||
std::string m_function;
|
||||
int m_lineNumber = 0;
|
||||
const ErrorBase* m_originatingObject = nullptr;
|
||||
double m_timestamp = 0.0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma pop_macro("GetMessage")
|
||||
#endif
|
||||
@@ -1,239 +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 <vector>
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "frc/Error.h"
|
||||
|
||||
// Forward declared manually to avoid needing to pull in entire HAL header.
|
||||
extern "C" const char* HAL_GetErrorMessage(int32_t code);
|
||||
|
||||
#define wpi_setErrnoErrorWithContext(context) \
|
||||
this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__)
|
||||
#define wpi_setErrnoError() wpi_setErrnoErrorWithContext("")
|
||||
#define wpi_setImaqErrorWithContext(code, context) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__); \
|
||||
} while (0)
|
||||
#define wpi_setErrorWithContext(code, context) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__); \
|
||||
} while (0)
|
||||
#define wpi_setErrorWithContextRange(code, min, max, req, context) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
this->SetErrorRange((code), (min), (max), (req), (context), __FILE__, \
|
||||
__FUNCTION__, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define wpi_setHALError(code) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
this->SetError((code), HAL_GetErrorMessage(code), __FILE__, \
|
||||
__FUNCTION__, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define wpi_setHALErrorWithRange(code, min, max, req) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
this->SetErrorRange((code), (min), (max), (req), \
|
||||
HAL_GetErrorMessage(code), __FILE__, __FUNCTION__, \
|
||||
__LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define wpi_setError(code) wpi_setErrorWithContext(code, "")
|
||||
#define wpi_setStaticErrorWithContext(object, code, context) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__); \
|
||||
} while (0)
|
||||
#define wpi_setStaticError(object, code) \
|
||||
wpi_setStaticErrorWithContext(object, code, "")
|
||||
|
||||
#define wpi_setGlobalErrorWithContext(code, context) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
::frc::ErrorBase::SetGlobalError((code), (context), __FILE__, \
|
||||
__FUNCTION__, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define wpi_setGlobalHALError(code) \
|
||||
do { \
|
||||
if ((code) != 0) \
|
||||
::frc::ErrorBase::SetGlobalError((code), HAL_GetErrorMessage(code), \
|
||||
__FILE__, __FUNCTION__, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define wpi_setGlobalError(code) wpi_setGlobalErrorWithContext(code, "")
|
||||
#define wpi_setWPIErrorWithContext(error, context) \
|
||||
this->SetWPIError(wpi_error_s_##error(), wpi_error_value_##error(), \
|
||||
(context), __FILE__, __FUNCTION__, __LINE__)
|
||||
#define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, ""))
|
||||
#define wpi_setStaticWPIErrorWithContext(object, error, context) \
|
||||
object->SetWPIError(wpi_error_s_##error(), (context), __FILE__, \
|
||||
__FUNCTION__, __LINE__)
|
||||
#define wpi_setStaticWPIError(object, error) \
|
||||
wpi_setStaticWPIErrorWithContext(object, error, "")
|
||||
#define wpi_setGlobalWPIErrorWithContext(error, context) \
|
||||
::frc::ErrorBase::SetGlobalWPIError(wpi_error_s_##error(), (context), \
|
||||
__FILE__, __FUNCTION__, __LINE__)
|
||||
#define wpi_setGlobalWPIError(error) wpi_setGlobalWPIErrorWithContext(error, "")
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Base class for most objects.
|
||||
*
|
||||
* ErrorBase is the base class for most objects since it holds the generated
|
||||
* error for that object. In addition, there is a single instance of a global
|
||||
* error object.
|
||||
*/
|
||||
class ErrorBase {
|
||||
// TODO: Consider initializing instance variables and cleanup in destructor
|
||||
public:
|
||||
ErrorBase();
|
||||
virtual ~ErrorBase() = default;
|
||||
|
||||
ErrorBase(const ErrorBase&) = default;
|
||||
ErrorBase& operator=(const ErrorBase&) = default;
|
||||
ErrorBase(ErrorBase&&) = default;
|
||||
ErrorBase& operator=(ErrorBase&&) = default;
|
||||
|
||||
/**
|
||||
* @brief Retrieve the current error.
|
||||
*
|
||||
* Get the current error information associated with this sensor.
|
||||
*/
|
||||
virtual Error& GetError();
|
||||
|
||||
/**
|
||||
* @brief Retrieve the current error.
|
||||
*
|
||||
* Get the current error information associated with this sensor.
|
||||
*/
|
||||
virtual const Error& GetError() const;
|
||||
|
||||
/**
|
||||
* @brief Clear the current error information associated with this sensor.
|
||||
*/
|
||||
virtual void ClearError() const;
|
||||
|
||||
/**
|
||||
* @brief Set error information associated with a C library call that set an
|
||||
* error to the "errno" global variable.
|
||||
*
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
virtual void SetErrnoError(const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const;
|
||||
|
||||
/**
|
||||
* @brief Set the current error information associated from the nivision Imaq
|
||||
* API.
|
||||
*
|
||||
* @param success The return from the function
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
virtual void SetImaqError(int success, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const;
|
||||
|
||||
/**
|
||||
* @brief Set the current error information associated with this sensor.
|
||||
*
|
||||
* @param code The error code
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
virtual void SetError(Error::Code code, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const;
|
||||
|
||||
/**
|
||||
* @brief Set the current error information associated with this sensor.
|
||||
* Range versions use for initialization code.
|
||||
*
|
||||
* @param code The error code
|
||||
* @param minRange The minimum allowed allocation range
|
||||
* @param maxRange The maximum allowed allocation range
|
||||
* @param requestedValue The requested value to allocate
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
virtual void SetErrorRange(Error::Code code, int32_t minRange,
|
||||
int32_t maxRange, int32_t requestedValue,
|
||||
const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const;
|
||||
|
||||
/**
|
||||
* @brief Set the current error information associated with this sensor.
|
||||
*
|
||||
* @param errorMessage The error message from WPIErrors.h
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
virtual void SetWPIError(const wpi::Twine& errorMessage, Error::Code code,
|
||||
const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber) const;
|
||||
|
||||
virtual void CloneError(const ErrorBase& rhs) const;
|
||||
|
||||
/**
|
||||
* @brief Check if the current error code represents a fatal error.
|
||||
*
|
||||
* @return true if the current error is fatal.
|
||||
*/
|
||||
virtual bool StatusIsFatal() const;
|
||||
|
||||
static void SetGlobalError(Error::Code code, const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename, wpi::StringRef function,
|
||||
int lineNumber);
|
||||
|
||||
static void SetGlobalWPIError(const wpi::Twine& errorMessage,
|
||||
const wpi::Twine& contextMessage,
|
||||
wpi::StringRef filename,
|
||||
wpi::StringRef function, int lineNumber);
|
||||
|
||||
/**
|
||||
* Retrieve the last global error.
|
||||
*/
|
||||
static Error GetGlobalError();
|
||||
|
||||
/**
|
||||
* Retrieve all global errors.
|
||||
*/
|
||||
static std::vector<Error> GetGlobalErrors();
|
||||
|
||||
/**
|
||||
* Clear global errors.
|
||||
*/
|
||||
void ClearGlobalErrors();
|
||||
|
||||
protected:
|
||||
mutable Error m_error;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
139
wpilibc/src/main/native/include/frc/Errors.h
Normal file
139
wpilibc/src/main/native/include/frc/Errors.h
Normal file
@@ -0,0 +1,139 @@
|
||||
// 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 <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Runtime error exception.
|
||||
*/
|
||||
class RuntimeError : public std::runtime_error {
|
||||
public:
|
||||
RuntimeError(int32_t code, const wpi::Twine& message, const wpi::Twine& loc,
|
||||
wpi::StringRef stack);
|
||||
RuntimeError(int32_t code, const wpi::Twine& message, const char* fileName,
|
||||
int lineNumber, const char* funcName, wpi::StringRef stack);
|
||||
|
||||
int32_t code() const noexcept { return m_data->code; }
|
||||
const char* loc() const noexcept { return m_data->loc.c_str(); }
|
||||
const char* stack() const noexcept { return m_data->stack.c_str(); }
|
||||
|
||||
/**
|
||||
* Reports error to Driver Station (using HAL_SendError).
|
||||
*/
|
||||
void Report() const;
|
||||
|
||||
private:
|
||||
struct Data {
|
||||
int32_t code;
|
||||
std::string loc;
|
||||
std::string stack;
|
||||
};
|
||||
std::shared_ptr<Data> m_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets error message string for an error code.
|
||||
*/
|
||||
const char* GetErrorMessage(int32_t code);
|
||||
|
||||
/**
|
||||
* Reports an error to the driver station (using HAL_SendError).
|
||||
* Generally the FRC_ReportError wrapper macro should be used instead.
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
* @param fileName source file name
|
||||
* @param lineNumber source line number
|
||||
* @param funcName source function name
|
||||
*/
|
||||
void ReportError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber, const char* funcName);
|
||||
|
||||
/**
|
||||
* Makes a runtime error exception object. This object should be thrown
|
||||
* by the caller. Generally the FRC_MakeError wrapper macro should be used
|
||||
* instead.
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
* @param fileName source file name
|
||||
* @param lineNumber source line number
|
||||
* @param funcName source function name
|
||||
* @return runtime error object
|
||||
*/
|
||||
[[nodiscard]] RuntimeError MakeError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName);
|
||||
|
||||
namespace err {
|
||||
#define S(label, offset, message) inline constexpr int label = offset;
|
||||
#include "frc/WPIErrors.mac"
|
||||
#undef S
|
||||
} // namespace err
|
||||
|
||||
namespace warn {
|
||||
#define S(label, offset, message) inline constexpr int label = offset;
|
||||
#include "frc/WPIWarnings.mac"
|
||||
#undef S
|
||||
} // namespace warn
|
||||
} // namespace frc
|
||||
|
||||
/**
|
||||
* Reports an error to the driver station (using HAL_SendError).
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
*/
|
||||
#define FRC_ReportError(status, message) \
|
||||
do { \
|
||||
if ((status) != 0) { \
|
||||
::frc::ReportError(status, message, __FILE__, __LINE__, __FUNCTION__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* Makes a runtime error exception object. This object should be thrown
|
||||
* by the caller.
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
* @return runtime error object
|
||||
*/
|
||||
#define FRC_MakeError(status, message) \
|
||||
::frc::MakeError(status, message, __FILE__, __LINE__, __FUNCTION__)
|
||||
|
||||
/**
|
||||
* Checks a status code and depending on its value, either throws a
|
||||
* RuntimeError exception, calls ReportError, or does nothing (if no error).
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
*/
|
||||
#define FRC_CheckErrorStatus(status, message) \
|
||||
do { \
|
||||
if ((status) < 0) { \
|
||||
throw FRC_MakeError(status, message); \
|
||||
} else if ((status) > 0) { \
|
||||
FRC_ReportError(status, message); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FRC_AssertMessage(condition, message) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
throw FRC_MakeError(err::AssertionFailure, message); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FRC_Assert(condition) FRC_AssertMessage(condition, #condition)
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class DriverStation;
|
||||
@@ -17,7 +15,7 @@ class DriverStation;
|
||||
/**
|
||||
* GenericHID Interface.
|
||||
*/
|
||||
class GenericHID : public ErrorBase {
|
||||
class GenericHID {
|
||||
public:
|
||||
enum RumbleType { kLeftRumble, kRightRumble };
|
||||
|
||||
@@ -44,7 +42,7 @@ class GenericHID : public ErrorBase {
|
||||
enum JoystickHand { kLeftHand = 0, kRightHand = 1 };
|
||||
|
||||
explicit GenericHID(int port);
|
||||
~GenericHID() override = default;
|
||||
virtual ~GenericHID() = default;
|
||||
|
||||
GenericHID(GenericHID&&) = default;
|
||||
GenericHID& operator=(GenericHID&&) = default;
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include <hal/I2CTypes.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
@@ -18,7 +16,7 @@ namespace frc {
|
||||
* This class is intended to be used by sensor (and other I2C device) drivers.
|
||||
* It probably should not be used directly.
|
||||
*/
|
||||
class I2C : public ErrorBase {
|
||||
class I2C {
|
||||
public:
|
||||
enum Port { kOnboard = 0, kMXP };
|
||||
|
||||
@@ -30,7 +28,7 @@ class I2C : public ErrorBase {
|
||||
*/
|
||||
I2C(Port port, int deviceAddress);
|
||||
|
||||
~I2C() override;
|
||||
~I2C();
|
||||
|
||||
I2C(I2C&&) = default;
|
||||
I2C& operator=(I2C&&) = default;
|
||||
|
||||
@@ -10,11 +10,10 @@
|
||||
#include <hal/Interrupts.h>
|
||||
|
||||
#include "frc/AnalogTriggerType.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class InterruptableSensorBase : public ErrorBase {
|
||||
class InterruptableSensorBase {
|
||||
public:
|
||||
enum WaitResult {
|
||||
kTimeout = 0x0,
|
||||
@@ -35,7 +34,7 @@ class InterruptableSensorBase : public ErrorBase {
|
||||
/**
|
||||
* Free the resources for an interrupt event.
|
||||
*/
|
||||
~InterruptableSensorBase() override;
|
||||
virtual ~InterruptableSensorBase();
|
||||
|
||||
InterruptableSensorBase(InterruptableSensorBase&&) = default;
|
||||
InterruptableSensorBase& operator=(InterruptableSensorBase&&) = default;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/Timer.h"
|
||||
|
||||
namespace wpi {
|
||||
@@ -21,10 +20,10 @@ namespace frc {
|
||||
*
|
||||
* The subclass should call Feed() whenever the motor value is updated.
|
||||
*/
|
||||
class MotorSafety : public ErrorBase {
|
||||
class MotorSafety {
|
||||
public:
|
||||
MotorSafety();
|
||||
~MotorSafety() override;
|
||||
virtual ~MotorSafety();
|
||||
|
||||
MotorSafety(MotorSafety&& rhs);
|
||||
MotorSafety& operator=(MotorSafety&& rhs);
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Notifier : public ErrorBase {
|
||||
class Notifier {
|
||||
public:
|
||||
/**
|
||||
* Create a Notifier for timer event notification.
|
||||
@@ -63,7 +61,7 @@ class Notifier : public ErrorBase {
|
||||
/**
|
||||
* Free the resources for a timer event.
|
||||
*/
|
||||
~Notifier() override;
|
||||
~Notifier();
|
||||
|
||||
Notifier(Notifier&& rhs);
|
||||
Notifier& operator=(Notifier&& rhs);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -33,7 +32,7 @@ class SendableBuilder;
|
||||
* - 1 = minimum pulse width (currently 0.5ms)
|
||||
* - 0 = disabled (i.e. PWM output is held low)
|
||||
*/
|
||||
class PWM : public ErrorBase, public Sendable, public SendableHelper<PWM> {
|
||||
class PWM : public Sendable, public SendableHelper<PWM> {
|
||||
public:
|
||||
friend class AddressableLED;
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -18,8 +17,7 @@ class SendableBuilder;
|
||||
* Class for getting voltage, current, temperature, power and energy from the
|
||||
* CAN PDP.
|
||||
*/
|
||||
class PowerDistributionPanel : public ErrorBase,
|
||||
public Sendable,
|
||||
class PowerDistributionPanel : public Sendable,
|
||||
public SendableHelper<PowerDistributionPanel> {
|
||||
public:
|
||||
PowerDistributionPanel();
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
|
||||
#include <networktables/NetworkTable.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
@@ -30,7 +28,7 @@ namespace frc {
|
||||
* This will also interact with {@link NetworkTable} by creating a table called
|
||||
* "Preferences" with all the key-value pairs.
|
||||
*/
|
||||
class Preferences : public ErrorBase {
|
||||
class Preferences {
|
||||
public:
|
||||
/**
|
||||
* Get the one and only {@link Preferences} object.
|
||||
@@ -226,7 +224,7 @@ class Preferences : public ErrorBase {
|
||||
|
||||
protected:
|
||||
Preferences();
|
||||
~Preferences() override;
|
||||
~Preferences();
|
||||
|
||||
Preferences(Preferences&&) = default;
|
||||
Preferences& operator=(Preferences&&) = default;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <hal/Types.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/MotorSafety.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
@@ -26,9 +24,9 @@ namespace frc {
|
||||
* resources; it just tracks which indices were marked in use by Allocate and
|
||||
* not yet freed by Free.
|
||||
*/
|
||||
class Resource : public ErrorBase {
|
||||
class Resource {
|
||||
public:
|
||||
~Resource() override = default;
|
||||
virtual ~Resource() = default;
|
||||
|
||||
/**
|
||||
* Factory method to create a Resource allocation-tracker *if* needed.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user