2017-10-16 22:54:36 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
2017-10-16 22:54:36 -04:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/SpeedControllerGroup.h"
|
2017-10-16 22:54:36 -04:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/smartdashboard/SendableBuilder.h"
|
2017-12-04 23:28:33 -08:00
|
|
|
|
2017-10-16 22:54:36 -04:00
|
|
|
using namespace frc;
|
|
|
|
|
|
|
|
|
|
void SpeedControllerGroup::Set(double speed) {
|
|
|
|
|
for (auto speedController : m_speedControllers) {
|
|
|
|
|
speedController.get().Set(m_isInverted ? -speed : speed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double SpeedControllerGroup::Get() const {
|
|
|
|
|
if (!m_speedControllers.empty()) {
|
2018-01-11 22:16:42 -08:00
|
|
|
return m_speedControllers.front().get().Get() * (m_isInverted ? -1 : 1);
|
2017-10-16 22:54:36 -04:00
|
|
|
}
|
|
|
|
|
return 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpeedControllerGroup::SetInverted(bool isInverted) {
|
|
|
|
|
m_isInverted = isInverted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SpeedControllerGroup::GetInverted() const { return m_isInverted; }
|
|
|
|
|
|
|
|
|
|
void SpeedControllerGroup::Disable() {
|
|
|
|
|
for (auto speedController : m_speedControllers) {
|
|
|
|
|
speedController.get().Disable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpeedControllerGroup::StopMotor() {
|
|
|
|
|
for (auto speedController : m_speedControllers) {
|
|
|
|
|
speedController.get().StopMotor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 22:03:13 -06:00
|
|
|
void SpeedControllerGroup::PIDWrite(double output) { Set(output); }
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
void SpeedControllerGroup::InitSendable(SendableBuilder& builder) {
|
|
|
|
|
builder.SetSmartDashboardType("Speed Controller");
|
2018-07-28 14:04:46 -07:00
|
|
|
builder.SetActuator(true);
|
2017-12-04 23:28:33 -08:00
|
|
|
builder.SetSafeState([=]() { StopMotor(); });
|
|
|
|
|
builder.AddDoubleProperty("Value", [=]() { return Get(); },
|
|
|
|
|
[=](double value) { Set(value); });
|
|
|
|
|
}
|