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