Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 6 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 7 | |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 8 | #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 | |
| 19 | class MotorSafetyHelper; |
| 20 | class 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 | */ |
| 31 | class Relay : public MotorSafety, |
| 32 | public SensorBase, |
| 33 | public ITableListener, |
| 34 | public LiveWindowSendable { |
| 35 | public: |
| 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 | |
| 76 | private: |
| 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 | }; |