WPILibC++ 2023.4.3
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 {
30 kLeft = 0,
31 kRight = 1,
32 kBack = 2
33 };
34
36 ~RobotDriveBase() override = default;
37
40
41 /**
42 * Sets the deadband applied to the drive inputs (e.g., joystick values).
43 *
44 * The default value is 0.02. Inputs smaller than the deadband are set to 0.0
45 * while inputs larger than the deadband are scaled from 0.0 to 1.0. See
46 * frc::ApplyDeadband().
47 *
48 * @param deadband The deadband to set.
49 */
50 void SetDeadband(double deadband);
51
52 /**
53 * Configure the scaling factor for using RobotDrive with motor controllers in
54 * a mode other than PercentVbus or to limit the maximum output.
55 *
56 * @param maxOutput Multiplied with the output percentage computed by the
57 * drive functions.
58 */
59 void SetMaxOutput(double maxOutput);
60
61 /**
62 * Feed the motor safety object. Resets the timer that will stop the motors if
63 * it completes.
64 *
65 * @see MotorSafetyHelper::Feed()
66 */
68
69 void StopMotor() override = 0;
70 std::string GetDescription() const override = 0;
71
72 protected:
73 /**
74 * Renormalize all wheel speeds if the magnitude of any wheel is greater than
75 * 1.0.
76 */
77 static void Desaturate(std::span<double> wheelSpeeds);
78
79 double m_deadband = 0.02;
80 double m_maxOutput = 1.0;
81};
82
83} // 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
std::string GetDescription() const override=0
The return value from this method is printed out when an error occurs.
void SetDeadband(double deadband)
Sets the deadband applied to the drive inputs (e.g., joystick values).
double m_deadband
Definition: RobotDriveBase.h:79
~RobotDriveBase() override=default
MotorType
The location of a motor on the robot for the purpose of driving.
Definition: RobotDriveBase.h:25
@ kLeft
Definition: RobotDriveBase.h:30
@ kFrontLeft
Definition: RobotDriveBase.h:26
@ kRight
Definition: RobotDriveBase.h:31
@ kFrontRight
Definition: RobotDriveBase.h:27
@ kRearRight
Definition: RobotDriveBase.h:29
@ kRearLeft
Definition: RobotDriveBase.h:28
@ kBack
Definition: RobotDriveBase.h:32
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
double m_maxOutput
Definition: RobotDriveBase.h:80
Definition: AprilTagFieldLayout.h:22