mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilib] Clamp sim battery voltage to 0 (#7325)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <span>
|
||||
|
||||
@@ -33,8 +34,9 @@ class BatterySim {
|
||||
static units::volt_t Calculate(units::volt_t nominalVoltage,
|
||||
units::ohm_t resistance,
|
||||
std::span<const units::ampere_t> currents) {
|
||||
return nominalVoltage -
|
||||
std::accumulate(currents.begin(), currents.end(), 0_A) * resistance;
|
||||
return std::max(0_V, nominalVoltage - std::accumulate(currents.begin(),
|
||||
currents.end(), 0_A) *
|
||||
resistance);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,8 +54,9 @@ class BatterySim {
|
||||
static units::volt_t Calculate(
|
||||
units::volt_t nominalVoltage, units::ohm_t resistance,
|
||||
std::initializer_list<units::ampere_t> currents) {
|
||||
return nominalVoltage -
|
||||
std::accumulate(currents.begin(), currents.end(), 0_A) * resistance;
|
||||
return std::max(0_V, nominalVoltage - std::accumulate(currents.begin(),
|
||||
currents.end(), 0_A) *
|
||||
resistance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user