Skip to content

Commit

Permalink
Added style.standard, reformatted all files
Browse files Browse the repository at this point in the history
  • Loading branch information
VyaasBaskar committed Dec 20, 2024
1 parent 09cfed4 commit 6c07e13
Show file tree
Hide file tree
Showing 51 changed files with 294 additions and 365 deletions.
18 changes: 15 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ spotless {
exclude '**/build/**', '**/build-*/**'
}
def selectedClangVersion = project.hasProperty('fromCI') ? '17.0.6' : '18.1.8'
clangFormat(selectedClangVersion).style('Google')

def styleFile = file('style.standard')
def styleConfig = styleFile.text.trim()

clangFormat(selectedClangVersion).style(styleConfig)
}
groovyGradle {
target fileTree('src') {
Expand All @@ -126,11 +130,17 @@ spotless {
}
}

check.dependsOn spotlessApply
if (!project.hasProperty('fromCI')) {
check.dependsOn spotlessApply
}

task runCppcheck(type: Exec) {
def outputBuffer = new ByteArrayOutputStream()

if (project.hasProperty('runningCppCheckTest')) {
println "Running cppcheck in CI mode - will fail on critical issues or too many warnings."
}

commandLine 'cppcheck', '--enable=all', '--template=gcc',
'--force', '--suppress=missingIncludeSystem', '--suppress=missingInclude', '--check-level=exhaustive', 'src/'

Expand Down Expand Up @@ -176,4 +186,6 @@ ${reportContent.trim()}
}
}

check.dependsOn runCppcheck
if (!project.hasProperty('fromCI')) {
check.dependsOn runCppcheck
}
4 changes: 1 addition & 3 deletions src/frc846/cpp/frc846/base/FunkyLogSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ void FunkyLogSystem::LogThread(int rateLimit, std::string logFileName) {
while (!FunkyLogSystem::messages.empty()) {
LogMessage msg = FunkyLogSystem::messages.front();
runningCharCounter += msg.char_count;
if (runningCharCounter > rateLimit) {
break;
}
if (runningCharCounter > rateLimit) { break; }

logBundle += msg.pack() + "\n";
FunkyLogSystem::messages.pop();
Expand Down
16 changes: 4 additions & 12 deletions src/frc846/cpp/frc846/base/Loggable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,22 @@ bool Loggable::CheckPreferenceKeyExists(std::string key) {
}

double Loggable::GetPreferenceValue_double(std::string key) {
if (!CheckPreferenceKeyExists(key)) {
return 0;
}
if (!CheckPreferenceKeyExists(key)) { return 0; }
return frc::Preferences::GetDouble(name_ + "/" + key);
}

bool Loggable::GetPreferenceValue_bool(std::string key) {
if (!CheckPreferenceKeyExists(key)) {
return false;
}
if (!CheckPreferenceKeyExists(key)) { return false; }
return frc::Preferences::GetBoolean(name_ + "/" + key);
}

int Loggable::GetPreferenceValue_int(std::string key) {
if (!CheckPreferenceKeyExists(key)) {
return 0;
}
if (!CheckPreferenceKeyExists(key)) { return 0; }
return frc::Preferences::GetInt(name_ + "/" + key);
}

std::string Loggable::GetPreferenceValue_string(std::string key) {
if (!CheckPreferenceKeyExists(key)) {
return "";
}
if (!CheckPreferenceKeyExists(key)) { return ""; }
return frc::Preferences::GetString(name_ + "/" + key);
}

Expand Down
8 changes: 2 additions & 6 deletions src/frc846/cpp/frc846/base/compression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ std::vector<uint8_t> Compression::pack_bytes(std::vector<uint8_t> conv) {
}
}

if (bitCount > 0) {
output.push_back((buffer >> 16) & 0xFF);
}
if (bitCount > 0) { output.push_back((buffer >> 16) & 0xFF); }

return output;
}
Expand All @@ -53,9 +51,7 @@ std::vector<uint8_t> Compression::compress(const std::string& data) {
std::vector<uint8_t> conv;
for (char c : data) {
auto [val, is_upper] = char_conv(c);
if (is_upper) {
conv.push_back((uint8_t)63);
}
if (is_upper) { conv.push_back((uint8_t)63); }
conv.push_back(val);
}
std::vector<uint8_t> packed = pack_bytes(conv);
Expand Down
13 changes: 6 additions & 7 deletions src/frc846/cpp/frc846/control/HigherMotorController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ HigherMotorController::HigherMotorController(
: mmtype_(mmtype), constr_params_(params) {}

void HigherMotorController::Setup() {
slot_id_ = frc846::control::MotorMonkey::ConstructController(mmtype_,
constr_params_);
slot_id_ = frc846::control::MotorMonkey::ConstructController(
mmtype_, constr_params_);
// TODO: Config here as well
}

Expand Down Expand Up @@ -45,15 +45,14 @@ void HigherMotorController::WriteTorque(units::newton_meter_t torque) {

void HigherMotorController::WriteVelocity(
units::radians_per_second_t velocity) {
double dc_target = gains_.calculate((velocity - GetVelocity()).to<double>(),
0.0, 0.0, load_.to<double>());
double dc_target = gains_.calculate(
(velocity - GetVelocity()).to<double>(), 0.0, 0.0, load_.to<double>());
WriteDC(dc_target);
}

void HigherMotorController::WritePosition(units::radian_t position) {
double dc_target =
gains_.calculate((position - GetPosition()).to<double>(), 0.0,
GetVelocity().to<double>(), load_.to<double>());
double dc_target = gains_.calculate((position - GetPosition()).to<double>(),
0.0, GetVelocity().to<double>(), load_.to<double>());
WriteDC(dc_target);
}

Expand Down
8 changes: 4 additions & 4 deletions src/frc846/cpp/frc846/control/MotorMonkey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ units::volt_t MotorMonkey::GetBatteryVoltage() { return battery_voltage; }

void MotorMonkey::SetLoad(size_t slot_id, units::newton_meter_t load) {}

void MotorMonkey::SetGains(size_t slot_id,
frc846::control::base::MotorGains gains) {}
void MotorMonkey::SetGains(
size_t slot_id, frc846::control::base::MotorGains gains) {}

void MotorMonkey::WriteDC(size_t slot_id, double duty_cycle) {}

void MotorMonkey::WriteVelocity(size_t slot_id,
units::radians_per_second_t velocity) {}
void MotorMonkey::WriteVelocity(
size_t slot_id, units::radians_per_second_t velocity) {}

void MotorMonkey::WritePosition(size_t slot_id, units::radian_t position) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ frc846::wpilib::unit_ohm CircuitResistanceCalculator::calculate(
units::foot_t wire_length, WireGauge gauge, unsigned int num_connectors) {
frc846::wpilib::unit_ohms_per_meter resistance_per_meter;
switch (gauge) {
case twelve_gauge:
resistance_per_meter = KnownResistances::kTwelveGaugeResistance;
break;
case fourteen_gauge:
resistance_per_meter = KnownResistances::kFourteenGaugeResistance;
break;
case sixteen_gauge:
resistance_per_meter = KnownResistances::kSixteenGaugeResistance;
break;
case eighteen_gauge:
resistance_per_meter = KnownResistances::kEighteenGaugeResistance;
break;
case twelve_gauge:
resistance_per_meter = KnownResistances::kTwelveGaugeResistance;
break;
case fourteen_gauge:
resistance_per_meter = KnownResistances::kFourteenGaugeResistance;
break;
case sixteen_gauge:
resistance_per_meter = KnownResistances::kSixteenGaugeResistance;
break;
case eighteen_gauge:
resistance_per_meter = KnownResistances::kEighteenGaugeResistance;
break;
}

frc846::wpilib::unit_ohm total_resistance =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace frc846::control::calculators {

units::ampere_t CurrentTorqueCalculator::predict_current_draw(
double duty_cycle, units::revolutions_per_minute_t rpm,
units::volt_t v_supply, unit_ohm circuit_resistance, MotorSpecs specs) {
units::ampere_t CurrentTorqueCalculator::predict_current_draw(double duty_cycle,
units::revolutions_per_minute_t rpm, units::volt_t v_supply,
unit_ohm circuit_resistance, MotorSpecs specs) {
double pct_speed = rpm / specs.free_speed;

unit_ohm winding_resistance =
Expand All @@ -21,9 +21,9 @@ units::ampere_t CurrentTorqueCalculator::predict_current_draw(
return current_draw;
}

units::newton_meter_t CurrentTorqueCalculator::predict_torque(
double duty_cycle, units::revolutions_per_minute_t rpm,
units::volt_t v_supply, unit_ohm circuit_resistance, MotorSpecs specs) {
units::newton_meter_t CurrentTorqueCalculator::predict_torque(double duty_cycle,
units::revolutions_per_minute_t rpm, units::volt_t v_supply,
unit_ohm circuit_resistance, MotorSpecs specs) {
units::ampere_t current_draw = predict_current_draw(
duty_cycle, rpm, v_supply, circuit_resistance, specs);

Expand All @@ -39,9 +39,9 @@ units::newton_meter_t CurrentTorqueCalculator::current_to_torque(
return (current / specs.stall_current) * specs.stall_torque;
}

double CurrentTorqueCalculator::current_control(
units::ampere_t target_current, units::revolutions_per_minute_t rpm,
units::volt_t v_supply, unit_ohm circuit_resistance, MotorSpecs specs) {
double CurrentTorqueCalculator::current_control(units::ampere_t target_current,
units::revolutions_per_minute_t rpm, units::volt_t v_supply,
unit_ohm circuit_resistance, MotorSpecs specs) {
double pct_speed = rpm / specs.free_speed;

unit_ohm winding_resistance =
Expand All @@ -60,7 +60,7 @@ double CurrentTorqueCalculator::torque_control(
units::newton_meter_t target_torque, units::revolutions_per_minute_t rpm,
units::volt_t v_supply, unit_ohm circuit_resistance, MotorSpecs specs) {
return current_control(torque_to_current(target_torque, specs), rpm, v_supply,
circuit_resistance, specs);
circuit_resistance, specs);
}

} // namespace frc846::control::calculators
27 changes: 12 additions & 15 deletions src/frc846/cpp/frc846/control/hardware/TalonFX_interm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace frc846::control::hardware {

TalonFX_interm::TalonFX_interm(int can_id, std::string bus,
units::millisecond_t max_wait_time)
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) {}

void TalonFX_interm::Tick() {
Expand Down Expand Up @@ -42,8 +42,8 @@ void TalonFX_interm::SetCurrentLimit(units::ampere_t current_limit) {
last_error_ = getErrorCode(talon_.GetConfigurator().Apply(configs));
}

void TalonFX_interm::SetSoftLimits(units::radian_t forward_limit,
units::radian_t reverse_limit) {
void TalonFX_interm::SetSoftLimits(
units::radian_t forward_limit, units::radian_t reverse_limit) {
ctre::phoenix6::configs::SoftwareLimitSwitchConfigs configs{};
configs.WithForwardSoftLimitEnable(true);
configs.WithForwardSoftLimitThreshold(forward_limit.to<double>());
Expand Down Expand Up @@ -79,9 +79,7 @@ void TalonFX_interm::WritePosition(units::radian_t position) {
void TalonFX_interm::EnableStatusFrames(
std::vector<frc846::control::config::StatusFrame> frames) {
last_error_ = getErrorCode(talon_.OptimizeBusUtilization(max_wait_time_));
if (last_error_ != ControllerErrorCodes::kAllOK) {
return;
}
if (last_error_ != ControllerErrorCodes::kAllOK) { return; }
for (auto frame : frames) {
ctre::phoenix::StatusCode last_status_code = ctre::phoenix::StatusCode::OK;
if (frame == frc846::control::config::StatusFrame::kCurrentFrame) {
Expand Down Expand Up @@ -136,14 +134,13 @@ ControllerErrorCodes TalonFX_interm::GetLastErrorCode() { return last_error_; }
frc846::control::hardware::ControllerErrorCodes TalonFX_interm::getErrorCode(
ctre::phoenix::StatusCode code) {
switch (code) {
case ctre::phoenix::StatusCode::OK:
return ControllerErrorCodes::kAllOK;
case ctre::phoenix::StatusCode::InvalidDeviceSpec:
return ControllerErrorCodes::kDeviceDisconnected;
case ctre::phoenix::StatusCode::ConfigFailed:
return ControllerErrorCodes::kConfigFailed;
case ctre::phoenix::StatusCode::ApiTooOld:
return ControllerErrorCodes::kVersionMismatch;
case ctre::phoenix::StatusCode::OK: return ControllerErrorCodes::kAllOK;
case ctre::phoenix::StatusCode::InvalidDeviceSpec:
return ControllerErrorCodes::kDeviceDisconnected;
case ctre::phoenix::StatusCode::ConfigFailed:
return ControllerErrorCodes::kConfigFailed;
case ctre::phoenix::StatusCode::ApiTooOld:
return ControllerErrorCodes::kVersionMismatch;
}

if (code.IsWarning()) {
Expand Down
12 changes: 6 additions & 6 deletions src/frc846/cpp/frc846/control/simulation/MCSimulator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
namespace frc846::control::simulation {

MCSimulator::MCSimulator(frc846::control::base::MotorSpecs specs,
frc846::wpilib::unit_ohm circuit_resistance,
frc846::wpilib::unit_kg_m_sq rotational_inertia)
frc846::wpilib::unit_ohm circuit_resistance,
frc846::wpilib::unit_kg_m_sq rotational_inertia)
: specs(specs),
circuit_resistance_{circuit_resistance},
rotational_inertia_{rotational_inertia} {
last_tick_ = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch());
}

void MCSimulator::Tick(units::volt_t battery_voltage,
units::newton_meter_t load) {
void MCSimulator::Tick(
units::volt_t battery_voltage, units::newton_meter_t load) {
double duty_cycle = 0.0;
if (auto* dc = std::get_if<double>(&control_message)) {
duty_cycle = *dc;
Expand All @@ -25,8 +25,8 @@ void MCSimulator::Tick(units::volt_t battery_voltage,
duty_cycle =
gains.calculate(vel->to<double>(), 0.0, 0.0, load.to<double>());
} else if (auto* pos = std::get_if<units::radian_t>(&control_message)) {
duty_cycle = gains.calculate(pos->to<double>(), 0.0, velocity_.to<double>(),
load.to<double>());
duty_cycle = gains.calculate(
pos->to<double>(), 0.0, velocity_.to<double>(), load.to<double>());
}

units::newton_meter_t torque_output =
Expand Down
12 changes: 6 additions & 6 deletions src/frc846/cpp/frc846/math/collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bool DEquals(double x, double y, double epsilon) {
}

double HorizontalDeadband(double input, double x_intercept, double max,
double exponent, double sensitivity) {
double exponent, double sensitivity) {
double y = 0;

auto slope = max / (max - x_intercept);
Expand All @@ -23,7 +23,7 @@ double HorizontalDeadband(double input, double x_intercept, double max,
}

double VerticalDeadband(double input, double y_intercept, double max,
double exponent, double sensitivity) {
double exponent, double sensitivity) {
double y = 0;

auto slope = (max - y_intercept) / max;
Expand All @@ -36,8 +36,8 @@ double VerticalDeadband(double input, double y_intercept, double max,
return copysign(max * pow(y / max, exponent) * sensitivity, input);
}

units::degree_t CoterminalDifference(units::degree_t angle,
units::degree_t other_angle) {
units::degree_t CoterminalDifference(
units::degree_t angle, units::degree_t other_angle) {
const units::angle::degree_t difference =
units::math::fmod(angle, 1_tr) - units::math::fmod(other_angle, 1_tr);
if (difference > 0.5_tr) {
Expand All @@ -49,8 +49,8 @@ units::degree_t CoterminalDifference(units::degree_t angle,
}
}

units::degree_t CoterminalSum(units::degree_t angle,
units::degree_t other_angle) {
units::degree_t CoterminalSum(
units::degree_t angle, units::degree_t other_angle) {
const units::angle::degree_t difference =
units::math::fmod(angle, 1_tr) + units::math::fmod(other_angle, 1_tr);
if (difference > 0.5_tr) {
Expand Down
Loading

0 comments on commit 6c07e13

Please sign in to comment.