WPILibC++  2019.1.1-beta-2-22-gc405188
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
DifferentialDrive.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 <wpi/raw_ostream.h>
11 
12 #include "frc/drive/RobotDriveBase.h"
13 
14 namespace frc {
15 
16 class SpeedController;
17 
100  public:
101  static constexpr double kDefaultQuickStopThreshold = 0.2;
102  static constexpr double kDefaultQuickStopAlpha = 0.1;
103 
110  DifferentialDrive(SpeedController& leftMotor, SpeedController& rightMotor);
111 
112  ~DifferentialDrive() override = default;
113 
115  DifferentialDrive& operator=(DifferentialDrive&&) = default;
116 
129  void ArcadeDrive(double xSpeed, double zRotation, bool squareInputs = true);
130 
146  void CurvatureDrive(double xSpeed, double zRotation, bool isQuickTurn);
147 
157  void TankDrive(double leftSpeed, double rightSpeed, bool squareInputs = true);
158 
174  void SetQuickStopThreshold(double threshold);
175 
187  void SetQuickStopAlpha(double alpha);
188 
195  bool IsRightSideInverted() const;
196 
203  void SetRightSideInverted(bool rightSideInverted);
204 
205  void StopMotor() override;
206  void GetDescription(wpi::raw_ostream& desc) const override;
207 
208  void InitSendable(SendableBuilder& builder) override;
209 
210  private:
211  SpeedController& m_leftMotor;
212  SpeedController& m_rightMotor;
213 
214  double m_quickStopThreshold = kDefaultQuickStopThreshold;
215  double m_quickStopAlpha = kDefaultQuickStopAlpha;
216  double m_quickStopAccumulator = 0.0;
217  double m_rightSideInvertMultiplier = -1.0;
218 };
219 
220 } // namespace frc
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Interface for speed controlling devices.
Definition: SpeedController.h:17
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void TankDrive(double leftSpeed, double rightSpeed, bool squareInputs=true)
Tank drive method for differential drive platform.
void CurvatureDrive(double xSpeed, double zRotation, bool isQuickTurn)
Curvature drive method for differential drive platform.
A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive base...
Definition: DifferentialDrive.h:99
void SetRightSideInverted(bool rightSideInverted)
Sets if the power sent to the right side of the drivetrain should be multipled by -1...
void SetQuickStopThreshold(double threshold)
Sets the QuickStop speed threshold in curvature drive.
Definition: SendableBuilder.h:23
DifferentialDrive(SpeedController &leftMotor, SpeedController &rightMotor)
Construct a DifferentialDrive.
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
bool IsRightSideInverted() const
Gets if the power sent to the right side of the drivetrain is multipled by -1.
void SetQuickStopAlpha(double alpha)
Sets the low-pass filter gain for QuickStop in curvature drive.
Common base class for drive platforms.
Definition: RobotDriveBase.h:25
void ArcadeDrive(double xSpeed, double zRotation, bool squareInputs=true)
Arcade drive method for differential drive platform.