[wpilib] Move motor controllers to motorcontrol package (#3302)

Also deprecate SpeedController in favor of motorcontrol.MotorController and
SpeedControllerGroup in favor of motorcontrol.MotorControllerGroup.

The MotorController interface is derived from the SpeedController interface
so that code such as SpeedController x = new VictorSP(1) continues to
compile (just with a warning).

SpeedControllerGroup and MotorControllerGroup are independent classes;
both implement the MotorController interface.
This commit is contained in:
Peter Johnson
2021-04-17 11:27:16 -07:00
committed by GitHub
parent b7b178f49c
commit 0abf6c9045
194 changed files with 1096 additions and 696 deletions

View File

@@ -15,6 +15,14 @@
using namespace frc;
#if defined(_MSC_VER)
#pragma warning(disable : 4996) // was declared deprecated
#elif defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
DifferentialDrive::DifferentialDrive(SpeedController& leftMotor,
SpeedController& rightMotor)
: m_leftMotor(&leftMotor), m_rightMotor(&rightMotor) {

View File

@@ -16,6 +16,14 @@
using namespace frc;
#if defined(_MSC_VER)
#pragma warning(disable : 4996) // was declared deprecated
#elif defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
KilloughDrive::KilloughDrive(SpeedController& leftMotor,
SpeedController& rightMotor,
SpeedController& backMotor)

View File

@@ -17,6 +17,14 @@
using namespace frc;
#if defined(_MSC_VER)
#pragma warning(disable : 4996) // was declared deprecated
#elif defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
MecanumDrive::MecanumDrive(SpeedController& frontLeftMotor,
SpeedController& rearLeftMotor,
SpeedController& frontRightMotor,

View File

@@ -11,7 +11,7 @@
#include <hal/FRCUsageReporting.h>
#include "frc/Base.h"
#include "frc/SpeedController.h"
#include "frc/motorcontrol/MotorController.h"
using namespace frc;

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/DMC60.h"
#include "frc/motorcontrol/DMC60.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
DMC60::DMC60(int channel) : PWMSpeedController("DMC60", channel) {
DMC60::DMC60(int channel) : PWMMotorController("DMC60", channel) {
m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/Jaguar.h"
#include "frc/motorcontrol/Jaguar.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
Jaguar::Jaguar(int channel) : PWMSpeedController("Jaguar", channel) {
Jaguar::Jaguar(int channel) : PWMMotorController("Jaguar", channel) {
m_pwm.SetBounds(2.31, 1.55, 1.507, 1.454, 0.697);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -0,0 +1,69 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/motorcontrol/MotorControllerGroup.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
// Can't use a delegated constructor here because of an MSVC bug.
// https://developercommunity.visualstudio.com/content/problem/583/compiler-bug-with-delegating-a-constructor.html
MotorControllerGroup::MotorControllerGroup(
std::vector<std::reference_wrapper<MotorController>>&& motorControllers)
: m_motorControllers(std::move(motorControllers)) {
Initialize();
}
void MotorControllerGroup::Initialize() {
for (auto& motorController : m_motorControllers) {
SendableRegistry::GetInstance().AddChild(this, &motorController.get());
}
static int instances = 0;
++instances;
SendableRegistry::GetInstance().Add(this, "MotorControllerGroup", instances);
}
void MotorControllerGroup::Set(double speed) {
for (auto motorController : m_motorControllers) {
motorController.get().Set(m_isInverted ? -speed : speed);
}
}
double MotorControllerGroup::Get() const {
if (!m_motorControllers.empty()) {
return m_motorControllers.front().get().Get() * (m_isInverted ? -1 : 1);
}
return 0.0;
}
void MotorControllerGroup::SetInverted(bool isInverted) {
m_isInverted = isInverted;
}
bool MotorControllerGroup::GetInverted() const {
return m_isInverted;
}
void MotorControllerGroup::Disable() {
for (auto motorController : m_motorControllers) {
motorController.get().Disable();
}
}
void MotorControllerGroup::StopMotor() {
for (auto motorController : m_motorControllers) {
motorController.get().StopMotor();
}
}
void MotorControllerGroup::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.SetSafeState([=]() { StopMotor(); });
builder.AddDoubleProperty(
"Value", [=]() { return Get(); }, [=](double value) { Set(value); });
}

View File

@@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/NidecBrushless.h"
#include "frc/motorcontrol/NidecBrushless.h"
#include <hal/FRCUsageReporting.h>
#include <wpi/raw_ostream.h>

View File

@@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
#include <wpi/raw_ostream.h>
@@ -10,45 +10,45 @@
using namespace frc;
void PWMSpeedController::Set(double speed) {
void PWMMotorController::Set(double speed) {
m_pwm.SetSpeed(m_isInverted ? -speed : speed);
}
double PWMSpeedController::Get() const {
double PWMMotorController::Get() const {
return m_pwm.GetSpeed() * (m_isInverted ? -1.0 : 1.0);
}
void PWMSpeedController::SetInverted(bool isInverted) {
void PWMMotorController::SetInverted(bool isInverted) {
m_isInverted = isInverted;
}
bool PWMSpeedController::GetInverted() const {
bool PWMMotorController::GetInverted() const {
return m_isInverted;
}
void PWMSpeedController::Disable() {
void PWMMotorController::Disable() {
m_pwm.SetDisabled();
}
void PWMSpeedController::StopMotor() {
void PWMMotorController::StopMotor() {
Disable();
}
void PWMSpeedController::GetDescription(wpi::raw_ostream& desc) const {
void PWMMotorController::GetDescription(wpi::raw_ostream& desc) const {
desc << "PWM " << GetChannel();
}
int PWMSpeedController::GetChannel() const {
int PWMMotorController::GetChannel() const {
return m_pwm.GetChannel();
}
PWMSpeedController::PWMSpeedController(const wpi::Twine& name, int channel)
PWMMotorController::PWMMotorController(const wpi::Twine& name, int channel)
: m_pwm(channel, false) {
SendableRegistry::GetInstance().AddLW(this, name, channel);
}
void PWMSpeedController::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Speed Controller");
void PWMMotorController::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.SetSafeState([=] { Disable(); });
builder.AddDoubleProperty(

View File

@@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/PWMSparkMax.h"
#include "frc/motorcontrol/PWMSparkMax.h"
#include <hal/FRCUsageReporting.h>
@@ -11,7 +11,7 @@
using namespace frc;
PWMSparkMax::PWMSparkMax(int channel)
: PWMSpeedController("PWMSparkMax", channel) {
: PWMMotorController("PWMSparkMax", channel) {
m_pwm.SetBounds(2.003, 1.55, 1.50, 1.46, 0.999);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,14 +2,14 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/PWMTalonFX.h"
#include "frc/motorcontrol/PWMTalonFX.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
PWMTalonFX::PWMTalonFX(int channel)
: PWMSpeedController("PWMTalonFX", channel) {
: PWMMotorController("PWMTalonFX", channel) {
m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,14 +2,14 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/PWMTalonSRX.h"
#include "frc/motorcontrol/PWMTalonSRX.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
PWMTalonSRX::PWMTalonSRX(int channel)
: PWMSpeedController("PWMTalonSRX", channel) {
: PWMMotorController("PWMTalonSRX", channel) {
m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/PWMVenom.h"
#include "frc/motorcontrol/PWMVenom.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
PWMVenom::PWMVenom(int channel) : PWMSpeedController("PWMVenom", channel) {
PWMVenom::PWMVenom(int channel) : PWMMotorController("PWMVenom", channel) {
m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,14 +2,14 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/PWMVictorSPX.h"
#include "frc/motorcontrol/PWMVictorSPX.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
PWMVictorSPX::PWMVictorSPX(int channel)
: PWMSpeedController("PWMVictorSPX", channel) {
: PWMMotorController("PWMVictorSPX", channel) {
m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/SD540.h"
#include "frc/motorcontrol/SD540.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
SD540::SD540(int channel) : PWMSpeedController("SD540", channel) {
SD540::SD540(int channel) : PWMMotorController("SD540", channel) {
m_pwm.SetBounds(2.05, 1.55, 1.50, 1.44, 0.94);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/Spark.h"
#include "frc/motorcontrol/Spark.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
Spark::Spark(int channel) : PWMSpeedController("Spark", channel) {
Spark::Spark(int channel) : PWMMotorController("Spark", channel) {
m_pwm.SetBounds(2.003, 1.55, 1.50, 1.46, 0.999);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/Talon.h"
#include "frc/motorcontrol/Talon.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
Talon::Talon(int channel) : PWMSpeedController("Talon", channel) {
Talon::Talon(int channel) : PWMMotorController("Talon", channel) {
m_pwm.SetBounds(2.037, 1.539, 1.513, 1.487, 0.989);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/Victor.h"
#include "frc/motorcontrol/Victor.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
Victor::Victor(int channel) : PWMSpeedController("Victor", channel) {
Victor::Victor(int channel) : PWMMotorController("Victor", channel) {
m_pwm.SetBounds(2.027, 1.525, 1.507, 1.49, 1.026);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_2X);
m_pwm.SetSpeed(0.0);

View File

@@ -2,13 +2,13 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/VictorSP.h"
#include "frc/motorcontrol/VictorSP.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
VictorSP::VictorSP(int channel) : PWMSpeedController("VictorSP", channel) {
VictorSP::VictorSP(int channel) : PWMMotorController("VictorSP", channel) {
m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
m_pwm.SetSpeed(0.0);