WPILibC++  unspecified
RobotDrive.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 #pragma once
9 
10 #include <memory>
11 
12 #include <llvm/raw_ostream.h>
13 #include <support/deprecated.h>
14 
15 #include "ErrorBase.h"
16 #include "MotorSafety.h"
17 #include "MotorSafetyHelper.h"
18 
19 namespace frc {
20 
21 class SpeedController;
22 class GenericHID;
23 
34 class WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.")
35  RobotDrive : public MotorSafety,
36  public ErrorBase {
37  public:
38  enum MotorType {
39  kFrontLeftMotor = 0,
40  kFrontRightMotor = 1,
41  kRearLeftMotor = 2,
42  kRearRightMotor = 3
43  };
44 
45  RobotDrive(int leftMotorChannel, int rightMotorChannel);
46  RobotDrive(int frontLeftMotorChannel, int rearLeftMotorChannel,
47  int frontRightMotorChannel, int rearRightMotorChannel);
48  RobotDrive(SpeedController* leftMotor, SpeedController* rightMotor);
49  RobotDrive(SpeedController& leftMotor, SpeedController& rightMotor);
50  RobotDrive(std::shared_ptr<SpeedController> leftMotor,
51  std::shared_ptr<SpeedController> rightMotor);
52  RobotDrive(SpeedController* frontLeftMotor, SpeedController* rearLeftMotor,
53  SpeedController* frontRightMotor, SpeedController* rearRightMotor);
54  RobotDrive(SpeedController& frontLeftMotor, SpeedController& rearLeftMotor,
55  SpeedController& frontRightMotor, SpeedController& rearRightMotor);
56  RobotDrive(std::shared_ptr<SpeedController> frontLeftMotor,
57  std::shared_ptr<SpeedController> rearLeftMotor,
58  std::shared_ptr<SpeedController> frontRightMotor,
59  std::shared_ptr<SpeedController> rearRightMotor);
60  virtual ~RobotDrive() = default;
61 
62  RobotDrive(const RobotDrive&) = delete;
63  RobotDrive& operator=(const RobotDrive&) = delete;
64 
65  void Drive(double outputMagnitude, double curve);
66  void TankDrive(GenericHID* leftStick, GenericHID* rightStick,
67  bool squaredInputs = true);
68  void TankDrive(GenericHID& leftStick, GenericHID& rightStick,
69  bool squaredInputs = true);
70  void TankDrive(GenericHID* leftStick, int leftAxis, GenericHID* rightStick,
71  int rightAxis, bool squaredInputs = true);
72  void TankDrive(GenericHID& leftStick, int leftAxis, GenericHID& rightStick,
73  int rightAxis, bool squaredInputs = true);
74  void TankDrive(double leftValue, double rightValue,
75  bool squaredInputs = true);
76  void ArcadeDrive(GenericHID* stick, bool squaredInputs = true);
77  void ArcadeDrive(GenericHID& stick, bool squaredInputs = true);
78  void ArcadeDrive(GenericHID* moveStick, int moveChannel,
79  GenericHID* rotateStick, int rotateChannel,
80  bool squaredInputs = true);
81  void ArcadeDrive(GenericHID& moveStick, int moveChannel,
82  GenericHID& rotateStick, int rotateChannel,
83  bool squaredInputs = true);
84  void ArcadeDrive(double moveValue, double rotateValue,
85  bool squaredInputs = true);
86  void MecanumDrive_Cartesian(double x, double y, double rotation,
87  double gyroAngle = 0.0);
88  void MecanumDrive_Polar(double magnitude, double direction, double rotation);
89  void HolonomicDrive(double magnitude, double direction, double rotation);
90  virtual void SetLeftRightMotorOutputs(double leftOutput, double rightOutput);
91  void SetInvertedMotor(MotorType motor, bool isInverted);
92  void SetSensitivity(double sensitivity);
93  void SetMaxOutput(double maxOutput);
94 
95  void SetExpiration(double timeout) override;
96  double GetExpiration() const override;
97  bool IsAlive() const override;
98  void StopMotor() override;
99  bool IsSafetyEnabled() const override;
100  void SetSafetyEnabled(bool enabled) override;
101  void GetDescription(llvm::raw_ostream& desc) const override;
102 
103  protected:
104  void InitRobotDrive();
105  double Limit(double number);
106  void Normalize(double* wheelSpeeds);
107  void RotateVector(double& x, double& y, double angle);
108 
109  static const int kMaxNumberOfMotors = 4;
110  double m_sensitivity = 0.5;
111  double m_maxOutput = 1.0;
112  std::shared_ptr<SpeedController> m_frontLeftMotor;
113  std::shared_ptr<SpeedController> m_frontRightMotor;
114  std::shared_ptr<SpeedController> m_rearLeftMotor;
115  std::shared_ptr<SpeedController> m_rearRightMotor;
116  std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
117 
118  private:
119  int GetNumMotors() {
120  int motors = 0;
121  if (m_frontLeftMotor) motors++;
122  if (m_frontRightMotor) motors++;
123  if (m_rearLeftMotor) motors++;
124  if (m_rearRightMotor) motors++;
125  return motors;
126  }
127 };
128 
129 } // namespace frc
Interface for speed controlling devices.
Definition: SpeedController.h:17
Definition: Timer.cpp:18
A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive base...
Definition: DifferentialDrive.h:77
A class for driving Mecanum drive platforms.
Definition: MecanumDrive.h:40
Definition: MotorSafety.h:16
Base class for most objects.
Definition: ErrorBase.h:74
GenericHID Interface.
Definition: GenericHID.h:23
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33