WPILibC++ 2024.3.2
RobotDriveBase.h
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 <memory>
8#include <span>
9#include <string>
10
11#include "frc/MotorSafety.h"
12
13namespace frc {
14
15/**
16 * Common base class for drive platforms.
17 *
18 * MotorSafety is enabled by default.
19 */
21 public:
22 /**
23 * The location of a motor on the robot for the purpose of driving.
24 */
25 enum MotorType {
26 /// Front-left motor.
28 /// Front-right motor.
30 /// Rear-left motor.
32 /// Rear-right motor.
34 /// Left motor.
35 kLeft = 0,
36 /// Right motor.
37 kRight = 1,
38 /// Back motor.
39 kBack = 2
40 };
41
43 ~RobotDriveBase() override = default;
44
47
48 /**
49 * Sets the deadband applied to the drive inputs (e.g., joystick values).
50 *
51 * The default value is 0.02. Inputs smaller than the deadband are set to 0.0
52 * while inputs larger than the deadband are scaled from 0.0 to 1.0. See
53 * frc::ApplyDeadband().
54 *
55 * @param deadband The deadband to set.
56 */
57 void SetDeadband(double deadband);
58
59 /**
60 * Configure the scaling factor for using RobotDrive with motor controllers in
61 * a mode other than PercentVbus or to limit the maximum output.
62 *
63 * @param maxOutput Multiplied with the output percentage computed by the
64 * drive functions.
65 */
66 void SetMaxOutput(double maxOutput);
67
68 /**
69 * Feed the motor safety object. Resets the timer that will stop the motors if
70 * it completes.
71 *
72 * @see MotorSafetyHelper::Feed()
73 */
75
76 void StopMotor() override = 0;
77 std::string GetDescription() const override = 0;
78
79 protected:
80 /// Default input deadband.
81 static constexpr double kDefaultDeadband = 0.02;
82
83 /// Default maximum output.
84 static constexpr double kDefaultMaxOutput = 1.0;
85
86 /**
87 * Renormalize all wheel speeds if the magnitude of any wheel is greater than
88 * 1.0.
89 */
90 static void Desaturate(std::span<double> wheelSpeeds);
91
92 /// Input deadband.
94
95 /// Maximum output.
97};
98
99} // namespace frc
The Motor Safety feature acts as a watchdog timer for an individual motor.
Definition: MotorSafety.h:25
Common base class for drive platforms.
Definition: RobotDriveBase.h:20
RobotDriveBase & operator=(RobotDriveBase &&)=default
void StopMotor() override=0
Called to stop the motor when the timeout expires.
std::string GetDescription() const override=0
Returns a description to print when an error occurs.
void SetDeadband(double deadband)
Sets the deadband applied to the drive inputs (e.g., joystick values).
double m_deadband
Input deadband.
Definition: RobotDriveBase.h:93
static constexpr double kDefaultDeadband
Default input deadband.
Definition: RobotDriveBase.h:81
~RobotDriveBase() override=default
MotorType
The location of a motor on the robot for the purpose of driving.
Definition: RobotDriveBase.h:25
@ kLeft
Left motor.
Definition: RobotDriveBase.h:35
@ kFrontLeft
Front-left motor.
Definition: RobotDriveBase.h:27
@ kRight
Right motor.
Definition: RobotDriveBase.h:37
@ kFrontRight
Front-right motor.
Definition: RobotDriveBase.h:29
@ kRearRight
Rear-right motor.
Definition: RobotDriveBase.h:33
@ kRearLeft
Rear-left motor.
Definition: RobotDriveBase.h:31
@ kBack
Back motor.
Definition: RobotDriveBase.h:39
void SetMaxOutput(double maxOutput)
Configure the scaling factor for using RobotDrive with motor controllers in a mode other than Percent...
static void Desaturate(std::span< double > wheelSpeeds)
Renormalize all wheel speeds if the magnitude of any wheel is greater than 1.0.
void FeedWatchdog()
Feed the motor safety object.
RobotDriveBase(RobotDriveBase &&)=default
static constexpr double kDefaultMaxOutput
Default maximum output.
Definition: RobotDriveBase.h:84
double m_maxOutput
Maximum output.
Definition: RobotDriveBase.h:96
Definition: AprilTagPoseEstimator.h:15