WPILibC++  unspecified
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 "DigitalOutput.h"
13 #include "ErrorBase.h"
14 #include "MotorSafety.h"
15 #include "MotorSafetyHelper.h"
16 #include "PWM.h"
17 #include "SmartDashboard/SendableBase.h"
18 #include "SpeedController.h"
19 
20 namespace frc {
21 
25 class NidecBrushless : public ErrorBase,
26  public SendableBase,
27  public SpeedController,
28  public MotorSafety {
29  public:
30  NidecBrushless(int pwmChannel, int dioChannel);
31  ~NidecBrushless() override = default;
32 
33  // SpeedController interface
34  void Set(double speed) override;
35  double Get() const override;
36  void SetInverted(bool isInverted) override;
37  bool GetInverted() const override;
38  void Disable() override;
39  void StopMotor() override;
40 
41  void Enable();
42 
43  // PIDOutput interface
44  void PIDWrite(double output) override;
45 
46  // MotorSafety interface
47  void SetExpiration(double timeout) override;
48  double GetExpiration() const override;
49  bool IsAlive() const override;
50  void SetSafetyEnabled(bool enabled) override;
51  bool IsSafetyEnabled() const override;
52  void GetDescription(llvm::raw_ostream& desc) const override;
53 
54  int GetChannel() const;
55 
56  // Sendable interface
57  void InitSendable(SendableBuilder& builder) override;
58 
59  private:
60  MotorSafetyHelper m_safetyHelper;
61  bool m_isInverted = false;
62  std::atomic_bool m_disabled{false};
63  DigitalOutput m_dio;
64  PWM m_pwm;
65  double m_speed = 0.0;
66 };
67 
68 } // namespace frc
Interface for speed controlling devices.
Definition: SpeedController.h:17
Definition: RobotController.cpp:14
void SetInverted(bool isInverted) override
Common interface for inverting direction of a speed controller.
Definition: NidecBrushless.cpp:63
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: NidecBrushless.cpp:150
bool IsSafetyEnabled() const override
Check if motor safety is enabled.
Definition: NidecBrushless.cpp:115
void Set(double speed) override
Set the PWM value.
Definition: NidecBrushless.cpp:47
double GetExpiration() const override
Return the safety expiration time.
Definition: NidecBrushless.cpp:88
void SetExpiration(double timeout) override
Set the safety expiration time.
Definition: NidecBrushless.cpp:79
void Enable()
Re-enable the motor after Disable() has been called.
Definition: NidecBrushless.cpp:141
Definition: MotorSafety.h:16
Definition: MotorSafetyHelper.h:20
void StopMotor() override
Stop the motor.
Definition: NidecBrushless.cpp:105
int GetChannel() const
Gets the channel number associated with the object.
Definition: NidecBrushless.cpp:148
void Disable() override
Disable the motor.
Definition: NidecBrushless.cpp:131
Nidec Brushless Motor.
Definition: NidecBrushless.h:25
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
bool IsAlive() const override
Check if the motor is currently alive or stopped due to a timeout.
Definition: NidecBrushless.cpp:98
void PIDWrite(double output) override
Write out the PID value as seen in the PIDOutput base object.
Definition: NidecBrushless.cpp:72
Class to write to digital outputs.
Definition: DigitalOutput.h:24
Definition: SendableBuilder.h:23
double Get() const override
Get the recently set value of the PWM.
Definition: NidecBrushless.cpp:61
Class implements the PWM generation in the FPGA.
Definition: PWM.h:36
NidecBrushless(int pwmChannel, int dioChannel)
Constructor.
Definition: NidecBrushless.cpp:24
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33
bool GetInverted() const override
Common interface for returning the inversion state of a speed controller.
Definition: NidecBrushless.cpp:65