[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

@@ -5,7 +5,6 @@
#pragma once
#include "frc/PWM.h"
#include "frc/SpeedController.h"
namespace frc {

View File

@@ -5,13 +5,14 @@
#pragma once
#include <units/voltage.h>
#include <wpi/deprecated.h>
namespace frc {
/**
* Interface for speed controlling devices.
*/
class SpeedController {
class WPI_DEPRECATED("use MotorController") SpeedController {
public:
virtual ~SpeedController() = default;

View File

@@ -7,15 +7,18 @@
#include <functional>
#include <vector>
#include "frc/SpeedController.h"
#include <wpi/deprecated.h>
#include "frc/motorcontrol/MotorController.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SpeedControllerGroup : public Sendable,
public SpeedController,
public SendableHelper<SpeedControllerGroup> {
class WPI_DEPRECATED("use MotorControllerGroup") SpeedControllerGroup
: public Sendable,
public MotorController,
public SendableHelper<SpeedControllerGroup> {
public:
template <class... SpeedControllers>
explicit SpeedControllerGroup(SpeedController& speedController,

View File

@@ -12,6 +12,17 @@
namespace frc {
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996) // was declared deprecated
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
class SpeedController;
/**
@@ -19,9 +30,9 @@ class SpeedController;
* the Kit of Parts drive base, "tank drive", or West Coast Drive.
*
* These drive bases typically have drop-center / skid-steer with two or more
* wheels per side (e.g., 6WD or 8WD). This class takes a SpeedController per
* wheels per side (e.g., 6WD or 8WD). This class takes a MotorController per
* side. For four and six motor drivetrains, construct and pass in
* SpeedControllerGroup instances as follows.
* MotorControllerGroup instances as follows.
*
* Four motor drivetrain:
* @code{.cpp}
@@ -29,11 +40,11 @@ class SpeedController;
* public:
* frc::PWMVictorSPX m_frontLeft{1};
* frc::PWMVictorSPX m_rearLeft{2};
* frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft};
* frc::MotorControllerGroup m_left{m_frontLeft, m_rearLeft};
*
* frc::PWMVictorSPX m_frontRight{3};
* frc::PWMVictorSPX m_rearRight{4};
* frc::SpeedControllerGroup m_right{m_frontRight, m_rearRight};
* frc::MotorControllerGroup m_right{m_frontRight, m_rearRight};
*
* frc::DifferentialDrive m_drive{m_left, m_right};
* };
@@ -46,12 +57,12 @@ class SpeedController;
* frc::PWMVictorSPX m_frontLeft{1};
* frc::PWMVictorSPX m_midLeft{2};
* frc::PWMVictorSPX m_rearLeft{3};
* frc::SpeedControllerGroup m_left{m_frontLeft, m_midLeft, m_rearLeft};
* frc::MotorControllerGroup m_left{m_frontLeft, m_midLeft, m_rearLeft};
*
* frc::PWMVictorSPX m_frontRight{4};
* frc::PWMVictorSPX m_midRight{5};
* frc::PWMVictorSPX m_rearRight{6};
* frc::SpeedControllerGroup m_right{m_frontRight, m_midRight, m_rearRight};
* frc::MotorControllerGroup m_right{m_frontRight, m_midRight, m_rearRight};
*
* frc::DifferentialDrive m_drive{m_left, m_right};
* };
@@ -105,7 +116,7 @@ class DifferentialDrive : public RobotDriveBase,
/**
* Construct a DifferentialDrive.
*
* To pass multiple motors per side, use a SpeedControllerGroup. If a motor
* To pass multiple motors per side, use a MotorControllerGroup. If a motor
* needs to be inverted, do so before passing it in.
*/
DifferentialDrive(SpeedController& leftMotor, SpeedController& rightMotor);
@@ -219,4 +230,12 @@ class DifferentialDrive : public RobotDriveBase,
double m_rightSideInvertMultiplier = -1.0;
};
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} // namespace frc

View File

@@ -15,6 +15,17 @@
namespace frc {
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996) // was declared deprecated
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
class SpeedController;
/**
@@ -140,4 +151,12 @@ class KilloughDrive : public RobotDriveBase,
bool reported = false;
};
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} // namespace frc

View File

@@ -14,6 +14,17 @@
namespace frc {
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996) // was declared deprecated
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
class SpeedController;
/**
@@ -145,4 +156,12 @@ class MecanumDrive : public RobotDriveBase,
bool reported = false;
};
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} // namespace frc

View File

@@ -13,8 +13,6 @@
namespace frc {
class SpeedController;
/**
* Common base class for drive platforms.
*/

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Digilent DMC 60 Speed Controller.
* Digilent DMC 60 Motor Controller.
*
* Note that the DMC 60 uses the following bounds for PWM values. These
* values should work reasonably well for most controllers, but if users
@@ -24,7 +24,7 @@ namespace frc {
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class DMC60 : public PWMSpeedController {
class DMC60 : public PWMMotorController {
public:
/**
* Constructor for a Digilent DMC 60.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Luminary Micro / Vex Robotics Jaguar Speed Controller with PWM control.
* Luminary Micro / Vex Robotics Jaguar Motor Controller with PWM control.
*
* Note that the Jaguar uses the following bounds for PWM values. These values
* should work reasonably well for most controllers, but if users experience
@@ -24,7 +24,7 @@ namespace frc {
* \li 1.454ms = the "low end" of the deadband range
* \li 0.697ms = full "reverse"
*/
class Jaguar : public PWMSpeedController {
class Jaguar : public PWMMotorController {
public:
/**
* Constructor for a Jaguar connected via PWM.

View File

@@ -0,0 +1,37 @@
// 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.
#pragma once
#include <units/voltage.h>
#include "frc/SpeedController.h"
namespace frc {
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996) // was declared deprecated
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
/**
* Interface for motor controlling devices.
*/
class MotorController : public SpeedController {};
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} // namespace frc

View File

@@ -0,0 +1,47 @@
// 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.
#pragma once
#include <functional>
#include <vector>
#include "frc/motorcontrol/MotorController.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class MotorControllerGroup : public Sendable,
public MotorController,
public SendableHelper<MotorControllerGroup> {
public:
template <class... MotorControllers>
explicit MotorControllerGroup(MotorController& motorController,
MotorControllers&... motorControllers);
explicit MotorControllerGroup(
std::vector<std::reference_wrapper<MotorController>>&& motorControllers);
MotorControllerGroup(MotorControllerGroup&&) = default;
MotorControllerGroup& operator=(MotorControllerGroup&&) = default;
void Set(double speed) override;
double Get() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;
void StopMotor() override;
void InitSendable(SendableBuilder& builder) override;
private:
bool m_isInverted = false;
std::vector<std::reference_wrapper<MotorController>> m_motorControllers;
void Initialize();
};
} // namespace frc
#include "frc/motorcontrol/MotorControllerGroup.inc"

View File

@@ -0,0 +1,22 @@
// 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.
#pragma once
#include <functional>
#include <vector>
#include "frc/motorcontrol/MotorControllerGroup.h"
namespace frc {
template <class... MotorControllers>
MotorControllerGroup::MotorControllerGroup(
MotorController& motorController, MotorControllers&... motorControllers)
: m_motorControllers(std::vector<std::reference_wrapper<MotorController>>{
motorController, motorControllers...}) {
Initialize();
}
} // namespace frc

View File

@@ -8,7 +8,7 @@
#include "frc/ErrorBase.h"
#include "frc/MotorSafety.h"
#include "frc/PWM.h"
#include "frc/SpeedController.h"
#include "frc/motorcontrol/MotorController.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
@@ -19,7 +19,7 @@ class SendableBuilder;
/**
* Nidec Brushless Motor.
*/
class NidecBrushless : public SpeedController,
class NidecBrushless : public MotorController,
public MotorSafety,
public Sendable,
public SendableHelper<NidecBrushless> {
@@ -39,7 +39,7 @@ class NidecBrushless : public SpeedController,
NidecBrushless(NidecBrushless&&) = default;
NidecBrushless& operator=(NidecBrushless&&) = default;
// SpeedController interface
// MotorController interface
/**
* Set the PWM value.
*

View File

@@ -8,7 +8,7 @@
#include "frc/MotorSafety.h"
#include "frc/PWM.h"
#include "frc/SpeedController.h"
#include "frc/motorcontrol/MotorController.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
@@ -19,15 +19,15 @@ class raw_ostream;
namespace frc {
/**
* Common base class for all PWM Speed Controllers.
* Common base class for all PWM Motor Controllers.
*/
class PWMSpeedController : public SpeedController,
class PWMMotorController : public MotorController,
public MotorSafety,
public Sendable,
public SendableHelper<PWMSpeedController> {
public SendableHelper<PWMMotorController> {
public:
PWMSpeedController(PWMSpeedController&&) = default;
PWMSpeedController& operator=(PWMSpeedController&&) = default;
PWMMotorController(PWMMotorController&&) = default;
PWMMotorController& operator=(PWMMotorController&&) = default;
/**
* Set the PWM value.
@@ -42,7 +42,7 @@ class PWMSpeedController : public SpeedController,
/**
* Get the recently set value of the PWM. This value is affected by the
* inversion property. If you want the value that is sent directly to the
* SpeedController, use {@link PWM#getSpeed()} instead.
* MotorController, use {@link PWM#getSpeed()} instead.
*
* @return The most recently set value for the PWM between -1.0 and 1.0.
*/
@@ -62,13 +62,13 @@ class PWMSpeedController : public SpeedController,
protected:
/**
* Constructor for a PWM Speed Controller connected via PWM.
* Constructor for a PWM Motor Controller connected via PWM.
*
* @param name Name to use for SendableRegistry
* @param channel The PWM channel that the controller is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
PWMSpeedController(const wpi::Twine& name, int channel);
PWMMotorController(const wpi::Twine& name, int channel);
void InitSendable(SendableBuilder& builder) override;

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* REV Robotics SPARK MAX Speed Controller.
* REV Robotics SPARK MAX Motor Controller.
*
* Note that the SPARK MAX uses the following bounds for PWM values. These
* values should work reasonably well for most controllers, but if users
@@ -24,7 +24,7 @@ namespace frc {
* \li 1.460ms = the "low end" of the deadband range
* \li 0.999ms = full "reverse"
*/
class PWMSparkMax : public PWMSpeedController {
class PWMSparkMax : public PWMMotorController {
public:
/**
* Constructor for a SPARK MAX.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Cross the Road Electronics (CTRE) Talon FX Speed Controller with PWM
* Cross the Road Electronics (CTRE) Talon FX Motor Controller with PWM
* control.
*
* Note that the Talon FX uses the following bounds for PWM values. These
@@ -25,7 +25,7 @@ namespace frc {
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class PWMTalonFX : public PWMSpeedController {
class PWMTalonFX : public PWMMotorController {
public:
/**
* Construct a Talon FX connected via PWM.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Cross the Road Electronics (CTRE) Talon SRX Speed Controller with PWM
* Cross the Road Electronics (CTRE) Talon SRX Motor Controller with PWM
* control.
*
* Note that the Talon SRX uses the following bounds for PWM values. These
@@ -25,7 +25,7 @@ namespace frc {
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class PWMTalonSRX : public PWMSpeedController {
class PWMTalonSRX : public PWMMotorController {
public:
/**
* Construct a Talon SRX connected via PWM.

View File

@@ -4,7 +4,7 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
@@ -23,7 +23,7 @@ namespace frc {
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class PWMVenom : public PWMSpeedController {
class PWMVenom : public PWMMotorController {
public:
/**
* Construct a Venom connected via PWM.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Cross the Road Electronics (CTRE) Victor SPX Speed Controller with PWM
* Cross the Road Electronics (CTRE) Victor SPX Motor Controller with PWM
* control.
*
* Note that the Victor SPX uses the following bounds for PWM values. These
@@ -25,7 +25,7 @@ namespace frc {
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class PWMVictorSPX : public PWMSpeedController {
class PWMVictorSPX : public PWMMotorController {
public:
/**
* Construct a Victor SPX connected via PWM.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Mindsensors SD540 Speed Controller.
* Mindsensors SD540 Motor Controller.
*
* Note that the SD540 uses the following bounds for PWM values. These values
* should work reasonably well for most controllers, but if users experience
@@ -24,7 +24,7 @@ namespace frc {
* \li 1.44ms = the "low end" of the deadband range
* \li 0.94ms = full "reverse"
*/
class SD540 : public PWMSpeedController {
class SD540 : public PWMMotorController {
public:
/**
* Constructor for a SD540.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* REV Robotics SPARK Speed Controller.
* REV Robotics SPARK Motor Controller.
*
* Note that the SPARK uses the following bounds for PWM values. These values
* should work reasonably well for most controllers, but if users experience
@@ -24,7 +24,7 @@ namespace frc {
* \li 1.460ms = the "low end" of the deadband range
* \li 0.999ms = full "reverse"
*/
class Spark : public PWMSpeedController {
class Spark : public PWMMotorController {
public:
/**
* Constructor for a SPARK.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Cross the Road Electronics (CTRE) Talon and Talon SR Speed Controller.
* Cross the Road Electronics (CTRE) Talon and Talon SR Motor Controller.
*
* Note that the Talon uses the following bounds for PWM values. These values
* should work reasonably well for most controllers, but if users experience
@@ -24,7 +24,7 @@ namespace frc {
* \li 1.487ms = the "low end" of the deadband range
* \li 0.989ms = full "reverse"
*/
class Talon : public PWMSpeedController {
class Talon : public PWMMotorController {
public:
/**
* Constructor for a Talon (original or Talon SR).

View File

@@ -4,14 +4,14 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Vex Robotics Victor 888 Speed Controller.
* Vex Robotics Victor 888 Motor Controller.
*
* The Vex Robotics Victor 884 Speed Controller can also be used with this
* The Vex Robotics Victor 884 Motor Controller can also be used with this
* class but may need to be calibrated per the Victor 884 user manual.
*
* Note that the Victor uses the following bounds for PWM values. These
@@ -28,7 +28,7 @@ namespace frc {
* \li 1.490ms = the "low end" of the deadband range
* \li 1.026ms = full "reverse"
*/
class Victor : public PWMSpeedController {
class Victor : public PWMMotorController {
public:
/**
* Constructor for a Victor.

View File

@@ -4,12 +4,12 @@
#pragma once
#include "frc/PWMSpeedController.h"
#include "frc/motorcontrol/PWMMotorController.h"
namespace frc {
/**
* Vex Robotics Victor SP Speed Controller.
* Vex Robotics Victor SP Motor Controller.
*
* Note that the Victor SP uses the following bounds for PWM values. These
* values should work reasonably well for most controllers, but if users
@@ -24,7 +24,7 @@ namespace frc {
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class VictorSP : public PWMSpeedController {
class VictorSP : public PWMMotorController {
public:
/**
* Constructor for a Victor SP.

View File

@@ -200,10 +200,10 @@ enum class BuiltInWidgets {
*/
kEncoder,
/**
* Displays a SpeedController.
* Displays a MotorController.
* The speed controller will be controllable from the dashboard when test mode
* is enabled, but will otherwise be view-only. <br>Supported types: <ul>
* <li>PWMSpeedController</li>
* <li>PWMMotorController</li>
* <li>DMC60</li>
* <li>Jaguar</li>
* <li>PWMTalonSRX</li>
@@ -213,7 +213,7 @@ enum class BuiltInWidgets {
* <li>Talon</li>
* <li>Victor</li>
* <li>VictorSP</li>
* <li>SpeedControllerGroup</li>
* <li>MotorControllerGroup</li>
* <li>Any custom subclass of {@code SpeedContorller}</li>
* </ul>
* <br>Custom properties:
@@ -223,7 +223,7 @@ enum class BuiltInWidgets {
* <td>One of {@code ["HORIZONTAL", "VERTICAL"]}</td></tr>
* </table>
*/
kSpeedController,
kMotorController,
/**
* Displays a command with a toggle button. Pressing the button will start the
* command, and the button will automatically release when the command