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