WPILibC++  unspecified
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 <llvm/raw_ostream.h>
14 
15 #include "ErrorBase.h"
16 #include "MotorSafety.h"
17 #include "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 
40  explicit Relay(int channel, Direction direction = kBothDirections);
41  ~Relay() override;
42 
43  void Set(Value value);
44  Value Get() const;
45  int GetChannel() const;
46 
47  void SetExpiration(double timeout) override;
48  double GetExpiration() const override;
49  bool IsAlive() const override;
50  void StopMotor() override;
51  bool IsSafetyEnabled() const override;
52  void SetSafetyEnabled(bool enabled) override;
53  void GetDescription(llvm::raw_ostream& desc) const override;
54 
55  void InitSendable(SendableBuilder& builder) override;
56 
57  private:
58  int m_channel;
59  Direction m_direction;
60 
61  HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle;
62  HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle;
63 
64  std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
65 };
66 
67 } // namespace frc
Value Get() const
Get the Relay State.
Definition: Relay.cpp:183
Definition: RobotController.cpp:14
void Set(Value value)
Set the relay state.
Definition: Relay.cpp:122
Class for Spike style relay outputs.
Definition: Relay.h:35
void SetExpiration(double timeout) override
Set the expiration time for the Relay object.
Definition: Relay.cpp:224
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: Relay.cpp:275
Definition: MotorSafety.h:16
Definition: MotorSafetyHelper.h:20
void SetSafetyEnabled(bool enabled) override
Enable/disable motor safety for this device.
Definition: Relay.cpp:258
Relay(int channel, Direction direction=kBothDirections)
Relay constructor given a channel.
Definition: Relay.cpp:31
double GetExpiration() const override
Return the expiration time for the relay object.
Definition: Relay.cpp:233
void StopMotor() override
Stop the motor associated with this PWM object.
Definition: Relay.cpp:249
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
bool IsSafetyEnabled() const override
Check if motor safety is enabled for this object.
Definition: Relay.cpp:267
Definition: SendableBuilder.h:23
bool IsAlive() const override
Check if the relay object is currently alive or stopped due to a timeout.
Definition: Relay.cpp:241
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33
~Relay() override
Free the resource associated with a relay.
Definition: Relay.cpp:98