blob: 19ddd7d9a114e4dabe6547f5bf5a41d1836dbcd3 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. 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 "LiveWindow/LiveWindowSendable.h"
14#include "MotorSafety.h"
15#include "SensorBase.h"
16#include "simulation/SimContinuousOutput.h"
17#include "tables/ITable.h"
18#include "tables/ITableListener.h"
19
20namespace frc {
21
22class MotorSafetyHelper;
23class DigitalModule;
24
25/**
26 * Class for Spike style relay outputs.
27 *
28 * Relays are intended to be connected to spikes or similar relays. The relay
29 * channels controls a pair of pins that are either both off, one on, the other
30 * on, or both on. This translates into two spike outputs at 0v, one at 12v and
31 * one at 0v, one at 0v and the other at 12v, or two spike outputs at 12V. This
32 * allows off, full forward, or full reverse control of motors without variable
33 * speed. It also allows the two channels (forward and reverse) to be used
34 * independently for something that does not care about voltage polatiry (like
35 * a solenoid).
36 */
37class Relay : public MotorSafety,
38 public SensorBase,
39 public ITableListener,
40 public LiveWindowSendable {
41 public:
42 enum Value { kOff, kOn, kForward, kReverse };
43 enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
44
45 explicit Relay(int channel, Direction direction = kBothDirections);
46 virtual ~Relay();
47
48 void Set(Value value);
49 Value Get() const;
50 int GetChannel() const;
51
52 void SetExpiration(double timeout) override;
53 double GetExpiration() const override;
54 bool IsAlive() const override;
55 void StopMotor() override;
56 bool IsSafetyEnabled() const override;
57 void SetSafetyEnabled(bool enabled) override;
58 void GetDescription(std::ostringstream& desc) const override;
59
60 void ValueChanged(ITable* source, llvm::StringRef key,
61 std::shared_ptr<nt::Value> value, bool isNew) override;
62 void UpdateTable() override;
63 void StartLiveWindowMode() override;
64 void StopLiveWindowMode() override;
65 std::string GetSmartDashboardType() const override;
66 void InitTable(std::shared_ptr<ITable> subTable) override;
67 std::shared_ptr<ITable> GetTable() const override;
68
69 std::shared_ptr<ITable> m_table;
70
71 private:
72 int m_channel;
73 Direction m_direction;
74 std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
75 SimContinuousOutput* impl;
76 bool go_pos, go_neg;
77};
78
79} // namespace frc