WPILibC++  2019.1.1-beta-1-15-gd03b020
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
RobotDriveBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 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 <wpi/ArrayRef.h>
13 #include <wpi/raw_ostream.h>
14 
15 #include "frc/MotorSafety.h"
16 #include "frc/MotorSafetyHelper.h"
17 #include "frc/smartdashboard/SendableBase.h"
18 
19 namespace frc {
20 
21 class SpeedController;
22 
26 class RobotDriveBase : public MotorSafety, public SendableBase {
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  ~RobotDriveBase() override = default;
43 
44  RobotDriveBase(RobotDriveBase&&) = default;
45  RobotDriveBase& operator=(RobotDriveBase&&) = default;
46 
56  void SetDeadband(double deadband);
57 
65  void SetMaxOutput(double maxOutput);
66 
73  void FeedWatchdog();
74 
75  void SetExpiration(double timeout) override;
76  double GetExpiration() const override;
77  bool IsAlive() const override;
78  void StopMotor() override = 0;
79  bool IsSafetyEnabled() const override;
80  void SetSafetyEnabled(bool enabled) override;
81  void GetDescription(wpi::raw_ostream& desc) const override = 0;
82 
83  protected:
87  double Limit(double number);
88 
96  double ApplyDeadband(double number, double deadband);
97 
102  void Normalize(wpi::MutableArrayRef<double> wheelSpeeds);
103 
104  double m_deadband = 0.02;
105  double m_maxOutput = 1.0;
106  MotorSafetyHelper m_safetyHelper{this};
107 };
108 
109 } // namespace frc
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void Normalize(wpi::MutableArrayRef< double > wheelSpeeds)
Normalize all wheel speeds if the magnitude of any wheel is greater than 1.0.
void SetMaxOutput(double maxOutput)
Configure the scaling factor for using RobotDrive with motor controllers in a mode other than Percent...
Definition: MotorSafety.h:16
Definition: MotorSafetyHelper.h:18
double ApplyDeadband(double number, double deadband)
Returns 0.0 if the given value is within the specified range around zero.
void FeedWatchdog()
Feed the motor safety object.
double Limit(double number)
Limit motor values to the -1.0 to +1.0 range.
Definition: SendableBase.h:19
MotorType
The location of a motor on the robot for the purpose of driving.
Definition: RobotDriveBase.h:31
void SetDeadband(double deadband)
Sets the deadband applied to the drive inputs (e.g., joystick values).
Common base class for drive platforms.
Definition: RobotDriveBase.h:26
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:291