diff --git a/README.md b/README.md index 6e1c8eb..8a0aad6 100644 --- a/README.md +++ b/README.md @@ -176,8 +176,8 @@ To undo the going back: ## CppCheck Warnings ``` -src\frc846\cpp\frc846\math\collection.cc:11:0: warning: The function 'HorizontalDeadband' is never used. [unusedFunction] -src\frc846\cpp\frc846\math\collection.cc:25:0: warning: The function 'VerticalDeadband' is never used. [unusedFunction] -src\frc846\cpp\frc846\math\collection.cc:39:0: warning: The function 'CoterminalDifference' is never used. [unusedFunction] -src\frc846\cpp\frc846\math\collection.cc:52:0: warning: The function 'CoterminalSum' is never used. [unusedFunction] +src/frc846/cpp/frc846/math/collection.cc:11:0: warning: The function 'HorizontalDeadband' is never used. [unusedFunction] +src/frc846/cpp/frc846/math/collection.cc:25:0: warning: The function 'VerticalDeadband' is never used. [unusedFunction] +src/frc846/cpp/frc846/math/collection.cc:39:0: warning: The function 'CoterminalDifference' is never used. [unusedFunction] +src/frc846/cpp/frc846/math/collection.cc:52:0: warning: The function 'CoterminalSum' is never used. [unusedFunction] ``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 30bc986..d44efbb 100644 --- a/build.gradle +++ b/build.gradle @@ -182,12 +182,7 @@ task runCppcheck(type: Exec) { } } - def cppcheckSection = """ -## CppCheck Warnings -``` -${reportContent.trim()} -``` -""" + def cppcheckSection = """## CppCheck Warnings\n```\n${reportContent.trim()}\n```\n""" def readmeFile = file('README.md') def readmeContent = readmeFile.text @@ -205,4 +200,4 @@ runCppcheck.onlyIf { !project.hasProperty('fromCI') } if (!project.hasProperty('fromCI')) { check.dependsOn runCppcheck runCppcheck.dependsOn spotlessApply -} +} \ No newline at end of file diff --git a/src/frc846/cpp/frc846/control/HigherMotorController.cc b/src/frc846/cpp/frc846/control/HigherMotorController.cc index 96849ca..6c35454 100644 --- a/src/frc846/cpp/frc846/control/HigherMotorController.cc +++ b/src/frc846/cpp/frc846/control/HigherMotorController.cc @@ -15,6 +15,10 @@ void HigherMotorController::Setup() { mmtype_, constr_params_); } +bool HigherMotorController::VerifyConnected() { + return frc846::control::MotorMonkey::VerifyConnected(); +} + void HigherMotorController::SetGains(frc846::control::base::MotorGains gains) { gains_ = gains; frc846::control::MotorMonkey::SetGains(slot_id_, gains_); diff --git a/src/frc846/cpp/frc846/control/MotorMonkey.cc b/src/frc846/cpp/frc846/control/MotorMonkey.cc index d8df8a1..de2c3fc 100644 --- a/src/frc846/cpp/frc846/control/MotorMonkey.cc +++ b/src/frc846/cpp/frc846/control/MotorMonkey.cc @@ -74,6 +74,15 @@ void MotorMonkey::Tick() { } } +bool MotorMonkey::VerifyConnected() { + for (size_t i = 0; i < CONTROLLER_REGISTRY_SIZE; i++) { + if (controller_registry[i] != nullptr) { + if (!controller_registry[i]->VerifyConnected()) { return false; } + } + } + return true; +} + size_t MotorMonkey::ConstructController( frc846::control::base::MotorMonkeyType type, frc846::control::config::MotorConstructionParameters params) { diff --git a/src/frc846/cpp/frc846/control/hardware/SparkMXFX_interm.cc b/src/frc846/cpp/frc846/control/hardware/SparkMXFX_interm.cc index 9776a25..bc86728 100644 --- a/src/frc846/cpp/frc846/control/hardware/SparkMXFX_interm.cc +++ b/src/frc846/cpp/frc846/control/hardware/SparkMXFX_interm.cc @@ -8,6 +8,11 @@ namespace frc846::control::hardware { set_last_error(code); \ if (last_error_ != ControllerErrorCodes::kAllOK) return +bool SparkMXFX_interm::VerifyConnected() { + esc_->GetFirmwareVersion(); + return esc_->GetFirmwareVersion() != 0; +} + SparkMXFX_interm::SparkMXFX_interm(int can_id, units::millisecond_t max_wait_time, bool is_controller_spark_flex) { esc_ = is_controller_spark_flex diff --git a/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc b/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc index 22434f9..5fe51bf 100644 --- a/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc +++ b/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc @@ -2,6 +2,8 @@ namespace frc846::control::hardware { +bool TalonFX_interm::VerifyConnected() { return talon_.IsAlive(); } + TalonFX_interm::TalonFX_interm( int can_id, std::string bus, units::millisecond_t max_wait_time) : talon_(can_id, bus), max_wait_time_(max_wait_time) {} diff --git a/src/frc846/cpp/frc846/control/simulation/MCSimulator.cc b/src/frc846/cpp/frc846/control/hardware/simulation/MCSimulator.cc similarity index 97% rename from src/frc846/cpp/frc846/control/simulation/MCSimulator.cc rename to src/frc846/cpp/frc846/control/hardware/simulation/MCSimulator.cc index 7085001..310d485 100644 --- a/src/frc846/cpp/frc846/control/simulation/MCSimulator.cc +++ b/src/frc846/cpp/frc846/control/hardware/simulation/MCSimulator.cc @@ -1,4 +1,4 @@ -#include "frc846/control/simulation/MCSimulator.h" +#include "frc846/control/hardware/simulation/MCSimulator.h" #include "frc846/control/calculators/CurrentTorqueCalculator.h" #include "frc846/control/calculators/VelocityPositionEstimator.h" diff --git a/src/frc846/include/frc846/control/HigherMotorController.h b/src/frc846/include/frc846/control/HigherMotorController.h index 1d6ea70..05e833c 100644 --- a/src/frc846/include/frc846/control/HigherMotorController.h +++ b/src/frc846/include/frc846/control/HigherMotorController.h @@ -86,6 +86,9 @@ class HigherMotorController { // Custom soft limits maintained by HigherMotorController void SetSoftLimits(config::SoftLimits soft_limits); + // verify's if the hardware is connected + bool VerifyConnected(); + private: frc846::control::base::MotorMonkeyType mmtype_; frc846::control::config::MotorConstructionParameters constr_params_; diff --git a/src/frc846/include/frc846/control/MotorMonkey.h b/src/frc846/include/frc846/control/MotorMonkey.h index 5f734c8..5970ac4 100644 --- a/src/frc846/include/frc846/control/MotorMonkey.h +++ b/src/frc846/include/frc846/control/MotorMonkey.h @@ -90,6 +90,8 @@ class MotorMonkey { static std::string parseError( frc846::control::hardware::ControllerErrorCodes err); + static bool VerifyConnected(); + private: static frc846::base::Loggable loggable_; diff --git a/src/frc846/include/frc846/control/hardware/IntermediateController.h b/src/frc846/include/frc846/control/hardware/IntermediateController.h index 861d146..00a6799 100644 --- a/src/frc846/include/frc846/control/hardware/IntermediateController.h +++ b/src/frc846/include/frc846/control/hardware/IntermediateController.h @@ -64,6 +64,8 @@ class IntermediateController { virtual units::ampere_t GetCurrent() = 0; virtual ControllerErrorCodes GetLastErrorCode() = 0; + + virtual bool VerifyConnected() = 0; // changed }; } // namespace frc846::control::hardware \ No newline at end of file diff --git a/src/frc846/include/frc846/control/hardware/SparkMXFX_interm.h b/src/frc846/include/frc846/control/hardware/SparkMXFX_interm.h index 65a14c4..da840c9 100644 --- a/src/frc846/include/frc846/control/hardware/SparkMXFX_interm.h +++ b/src/frc846/include/frc846/control/hardware/SparkMXFX_interm.h @@ -158,6 +158,15 @@ class SparkMXFX_interm : public IntermediateController { */ void ZeroEncoder(units::radian_t position) override; + /* + VerifyHardware() + + Checks the TalonFX hardware and verifies it is functioning correctly. + + @return boolean indicating whether the hardware is verified successfully. + */ + bool VerifyConnected() override; // added + /* GetVelocity() diff --git a/src/frc846/include/frc846/control/hardware/TalonFX_interm.h b/src/frc846/include/frc846/control/hardware/TalonFX_interm.h index 6b080a9..f7b099b 100644 --- a/src/frc846/include/frc846/control/hardware/TalonFX_interm.h +++ b/src/frc846/include/frc846/control/hardware/TalonFX_interm.h @@ -156,6 +156,15 @@ class TalonFX_interm : public IntermediateController { */ void ZeroEncoder(units::radian_t position) override; + /* + VerifyHardware() + + Checks the TalonFX hardware and verifies it is functioning correctly. + + @return boolean indicating whether the hardware is verified successfully. + */ + bool VerifyConnected() override; // added + /* GetVelocity() diff --git a/src/frc846/include/frc846/control/simulation/MCSimulator.h b/src/frc846/include/frc846/control/hardware/simulation/MCSimulator.h similarity index 76% rename from src/frc846/include/frc846/control/simulation/MCSimulator.h rename to src/frc846/include/frc846/control/hardware/simulation/MCSimulator.h index dee7e70..ab42e49 100644 --- a/src/frc846/include/frc846/control/simulation/MCSimulator.h +++ b/src/frc846/include/frc846/control/hardware/simulation/MCSimulator.h @@ -8,6 +8,7 @@ #include +#include "frc846/control/hardware/IntermediateController.h" #include "frc846/control/base/motor_gains.h" #include "frc846/control/base/motor_specs.h" #include "frc846/wpilib/846_units.h" @@ -20,7 +21,7 @@ MCSimulator A class that simulates a motor controller. Uses motor dynamics to simulate position and velocity accurately. */ -class MCSimulator { +class MCSimulator : frc846::control::hardware::IntermediateController { public: MCSimulator(frc846::control::base::MotorSpecs specs, frc846::wpilib::unit_ohm circuit_resistance, @@ -33,19 +34,19 @@ class MCSimulator { */ void Tick(units::volt_t battery_voltage, units::newton_meter_t load); - void WriteDC(double duty_cycle); - void WriteVelocity(units::radians_per_second_t velocity); - void WritePosition(units::radian_t position); + void WriteDC(double duty_cycle) override; + void WriteVelocity(units::radians_per_second_t velocity) override; + void WritePosition(units::radian_t position) override; - units::radian_t GetPosition(); - units::radians_per_second_t GetVelocity(); + units::radian_t GetPosition() override; + units::radians_per_second_t GetVelocity() override; /* ZeroEncoder() Sets the motor's position to specified value. */ - void ZeroEncoder(units::radian_t position = 0_rad); + void ZeroEncoder(units::radian_t position = 0_rad) override; /* DisablePositionPacket() @@ -60,7 +61,7 @@ class MCSimulator { */ void DisableVelocityPacket(); - void SetGains(frc846::control::base::MotorGains gains); + void SetGains(frc846::control::base::MotorGains gains) override; private: frc846::control::base::MotorSpecs specs;