Skip to content

Commit

Permalink
[wombat/utils] add LimitVoltage function (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty authored Jan 7, 2024
1 parent 4784039 commit f90fec5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
10 changes: 10 additions & 0 deletions wombat/src/main/cpp/utils/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "utils/Util.h"

#include <frc/RobotController.h>

units::second_t wom::utils::now() {
uint64_t now = frc::RobotController::GetFPGATime();
return static_cast<double>(now) / 1000000 * 1_s;
Expand Down Expand Up @@ -33,3 +35,11 @@ double wom::utils::deadzone(double val, double deadzone) {
double wom::utils::spow2(double val) {
return val * val * (val > 0 ? 1 : -1);
}

units::volt_t wom::utils::LimitVoltage(units::volt_t voltage) {
if (voltage >= frc::RobotController::GetBatteryVoltage()) {
return frc::RobotController::GetBatteryVoltage() - 0.5_V;
}

return voltage;
}
2 changes: 0 additions & 2 deletions wombat/src/main/include/utils/Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include <string>

#include "utils/Util.h"

namespace wom {
namespace utils {
class Encoder {
Expand Down
2 changes: 0 additions & 2 deletions wombat/src/main/include/utils/Pathplanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <frc/trajectory/TrajectoryUtil.h>
#include <wpi/fs.h>

#include "utils/Util.h"

namespace wom {
namespace utils {
class Pathplanner {
Expand Down
3 changes: 3 additions & 0 deletions wombat/src/main/include/utils/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <frc/geometry/Pose3d.h>
#include <networktables/NetworkTable.h>
#include <units/time.h>
#include <units/voltage.h>

#include <functional>
#include <iostream>
Expand Down Expand Up @@ -95,5 +96,7 @@ void WritePose3NT(std::shared_ptr<nt::NetworkTable> table, frc::Pose3d pose);

double deadzone(double val, double deadzone = 0.05);
double spow2(double val);

units::volt_t LimitVoltage(units::volt_t voltage);
} // namespace utils
} // namespace wom
2 changes: 1 addition & 1 deletion wombat/src/main/include/utils/VoltageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VoltageController {
units::volt_t GetBusVoltage() const;

/**
* Create a MotorVoltageController with a given frc::MotorController
* Create a VoltageController with a given frc::MotorController
* subclass. Please note that this creates an unsafe pointer (will never
* dealloc)
*/
Expand Down

0 comments on commit f90fec5

Please sign in to comment.