WPILibC++ 2023.4.3
PWMMotorController.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 <string>
8#include <string_view>
9
12
13#include "frc/MotorSafety.h"
14#include "frc/PWM.h"
16
17namespace frc {
18class DMA;
19
20/**
21 * Common base class for all PWM Motor Controllers.
22 */
24 public MotorSafety,
25 public wpi::Sendable,
26 public wpi::SendableHelper<PWMMotorController> {
27 public:
28 friend class DMA;
29
32
33 /**
34 * Set the PWM value.
35 *
36 * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling
37 * the value for the FPGA.
38 *
39 * @param value The speed value between -1.0 and 1.0 to set.
40 */
41 void Set(double value) override;
42
43 /**
44 * Get the recently set value of the PWM. This value is affected by the
45 * inversion property. If you want the value that is sent directly to the
46 * MotorController, use PWM::GetSpeed() instead.
47 *
48 * @return The most recently set value for the PWM between -1.0 and 1.0.
49 */
50 double Get() const override;
51
52 void SetInverted(bool isInverted) override;
53
54 bool GetInverted() const override;
55
56 void Disable() override;
57
58 // MotorSafety interface
59 void StopMotor() override;
60 std::string GetDescription() const override;
61
62 int GetChannel() const;
63
64 /**
65 * Optionally eliminate the deadband from a motor controller.
66 *
67 * @param eliminateDeadband If true, set the motor curve on the motor
68 * controller to eliminate the deadband in the middle
69 * of the range. Otherwise, keep the full range
70 * without modifying any values.
71 */
72 void EnableDeadbandElimination(bool eliminateDeadband);
73
74 protected:
75 /**
76 * Constructor for a PWM Motor %Controller connected via PWM.
77 *
78 * @param name Name to use for SendableRegistry
79 * @param channel The PWM channel that the controller is attached to. 0-9 are
80 * on-board, 10-19 are on the MXP port
81 */
83
84 void InitSendable(wpi::SendableBuilder& builder) override;
85
87
88 private:
89 bool m_isInverted = false;
90
91 PWM* GetPwm() { return &m_pwm; }
92};
93
94} // namespace frc
Definition: DMA.h:20
Interface for motor controlling devices.
Definition: MotorController.h:14
The Motor Safety feature acts as a watchdog timer for an individual motor.
Definition: MotorSafety.h:25
Class implements the PWM generation in the FPGA.
Definition: PWM.h:34
Common base class for all PWM Motor Controllers.
Definition: PWMMotorController.h:26
void Disable() override
Common interface for disabling a motor.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
PWMMotorController(std::string_view name, int channel)
Constructor for a PWM Motor Controller connected via PWM.
bool GetInverted() const override
Common interface for returning the inversion state of a motor controller.
PWMMotorController & operator=(PWMMotorController &&)=default
void StopMotor() override
Common interface to stop the motor until Set is called again.
PWM m_pwm
Definition: PWMMotorController.h:86
void Set(double value) override
Set the PWM value.
double Get() const override
Get the recently set value of the PWM.
PWMMotorController(PWMMotorController &&)=default
std::string GetDescription() const override
The return value from this method is printed out when an error occurs.
void EnableDeadbandElimination(bool eliminateDeadband)
Optionally eliminate the deadband from a motor controller.
void SetInverted(bool isInverted) override
Common interface for inverting direction of a motor controller.
Definition: core.h:1240
Definition: SendableBuilder.h:18
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
basic_string_view< char > string_view
Definition: core.h:520
Definition: AprilTagFieldLayout.h:22