blob: a807afcf33bd03498d71730c2f65d5411445a1a3 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
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
12using namespace frc;
13
14void SpeedControllerGroup::Set(double speed) {
15 for (auto speedController : m_speedControllers) {
16 speedController.get().Set(m_isInverted ? -speed : speed);
17 }
18}
19
20double 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
27void SpeedControllerGroup::SetInverted(bool isInverted) {
28 m_isInverted = isInverted;
29}
30
31bool SpeedControllerGroup::GetInverted() const { return m_isInverted; }
32
33void SpeedControllerGroup::Disable() {
34 for (auto speedController : m_speedControllers) {
35 speedController.get().Disable();
36 }
37}
38
39void SpeedControllerGroup::StopMotor() {
40 for (auto speedController : m_speedControllers) {
41 speedController.get().StopMotor();
42 }
43}
44
45void SpeedControllerGroup::PIDWrite(double output) { Set(output); }
46
47void 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}