WPILibC++  unspecified
Relay.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 #include <string>
12 
13 #include <HAL/Types.h>
14 #include <llvm/raw_ostream.h>
15 
16 #include "LiveWindow/LiveWindowSendable.h"
17 #include "MotorSafety.h"
18 #include "SensorBase.h"
19 #include "networktables/NetworkTableEntry.h"
20 
21 namespace frc {
22 
23 class MotorSafetyHelper;
24 
36 class Relay : public MotorSafety, public SensorBase, public LiveWindowSendable {
37  public:
38  enum Value { kOff, kOn, kForward, kReverse };
39  enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
40 
41  explicit Relay(int channel, Direction direction = kBothDirections);
42  virtual ~Relay();
43 
44  void Set(Value value);
45  Value Get() const;
46  int GetChannel() const;
47 
48  void SetExpiration(double timeout) override;
49  double GetExpiration() const override;
50  bool IsAlive() const override;
51  void StopMotor() override;
52  bool IsSafetyEnabled() const override;
53  void SetSafetyEnabled(bool enabled) override;
54  void GetDescription(llvm::raw_ostream& desc) const override;
55 
56  void UpdateTable() override;
57  void StartLiveWindowMode() override;
58  void StopLiveWindowMode() override;
59  std::string GetSmartDashboardType() const override;
60  void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
61 
62  protected:
63  nt::NetworkTableEntry m_valueEntry;
64  NT_EntryListener m_valueListener = 0;
65 
66  private:
67  int m_channel;
68  Direction m_direction;
69 
70  HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle;
71  HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle;
72 
73  std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
74 };
75 
76 } // namespace frc
Value Get() const
Get the Relay State.
Definition: Relay.cpp:186
Definition: Timer.cpp:18
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
Base class for all sensors.
Definition: SensorBase.h:20
void Set(Value value)
Set the relay state.
Definition: Relay.cpp:125
Class for Spike style relay outputs.
Definition: Relay.h:36
void SetExpiration(double timeout) override
Set the expiration time for the Relay object.
Definition: Relay.cpp:226
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Relay.cpp:290
Definition: MotorSafety.h:16
Definition: MotorSafetyHelper.h:19
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Relay.cpp:308
void SetSafetyEnabled(bool enabled) override
Enable/disable motor safety for this device.
Definition: Relay.cpp:259
Relay(int channel, Direction direction=kBothDirections)
Relay constructor given a channel.
Definition: Relay.cpp:30
double GetExpiration() const override
Return the expiration time for the relay object.
Definition: Relay.cpp:234
void InitTable(std::shared_ptr< nt::NetworkTable > subTable) override
Initializes a table for this sendable object.
Definition: Relay.cpp:317
std::string GetSmartDashboardType() const override
Definition: Relay.cpp:315
void StopMotor() override
Stop the motor associated with this PWM object.
Definition: Relay.cpp:250
bool IsSafetyEnabled() const override
Check if motor safety is enabled for this object.
Definition: Relay.cpp:268
virtual ~Relay()
Free the resource associated with a relay.
Definition: Relay.cpp:99
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Relay.cpp:276
bool IsAlive() const override
Check if the relay object is currently alive or stopped due to a timeout.
Definition: Relay.cpp:242
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33