[wpilib] MotorControllerGroup: Override setVoltage (#4403)

This causes setVoltage to be called on the lower level motor contollers,
which is benefical in cases when they are smart motor controllers.
Previously, the default implementation (using the bus voltage and
calling set()) was used in this case.

This does slightly pessimize the case when the lower level motor
controllers use the default setVoltage implementation, but given the
prevalence of smart motor controllers, this seems like an overall win.
This commit is contained in:
Peter Johnson
2022-09-06 08:18:33 -07:00
committed by GitHub
parent f36162fddc
commit 65c8fbd452
3 changed files with 14 additions and 0 deletions

View File

@@ -33,6 +33,12 @@ void MotorControllerGroup::Set(double speed) {
}
}
void MotorControllerGroup::SetVoltage(units::volt_t output) {
for (auto motorController : m_motorControllers) {
motorController.get().SetVoltage(m_isInverted ? -output : output);
}
}
double MotorControllerGroup::Get() const {
if (!m_motorControllers.empty()) {
return m_motorControllers.front().get().Get() * (m_isInverted ? -1 : 1);