WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
RobotDriveBase.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <span>
8#include <string>
9
11
12namespace wpi {
13
14/**
15 * Common base class for drive platforms.
16 *
17 * MotorSafety is enabled by default.
18 */
20 public:
21 /**
22 * The location of a motor on the robot for the purpose of driving.
23 */
24 enum class MotorType {
25 /// Front-left motor.
27 /// Front-right motor.
29 /// Rear-left motor.
31 /// Rear-right motor.
33 /// Left motor.
34 LEFT = 0,
35 /// Right motor.
36 RIGHT = 1,
37 /// Back motor.
38 BACK = 2
39 };
40
42 ~RobotDriveBase() override = default;
43
46
47 /**
48 * Sets the deadband applied to the drive inputs (e.g., joystick values).
49 *
50 * The default value is 0.02. Inputs smaller than the deadband are set to 0.0
51 * while inputs larger than the deadband are scaled from 0.0 to 1.0. See
52 * wpi::math::ApplyDeadband().
53 *
54 * @param deadband The deadband to set.
55 */
56 void SetDeadband(double deadband);
57
58 /**
59 * Configure the scaling factor for using RobotDrive with motor controllers in
60 * a mode other than PercentVbus or to limit the maximum output.
61 *
62 * @param maxOutput Multiplied with the output percentage computed by the
63 * drive functions.
64 */
65 void SetMaxOutput(double maxOutput);
66
67 /**
68 * Feed the motor safety object. Resets the timer that will stop the motors if
69 * it completes.
70 *
71 * @see MotorSafetyHelper::Feed()
72 */
74
75 void StopMotor() override = 0;
76 std::string GetDescription() const override = 0;
77
78 protected:
79 /// Default input deadband.
80 static constexpr double DEFAULT_DEADBAND = 0.02;
81
82 /// Default maximum output.
83 static constexpr double DEFAULT_MAX_OUTPUT = 1.0;
84
85 /**
86 * Renormalize all wheel velocities if the magnitude of any wheel is greater
87 * than 1.0.
88 */
89 static void Desaturate(std::span<double> wheelVelocities);
90
91 /// Input deadband.
93
94 /// Maximum output.
96};
97
98} // namespace wpi
RobotDriveBase & operator=(RobotDriveBase &&)=default
MotorType
The location of a motor on the robot for the purpose of driving.
Definition RobotDriveBase.hpp:24
@ BACK
Back motor.
Definition RobotDriveBase.hpp:38
@ RIGHT
Right motor.
Definition RobotDriveBase.hpp:36
@ FRONT_LEFT
Front-left motor.
Definition RobotDriveBase.hpp:26
@ FRONT_RIGHT
Front-right motor.
Definition RobotDriveBase.hpp:28
@ REAR_LEFT
Rear-left motor.
Definition RobotDriveBase.hpp:30
@ REAR_RIGHT
Rear-right motor.
Definition RobotDriveBase.hpp:32
@ LEFT
Left motor.
Definition RobotDriveBase.hpp:34
static constexpr double DEFAULT_MAX_OUTPUT
Default maximum output.
Definition RobotDriveBase.hpp:83
static void Desaturate(std::span< double > wheelVelocities)
Renormalize all wheel velocities if the magnitude of any wheel is greater than 1.0.
double m_deadband
Input deadband.
Definition RobotDriveBase.hpp:92
void StopMotor() override=0
Called to stop the motor when the timeout expires.
double m_maxOutput
Maximum output.
Definition RobotDriveBase.hpp:95
RobotDriveBase(RobotDriveBase &&)=default
void SetDeadband(double deadband)
Sets the deadband applied to the drive inputs (e.g., joystick values).
static constexpr double DEFAULT_DEADBAND
Default input deadband.
Definition RobotDriveBase.hpp:80
std::string GetDescription() const override=0
Returns a description to print when an error occurs.
void FeedWatchdog()
Feed the motor safety object.
~RobotDriveBase() override=default
void SetMaxOutput(double maxOutput)
Configure the scaling factor for using RobotDrive with motor controllers in a mode other than Percent...
Definition CvSource.hpp:15