WPILibC++ 2023.4.3-108-ge5452e3
NidecBrushless.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
11
12#include "frc/DigitalOutput.h"
13#include "frc/MotorSafety.h"
14#include "frc/PWM.h"
16
17namespace frc {
18
19/**
20 * Nidec Brushless Motor.
21 */
23 public MotorSafety,
24 public wpi::Sendable,
25 public wpi::SendableHelper<NidecBrushless> {
26 public:
27 /**
28 * Constructor.
29 *
30 * @param pwmChannel The PWM channel that the Nidec Brushless controller is
31 * attached to. 0-9 are on-board, 10-19 are on the MXP port.
32 * @param dioChannel The DIO channel that the Nidec Brushless controller is
33 * attached to. 0-9 are on-board, 10-25 are on the MXP port.
34 */
35 NidecBrushless(int pwmChannel, int dioChannel);
36
37 ~NidecBrushless() override = default;
38
41
42 // MotorController interface
43 /**
44 * Set the PWM value.
45 *
46 * The PWM value is set using a range of -1.0 to 1.0, appropriately scaling
47 * the value for the FPGA.
48 *
49 * @param speed The speed value between -1.0 and 1.0 to set.
50 */
51 void Set(double speed) override;
52
53 /**
54 * Get the recently set value of the PWM.
55 *
56 * @return The most recently set value for the PWM between -1.0 and 1.0.
57 */
58 double Get() const override;
59
60 void SetInverted(bool isInverted) override;
61
62 bool GetInverted() const override;
63
64 /**
65 * Disable the motor. The Enable() function must be called to re-enable the
66 * motor.
67 */
68 void Disable() override;
69
70 /**
71 * Re-enable the motor after Disable() has been called. The Set() function
72 * must be called to set a new motor speed.
73 */
74 void Enable();
75
76 // MotorSafety interface
77 void StopMotor() override;
78 std::string GetDescription() const override;
79
80 /**
81 * Gets the channel number associated with the object.
82 *
83 * @return The channel number.
84 */
85 int GetChannel() const;
86
87 // Sendable interface
88 void InitSendable(wpi::SendableBuilder& builder) override;
89
90 private:
91 bool m_isInverted = false;
92 bool m_disabled = false;
93 DigitalOutput m_dio;
94 PWM m_pwm;
95 double m_speed = 0.0;
96};
97
98} // namespace frc
Class to write to digital outputs.
Definition: DigitalOutput.h:25
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
Nidec Brushless Motor.
Definition: NidecBrushless.h:25
NidecBrushless(int pwmChannel, int dioChannel)
Constructor.
double Get() const override
Get the recently set value of the PWM.
void StopMotor() override
NidecBrushless(NidecBrushless &&)=default
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
std::string GetDescription() const override
The return value from this method is printed out when an error occurs.
void Enable()
Re-enable the motor after Disable() has been called.
int GetChannel() const
Gets the channel number associated with the object.
void Set(double speed) override
Set the PWM value.
bool GetInverted() const override
Common interface for returning the inversion state of a motor controller.
void Disable() override
Disable the motor.
~NidecBrushless() override=default
NidecBrushless & operator=(NidecBrushless &&)=default
void SetInverted(bool isInverted) override
Common interface for inverting direction of a motor controller.
Class implements the PWM generation in the FPGA.
Definition: PWM.h:26
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
Definition: AprilTagPoseEstimator.h:15