Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "frc/SpeedControllerGroup.h" |
| 9 | |
| 10 | #include "frc/smartdashboard/SendableBuilder.h" |
| 11 | |
| 12 | using namespace frc; |
| 13 | |
| 14 | void SpeedControllerGroup::Set(double speed) { |
| 15 | for (auto speedController : m_speedControllers) { |
| 16 | speedController.get().Set(m_isInverted ? -speed : speed); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | double SpeedControllerGroup::Get() const { |
| 21 | if (!m_speedControllers.empty()) { |
| 22 | return m_speedControllers.front().get().Get() * (m_isInverted ? -1 : 1); |
| 23 | } |
| 24 | return 0.0; |
| 25 | } |
| 26 | |
| 27 | void SpeedControllerGroup::SetInverted(bool isInverted) { |
| 28 | m_isInverted = isInverted; |
| 29 | } |
| 30 | |
| 31 | bool SpeedControllerGroup::GetInverted() const { return m_isInverted; } |
| 32 | |
| 33 | void SpeedControllerGroup::Disable() { |
| 34 | for (auto speedController : m_speedControllers) { |
| 35 | speedController.get().Disable(); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void SpeedControllerGroup::StopMotor() { |
| 40 | for (auto speedController : m_speedControllers) { |
| 41 | speedController.get().StopMotor(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void SpeedControllerGroup::PIDWrite(double output) { Set(output); } |
| 46 | |
| 47 | void SpeedControllerGroup::InitSendable(SendableBuilder& builder) { |
| 48 | builder.SetSmartDashboardType("Speed Controller"); |
| 49 | builder.SetActuator(true); |
| 50 | builder.SetSafeState([=]() { StopMotor(); }); |
| 51 | builder.AddDoubleProperty("Value", [=]() { return Get(); }, |
| 52 | [=](double value) { Set(value); }); |
| 53 | } |