WPILibC++  2018.4.1-20180924031742-1200-g1aa8446
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Relay.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-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 <memory>
11 
12 #include <hal/Types.h>
13 #include <wpi/raw_ostream.h>
14 
15 #include "frc/ErrorBase.h"
16 #include "frc/MotorSafety.h"
17 #include "frc/smartdashboard/SendableBase.h"
18 
19 namespace frc {
20 
21 class MotorSafetyHelper;
22 
35 class Relay : public MotorSafety, public ErrorBase, public SendableBase {
36  public:
37  enum Value { kOff, kOn, kForward, kReverse };
38  enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
39 
49  explicit Relay(int channel, Direction direction = kBothDirections);
50 
56  ~Relay() override;
57 
58  Relay(Relay&& rhs);
59  Relay& operator=(Relay&& rhs);
60 
76  void Set(Value value);
77 
88  Value Get() const;
89 
90  int GetChannel() const;
91 
97  void SetExpiration(double timeout) override;
98 
104  double GetExpiration() const override;
105 
112  bool IsAlive() const override;
113 
120  void StopMotor() override;
121 
129  void SetSafetyEnabled(bool enabled) override;
130 
136  bool IsSafetyEnabled() const override;
137 
138  void GetDescription(wpi::raw_ostream& desc) const override;
139 
140  void InitSendable(SendableBuilder& builder) override;
141 
142  private:
143  int m_channel;
144  Direction m_direction;
145 
146  HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle;
147  HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle;
148 
149  std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
150 };
151 
152 } // namespace frc
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Value Get() const
Get the Relay State.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
bool IsSafetyEnabled() const override
Check if motor safety is enabled for this object.
Class for Spike style relay outputs.
Definition: Relay.h:35
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: MotorSafety.h:16
Relay(int channel, Direction direction=kBothDirections)
Relay constructor given a channel.
void Set(Value value)
Set the relay state.
double GetExpiration() const override
Return the expiration time for the relay object.
bool IsAlive() const override
Check if the relay object is currently alive or stopped due to a timeout.
~Relay() override
Free the resource associated with a relay.
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
void SetExpiration(double timeout) override
Set the expiration time for the Relay object.
void StopMotor() override
Stop the motor associated with this PWM object.
Definition: SendableBuilder.h:23
void SetSafetyEnabled(bool enabled) override
Enable/disable motor safety for this device.