WPILibC++  2020.3.2
RobotDriveBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 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 
17 namespace frc {
18 
19 class SpeedController;
20 
24 class RobotDriveBase : public MotorSafety {
25  public:
29  enum MotorType {
30  kFrontLeft = 0,
31  kFrontRight = 1,
32  kRearLeft = 2,
33  kRearRight = 3,
34  kLeft = 0,
35  kRight = 1,
36  kBack = 2
37  };
38 
40  ~RobotDriveBase() override = default;
41 
42  RobotDriveBase(RobotDriveBase&&) = default;
43  RobotDriveBase& operator=(RobotDriveBase&&) = default;
44 
54  void SetDeadband(double deadband);
55 
63  void SetMaxOutput(double maxOutput);
64 
71  void FeedWatchdog();
72 
73  void StopMotor() override = 0;
74  void GetDescription(wpi::raw_ostream& desc) const override = 0;
75 
76  protected:
84  double ApplyDeadband(double number, double deadband);
85 
90  void Normalize(wpi::MutableArrayRef<double> wheelSpeeds);
91 
92  double m_deadband = 0.02;
93  double m_maxOutput = 1.0;
94 };
95 
96 } // namespace frc
frc::RobotDriveBase::Normalize
void Normalize(wpi::MutableArrayRef< double > wheelSpeeds)
Normalize all wheel speeds if the magnitude of any wheel is greater than 1.0.
frc::RobotDriveBase::SetDeadband
void SetDeadband(double deadband)
Sets the deadband applied to the drive inputs (e.g., joystick values).
frc::RobotDriveBase
Common base class for drive platforms.
Definition: RobotDriveBase.h:24
frc::MotorSafety
This base class runs a watchdog timer and calls the subclass's StopMotor() function if the timeout ex...
Definition: MotorSafety.h:24
frc::RobotDriveBase::FeedWatchdog
void FeedWatchdog()
Feed the motor safety object.
frc::RobotDriveBase::ApplyDeadband
double ApplyDeadband(double number, double deadband)
Returns 0.0 if the given value is within the specified range around zero.
frc::RobotDriveBase::MotorType
MotorType
The location of a motor on the robot for the purpose of driving.
Definition: RobotDriveBase.h:29
wpi::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:287
frc::RobotDriveBase::SetMaxOutput
void SetMaxOutput(double maxOutput)
Configure the scaling factor for using RobotDrive with motor controllers in a mode other than Percent...
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
wpi::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:47