WPILibC++  unspecified
RobotDriveBase.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/ArrayRef.h>
13 #include <llvm/raw_ostream.h>
14 
15 #include "ErrorBase.h"
16 #include "MotorSafety.h"
17 #include "MotorSafetyHelper.h"
18 
19 namespace frc {
20 
21 class SpeedController;
22 
26 class RobotDriveBase : public MotorSafety, public ErrorBase {
27  public:
31  enum MotorType {
32  kFrontLeft = 0,
33  kFrontRight = 1,
34  kRearLeft = 2,
35  kRearRight = 3,
36  kLeft = 0,
37  kRight = 1,
38  kBack = 2
39  };
40 
42  virtual ~RobotDriveBase() = default;
43 
44  RobotDriveBase(const RobotDriveBase&) = delete;
45  RobotDriveBase& operator=(const RobotDriveBase&) = delete;
46 
47  void SetDeadband(double deadband);
48  void SetMaxOutput(double maxOutput);
49 
50  void SetExpiration(double timeout) override;
51  double GetExpiration() const override;
52  bool IsAlive() const override;
53  void StopMotor() override = 0;
54  bool IsSafetyEnabled() const override;
55  void SetSafetyEnabled(bool enabled) override;
56  void GetDescription(llvm::raw_ostream& desc) const override = 0;
57 
58  protected:
59  double Limit(double number);
60  double ApplyDeadband(double number, double deadband);
61  void Normalize(llvm::MutableArrayRef<double> wheelSpeeds);
62 
63  double m_deadband = 0.02;
64  double m_maxOutput = 1.0;
65  MotorSafetyHelper m_safetyHelper{this};
66 };
67 
68 } // namespace frc
Interface for speed controlling devices.
Definition: SpeedController.h:17
Definition: Timer.cpp:18
double Limit(double number)
Limit motor values to the -1.0 to +1.0 range.
Definition: RobotDriveBase.cpp:55
Definition: MotorSafety.h:16
Definition: MotorSafetyHelper.h:19
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:227
Base class for most objects.
Definition: ErrorBase.h:74
MotorType
The location of a motor on the robot for the purpose of driving.
Definition: RobotDriveBase.h:31
void SetMaxOutput(double maxOutput)
Configure the scaling factor for using RobotDrive with motor controllers in a mode other than Percent...
Definition: RobotDriveBase.cpp:32
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33
Common base class for drive platforms.
Definition: RobotDriveBase.h:26
void Normalize(llvm::MutableArrayRef< double > wheelSpeeds)
Normalize all wheel speeds if the magnitude of any wheel is greater than 1.0.
Definition: RobotDriveBase.cpp:87
double ApplyDeadband(double number, double deadband)
Returns 0.0 if the given value is within the specified range around zero.
Definition: RobotDriveBase.cpp:72