blob: f582221b980601b8be8e9a29b53eb402f035dcd3 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
7#pragma once
8
9#include "MotorSafety.h"
10#include "SensorBase.h"
11#include "tables/ITableListener.h"
12#include "LiveWindow/LiveWindowSendable.h"
13#include "tables/ITable.h"
14
15#include <memory>
16
17class MotorSafetyHelper;
18
19/**
20 * Class for Spike style relay outputs.
21 * Relays are intended to be connected to spikes or similar relays. The relay
22 * channels controls
23 * a pair of pins that are either both off, one on, the other on, or both on.
24 * This translates into
25 * two spike outputs at 0v, one at 12v and one at 0v, one at 0v and the other at
26 * 12v, or two
27 * spike outputs at 12V. This allows off, full forward, or full reverse control
28 * of motors without
29 * variable speed. It also allows the two channels (forward and reverse) to be
30 * used independently
31 * for something that does not care about voltage polatiry (like a solenoid).
32 */
33class Relay : public MotorSafety,
34 public SensorBase,
35 public ITableListener,
36 public LiveWindowSendable {
37 public:
38 enum Value { kOff, kOn, kForward, kReverse };
39 enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
40
41 Relay(uint32_t channel, Direction direction = kBothDirections);
42 virtual ~Relay();
43
44 void Set(Value value);
45 Value Get() const;
46 uint32_t GetChannel() const;
47
48 void SetExpiration(float timeout) override;
49 float 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(std::ostringstream& desc) const override;
55
56 void ValueChanged(ITable* source, llvm::StringRef key,
57 std::shared_ptr<nt::Value> value, bool isNew) override;
58 void UpdateTable() override;
59 void StartLiveWindowMode() override;
60 void StopLiveWindowMode() override;
61 std::string GetSmartDashboardType() const override;
62 void InitTable(std::shared_ptr<ITable> subTable) override;
63 std::shared_ptr<ITable> GetTable() const override;
64
65 std::shared_ptr<ITable> m_table;
66
67 private:
68 uint32_t m_channel;
69 Direction m_direction;
70
71 std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
72};