WPILibC++  2019.1.1-beta-1-26-g8be693f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
NidecBrushless.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <atomic>
11 
12 #include "frc/DigitalOutput.h"
13 #include "frc/ErrorBase.h"
14 #include "frc/MotorSafety.h"
15 #include "frc/MotorSafetyHelper.h"
16 #include "frc/PWM.h"
17 #include "frc/SpeedController.h"
18 #include "frc/smartdashboard/SendableBase.h"
19 
20 namespace frc {
21 
25 class NidecBrushless : public ErrorBase,
26  public SendableBase,
27  public SpeedController,
28  public MotorSafety {
29  public:
38  NidecBrushless(int pwmChannel, int dioChannel);
39 
40  ~NidecBrushless() override = default;
41 
42  NidecBrushless(NidecBrushless&&) = default;
43  NidecBrushless& operator=(NidecBrushless&&) = default;
44 
45  // SpeedController interface
54  void Set(double speed) override;
55 
61  double Get() const override;
62 
63  void SetInverted(bool isInverted) override;
64 
65  bool GetInverted() const override;
66 
71  void Disable() override;
72 
80  void StopMotor() override;
81 
86  void Enable();
87 
88  // PIDOutput interface
94  void PIDWrite(double output) override;
95 
96  // MotorSafety interface
102  void SetExpiration(double timeout) override;
103 
109  double GetExpiration() const override;
110 
117  bool IsAlive() const override;
118 
119  void SetSafetyEnabled(bool enabled) override;
120 
121  bool IsSafetyEnabled() const override;
122 
123  void GetDescription(wpi::raw_ostream& desc) const override;
124 
130  int GetChannel() const;
131 
132  // Sendable interface
133  void InitSendable(SendableBuilder& builder) override;
134 
135  private:
136  MotorSafetyHelper m_safetyHelper;
137  bool m_isInverted = false;
138  std::atomic_bool m_disabled{false};
139  DigitalOutput m_dio;
140  PWM m_pwm;
141  double m_speed = 0.0;
142 };
143 
144 } // namespace frc
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
int GetChannel() const
Gets the channel number associated with the object.
Interface for speed controlling devices.
Definition: SpeedController.h:17
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void Enable()
Re-enable the motor after Disable() has been called.
void SetInverted(bool isInverted) override
Common interface for inverting direction of a speed controller.
void Disable() override
Disable the motor.
void PIDWrite(double output) override
Write out the PID value as seen in the PIDOutput base object.
void SetExpiration(double timeout) override
Set the safety expiration time.
Definition: MotorSafety.h:16
bool GetInverted() const override
Common interface for returning the inversion state of a speed controller.
double GetExpiration() const override
Return the safety expiration time.
Definition: MotorSafetyHelper.h:18
void StopMotor() override
Stop the motor.
double Get() const override
Get the recently set value of the PWM.
void Set(double speed) override
Set the PWM value.
Nidec Brushless Motor.
Definition: NidecBrushless.h:25
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
Class to write to digital outputs.
Definition: DigitalOutput.h:24
Definition: SendableBuilder.h:23
bool IsAlive() const override
Check if the motor is currently alive or stopped due to a timeout.
Class implements the PWM generation in the FPGA.
Definition: PWM.h:36
NidecBrushless(int pwmChannel, int dioChannel)
Constructor.
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.