From efeec9bc2a22cf6368b1fec0f8d99b0cb9f7535b Mon Sep 17 00:00:00 2001 From: prak132 Date: Thu, 23 Jan 2025 17:29:27 -0800 Subject: [PATCH 1/5] simulation fixes added friction --- .../cpp/frc846/control/hardware/simulation/MCSimulator.cc | 7 +++++++ src/frc846/include/frc846/control/base/motor_specs.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/frc846/cpp/frc846/control/hardware/simulation/MCSimulator.cc b/src/frc846/cpp/frc846/control/hardware/simulation/MCSimulator.cc index 6385752..de05941 100644 --- a/src/frc846/cpp/frc846/control/hardware/simulation/MCSimulator.cc +++ b/src/frc846/cpp/frc846/control/hardware/simulation/MCSimulator.cc @@ -39,6 +39,10 @@ void MCSimulator::Tick() { units::newton_meter_t torque_output = frc846::control::calculators::CurrentTorqueCalculator::current_to_torque( pred_current_, specs); + units::newton_meter_t friction_torque = + specs.stall_torque * specs.friction_loss * + (velocity_ / units::math::abs(velocity_)); + if (units::math::abs(velocity_) < 0.01_rad_per_s) { friction_torque = 0_Nm; } torque_output -= load_; std::chrono::microseconds current_time = @@ -50,6 +54,9 @@ void MCSimulator::Tick() { units::radians_per_second_t new_velocity = frc846::control::calculators::VelocityPositionEstimator::predict_velocity( velocity_, torque_output, loop_time, rotational_inertia_); + new_velocity = + units::radians_per_second_t{std::clamp(new_velocity.to(), + (-specs.free_speed).to(), specs.free_speed.to())}; units::radians_per_second_t avg_velocity = (velocity_ + new_velocity) / 2.0; position_ = diff --git a/src/frc846/include/frc846/control/base/motor_specs.h b/src/frc846/include/frc846/control/base/motor_specs.h index 34f3271..0e4e8f8 100644 --- a/src/frc846/include/frc846/control/base/motor_specs.h +++ b/src/frc846/include/frc846/control/base/motor_specs.h @@ -25,6 +25,7 @@ struct MotorSpecs { units::ampere_t stall_current; units::ampere_t free_current; units::newton_meter_t stall_torque; + double friction_loss = 0.01; }; /* From b9f1de919d751006d6971e8e6a4f1d666e49a0d1 Mon Sep 17 00:00:00 2001 From: DhananjayKhulbe Date: Fri, 24 Jan 2025 19:22:03 -0800 Subject: [PATCH 2/5] string_view fixes --- README.md | 8 ++++---- simgui-ds.json | 5 +++++ simgui.json | 7 +++++-- src/frc846/cpp/frc846/base/Loggable.cc | 6 ++++-- src/frc846/cpp/frc846/control/MotorMonkey.cc | 4 ++-- src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc | 2 +- src/frc846/cpp/frc846/robot/GenericRobot.cc | 7 ++++--- src/frc846/include/frc846/base/FunkyLogSystem.h | 4 ++-- src/frc846/include/frc846/base/Loggable.h | 6 +++--- src/frc846/include/frc846/control/MotorMonkey.h | 2 +- .../include/frc846/control/config/construction_params.h | 2 +- .../include/frc846/control/hardware/TalonFX_interm.h | 2 +- src/frc846/include/frc846/robot/GenericRobot.h | 6 +++--- src/frc846/include/frc846/robot/swerve/swerve_module.h | 2 +- src/y2025/include/rsighandler.h | 2 +- src/y2025/include/subsystems/robot_container.h | 2 +- 16 files changed, 39 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4c8186b..c9f13e6 100644 --- a/README.md +++ b/README.md @@ -173,8 +173,8 @@ To undo the going back: ## CppCheck Warnings ``` -src\frc846\cpp\frc846\robot\swerve\drivetrain.cc:173:64: warning: Variable 'accel_target' is assigned a value that is never used. [unreadVariable] -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/robot/swerve/drivetrain.cc:174:64: warning: Variable 'accel_target' is assigned a value that is never used. [unreadVariable] +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/simgui-ds.json b/simgui-ds.json index 07f1415..b8da04f 100644 --- a/simgui-ds.json +++ b/simgui-ds.json @@ -1,4 +1,9 @@ { + "FMS": { + "window": { + "visible": false + } + }, "Keyboard 0 Settings": { "window": { "visible": true diff --git a/simgui.json b/simgui.json index 2e61c3e..ab9b71c 100644 --- a/simgui.json +++ b/simgui.json @@ -32,12 +32,15 @@ "Connections": { "open": true }, - "Server": { - "Subscribers": { + "Elastic@1": { + "Publishers": { "open": true }, "open": true }, + "Server": { + "open": true + }, "visible": true } } diff --git a/src/frc846/cpp/frc846/base/Loggable.cc b/src/frc846/cpp/frc846/base/Loggable.cc index 7848e21..79d4d29 100644 --- a/src/frc846/cpp/frc846/base/Loggable.cc +++ b/src/frc846/cpp/frc846/base/Loggable.cc @@ -4,13 +4,15 @@ namespace frc846::base { -std::string Loggable::Join(std::string p, std::string n) { return p + "/" + n; } +std::string_view Loggable::Join(std::string p, std::string n) { + return p + "/" + n; +} unsigned int Loggable::GetWarnCount() { return warn_count_; } unsigned int Loggable::GetErrorCount() { return error_count_; } -std::unordered_set Loggable::used_preferences_{}; +std::unordered_set Loggable::used_preferences_{}; unsigned int Loggable::warn_count_ = 0; unsigned int Loggable::error_count_ = 0; diff --git a/src/frc846/cpp/frc846/control/MotorMonkey.cc b/src/frc846/cpp/frc846/control/MotorMonkey.cc index 40830b4..2986d1b 100644 --- a/src/frc846/cpp/frc846/control/MotorMonkey.cc +++ b/src/frc846/cpp/frc846/control/MotorMonkey.cc @@ -6,7 +6,7 @@ #include #include -#include +#include #include "frc846/control/hardware/SparkMXFX_interm.h" #include "frc846/control/hardware/TalonFX_interm.h" @@ -469,7 +469,7 @@ void MotorMonkey::SetSoftLimits(size_t slot_id, units::radian_t forward_limit, LOG_IF_ERROR("SetSoftLimits"); } -std::string MotorMonkey::parseError( +std::string_view MotorMonkey::parseError( frc846::control::hardware::ControllerErrorCodes err) { switch (err) { case frc846::control::hardware::ControllerErrorCodes::kAllOK: return "All OK"; diff --git a/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc b/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc index 801e7c8..95bda19 100644 --- a/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc +++ b/src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc @@ -5,7 +5,7 @@ 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) + int can_id, std::string_view bus, units::millisecond_t max_wait_time) : talon_(can_id, bus), max_wait_time_(max_wait_time) {} void TalonFX_interm::Tick() { diff --git a/src/frc846/cpp/frc846/robot/GenericRobot.cc b/src/frc846/cpp/frc846/robot/GenericRobot.cc index 95e96fe..d5e1c03 100644 --- a/src/frc846/cpp/frc846/robot/GenericRobot.cc +++ b/src/frc846/cpp/frc846/robot/GenericRobot.cc @@ -64,7 +64,8 @@ void GenericRobot::StartCompetition() { frc::SmartDashboard::PutData( "get_prune_list", new frc846::wpilib::NTAction([this] { - for (const std::string& x : frc846::base::Loggable::ListKeysToPrune()) { + for (const std::string_view& x : + frc846::base::Loggable::ListKeysToPrune()) { Log("Key {} found in prune list.", x); } })); @@ -131,7 +132,7 @@ void GenericRobot::StartCompetition() { loop.Clear(); } else if (mode == Mode::kAutonomous) { // Get and run selected auto command - std::string option_name = auto_chooser_.GetSelected(); + std::string_view option_name = auto_chooser_.GetSelected(); auto_command_ = autos_[option_name]; if (auto_command_ != nullptr) { @@ -222,7 +223,7 @@ void GenericRobot::VerifyHardware() { generic_robot_container_->VerifyHardware(); } -void GenericRobot::AddAuto(std::string name, frc2::Command* command) { +void GenericRobot::AddAuto(std::string_view name, frc2::Command* command) { auto_chooser_.AddOption(name, name); autos_[name] = command; frc::SmartDashboard::PutData(&auto_chooser_); diff --git a/src/frc846/include/frc846/base/FunkyLogSystem.h b/src/frc846/include/frc846/base/FunkyLogSystem.h index e4818a4..ec3ffb0 100644 --- a/src/frc846/include/frc846/base/FunkyLogSystem.h +++ b/src/frc846/include/frc846/base/FunkyLogSystem.h @@ -121,7 +121,7 @@ class FunkyLogger { } public: - FunkyLogger(std::string pname) : pname_{pname} {}; + FunkyLogger(std::string_view pname) : pname_{pname} {}; template void Log(fmt::format_string fmt, T&&... args) const { @@ -139,4 +139,4 @@ class FunkyLogger { } }; -} // namespace frc846::base +} // namespace frc846::base \ No newline at end of file diff --git a/src/frc846/include/frc846/base/Loggable.h b/src/frc846/include/frc846/base/Loggable.h index 40aa852..55424c4 100644 --- a/src/frc846/include/frc846/base/Loggable.h +++ b/src/frc846/include/frc846/base/Loggable.h @@ -130,7 +130,7 @@ class Loggable { static unsigned int GetWarnCount(); static unsigned int GetErrorCount(); - static std::string Join(std::string p, std::string n); + static std::string_view Join(std::string p, std::string n); static std::vector ListKeysToPrune(); @@ -141,7 +141,7 @@ class Loggable { const std::string name_; - static std::unordered_set used_preferences_; + static std::unordered_set used_preferences_; static unsigned int warn_count_; static unsigned int error_count_; @@ -149,4 +149,4 @@ class Loggable { frc846::base::FunkyLogger logger; }; -} // namespace frc846::base +} // namespace frc846::base \ No newline at end of file diff --git a/src/frc846/include/frc846/control/MotorMonkey.h b/src/frc846/include/frc846/control/MotorMonkey.h index 3090225..4ce75dd 100644 --- a/src/frc846/include/frc846/control/MotorMonkey.h +++ b/src/frc846/include/frc846/control/MotorMonkey.h @@ -118,7 +118,7 @@ class MotorMonkey { static void SetSoftLimits(size_t slot_id, units::radian_t forward_limit, units::radian_t reverse_limit); - static std::string parseError( + static std::string_view parseError( frc846::control::hardware::ControllerErrorCodes err); static bool VerifyConnected(); diff --git a/src/frc846/include/frc846/control/config/construction_params.h b/src/frc846/include/frc846/control/config/construction_params.h index ddb8656..44a07c7 100644 --- a/src/frc846/include/frc846/control/config/construction_params.h +++ b/src/frc846/include/frc846/control/config/construction_params.h @@ -44,7 +44,7 @@ struct MotorConstructionParameters { frc846::wpilib::unit_kg_m_sq rotational_inertia; - std::string bus = ""; + std::string_view bus = ""; units::millisecond_t max_wait_time = 20_ms; }; diff --git a/src/frc846/include/frc846/control/hardware/TalonFX_interm.h b/src/frc846/include/frc846/control/hardware/TalonFX_interm.h index f6c42ed..92252a3 100644 --- a/src/frc846/include/frc846/control/hardware/TalonFX_interm.h +++ b/src/frc846/include/frc846/control/hardware/TalonFX_interm.h @@ -15,7 +15,7 @@ TalonFX hardware. */ class TalonFX_interm : public IntermediateController { public: - TalonFX_interm(int can_id, std::string bus = "", + TalonFX_interm(int can_id, std::string_view bus = "", units::millisecond_t max_wait_time = 20_ms); /* Tick() diff --git a/src/frc846/include/frc846/robot/GenericRobot.h b/src/frc846/include/frc846/robot/GenericRobot.h index bd93a01..581d828 100644 --- a/src/frc846/include/frc846/robot/GenericRobot.h +++ b/src/frc846/include/frc846/robot/GenericRobot.h @@ -35,7 +35,7 @@ class GenericRobot : public frc::RobotBase, public frc846::base::Loggable { void VerifyHardware(); - void AddAuto(std::string name, frc2::Command* command); + void AddAuto(std::string_view name, frc2::Command* command); private: hal::Handle notifier_; @@ -47,8 +47,8 @@ class GenericRobot : public frc::RobotBase, public frc846::base::Loggable { GenericRobotContainer* generic_robot_container_; frc2::Command* auto_command_ = nullptr; - frc::SendableChooser auto_chooser_; - std::unordered_map autos_; + frc::SendableChooser auto_chooser_; + std::unordered_map autos_; }; } // namespace frc846::robot diff --git a/src/frc846/include/frc846/robot/swerve/swerve_module.h b/src/frc846/include/frc846/robot/swerve/swerve_module.h index 1125343..9cc735c 100644 --- a/src/frc846/include/frc846/robot/swerve/swerve_module.h +++ b/src/frc846/include/frc846/robot/swerve/swerve_module.h @@ -57,7 +57,7 @@ struct SwerveModuleCommonConfig { steer_conv_unit steer_reduction; drive_conv_unit drive_reduction; - std::string bus = ""; + std::string_view bus = ""; }; /* diff --git a/src/y2025/include/rsighandler.h b/src/y2025/include/rsighandler.h index b421818..4d31c2f 100644 --- a/src/y2025/include/rsighandler.h +++ b/src/y2025/include/rsighandler.h @@ -14,7 +14,7 @@ #include void handler(int sig) { - std::map sigErrors; + std::map sigErrors; sigErrors[SIGFPE] = "FATAL ERROR >> Arithmetic Error, SIGFPE"; sigErrors[SIGILL] = "FATAL ERROR >> Illegal Instruction, SIGILL"; diff --git a/src/y2025/include/subsystems/robot_container.h b/src/y2025/include/subsystems/robot_container.h index 5a96742..5fbea59 100644 --- a/src/y2025/include/subsystems/robot_container.h +++ b/src/y2025/include/subsystems/robot_container.h @@ -15,7 +15,7 @@ class RobotContainer : public frc846::robot::GenericRobotContainer { drivetrain_constructor_.getDrivetrainConfigs()}; RobotContainer() { - RegisterPreference("init_drivetrain", true); + RegisterPreference("init_drivetrain", false); RegisterPreference("init_leds", true); control_input_.Init(); From 5f7a45abc91e23f16df663d224b72edd8c3fb9cf Mon Sep 17 00:00:00 2001 From: VyaasBaskar Date: Sat, 25 Jan 2025 11:45:54 -0800 Subject: [PATCH 3/5] Applied formatting for reef alignment --- src/frc846/cpp/frc846/robot/swerve/drivetrain.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/frc846/cpp/frc846/robot/swerve/drivetrain.cc b/src/frc846/cpp/frc846/robot/swerve/drivetrain.cc index 5e93149..2b33dd0 100644 --- a/src/frc846/cpp/frc846/robot/swerve/drivetrain.cc +++ b/src/frc846/cpp/frc846/robot/swerve/drivetrain.cc @@ -177,9 +177,9 @@ DrivetrainReadings DrivetrainSubsystem::ReadFromHardware() { frc846::robot::swerve::odometry::SwervePose new_pose{ .position = odometry_ - .calculate({bearing, steer_positions, drive_positions, - GetPreferenceValue_double("odom_fudge_factor")}) - .position, + .calculate({bearing, steer_positions, drive_positions, + GetPreferenceValue_double("odom_fudge_factor")}) + .position, .bearing = bearing, .velocity = velocity, }; From bf214f6d18027bfbd79a72a7dc513eb478926922 Mon Sep 17 00:00:00 2001 From: Vyaas Baskar <68795520+VyaasBaskar@users.noreply.github.com> Date: Sat, 25 Jan 2025 11:48:03 -0800 Subject: [PATCH 4/5] Update robot_container.h --- src/y2025/include/subsystems/robot_container.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/y2025/include/subsystems/robot_container.h b/src/y2025/include/subsystems/robot_container.h index 5fbea59..5a96742 100644 --- a/src/y2025/include/subsystems/robot_container.h +++ b/src/y2025/include/subsystems/robot_container.h @@ -15,7 +15,7 @@ class RobotContainer : public frc846::robot::GenericRobotContainer { drivetrain_constructor_.getDrivetrainConfigs()}; RobotContainer() { - RegisterPreference("init_drivetrain", false); + RegisterPreference("init_drivetrain", true); RegisterPreference("init_leds", true); control_input_.Init(); From 085ed48c83e64573ce35fd927fd4f28fc90a908f Mon Sep 17 00:00:00 2001 From: VyaasBaskar Date: Sat, 25 Jan 2025 11:55:21 -0800 Subject: [PATCH 5/5] Fixed warning related to use of string_view in GenericRobot.cc --- src/frc846/cpp/frc846/robot/GenericRobot.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/frc846/cpp/frc846/robot/GenericRobot.cc b/src/frc846/cpp/frc846/robot/GenericRobot.cc index d5e1c03..112d414 100644 --- a/src/frc846/cpp/frc846/robot/GenericRobot.cc +++ b/src/frc846/cpp/frc846/robot/GenericRobot.cc @@ -64,8 +64,7 @@ void GenericRobot::StartCompetition() { frc::SmartDashboard::PutData( "get_prune_list", new frc846::wpilib::NTAction([this] { - for (const std::string_view& x : - frc846::base::Loggable::ListKeysToPrune()) { + for (const std::string& x : frc846::base::Loggable::ListKeysToPrune()) { Log("Key {} found in prune list.", x); } }));