2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/Types.h>
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/raw_ostream.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/ErrorBase.h"
|
|
|
|
|
#include "frc/MotorSafety.h"
|
|
|
|
|
#include "frc/smartdashboard/SendableBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Class for Spike style relay outputs.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Relays are intended to be connected to spikes or similar relays. The relay
|
2016-05-20 17:30:37 -07:00
|
|
|
* channels controls a pair of pins that are either both off, one on, the other
|
|
|
|
|
* on, or both on. This translates into two spike outputs at 0v, one at 12v and
|
|
|
|
|
* one at 0v, one at 0v and the other at 12v, or two spike outputs at 12V. This
|
|
|
|
|
* allows off, full forward, or full reverse control of motors without variable
|
2017-11-16 00:33:51 -08:00
|
|
|
* speed. It also allows the two channels (forward and reverse) to be used
|
2016-05-20 17:30:37 -07:00
|
|
|
* independently for something that does not care about voltage polarity (like
|
|
|
|
|
* a solenoid).
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2018-11-22 21:15:26 -08:00
|
|
|
class Relay : public MotorSafety, public SendableBase {
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
|
|
|
|
enum Value { kOff, kOn, kForward, kReverse };
|
|
|
|
|
enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Relay constructor given a channel.
|
|
|
|
|
*
|
|
|
|
|
* This code initializes the relay and reserves all resources that need to be
|
|
|
|
|
* locked. Initially the relay is set to both lines at 0v.
|
|
|
|
|
*
|
|
|
|
|
* @param channel The channel number (0-3).
|
|
|
|
|
* @param direction The direction that the Relay object will control.
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
explicit Relay(int channel, Direction direction = kBothDirections);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Free the resource associated with a relay.
|
|
|
|
|
*
|
|
|
|
|
* The relay channels are set to free and the relay output is turned off.
|
|
|
|
|
*/
|
2017-12-04 23:28:33 -08:00
|
|
|
~Relay() override;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
Relay(Relay&& rhs);
|
|
|
|
|
Relay& operator=(Relay&& rhs);
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Set the relay state.
|
|
|
|
|
*
|
|
|
|
|
* Valid values depend on which directions of the relay are controlled by the
|
|
|
|
|
* object.
|
|
|
|
|
*
|
|
|
|
|
* When set to kBothDirections, the relay can be any of the four states:
|
|
|
|
|
* 0v-0v, 0v-12v, 12v-0v, 12v-12v
|
|
|
|
|
*
|
|
|
|
|
* When set to kForwardOnly or kReverseOnly, you can specify the constant for
|
|
|
|
|
* the direction or you can simply specify kOff and kOn. Using only kOff and
|
|
|
|
|
* kOn is recommended.
|
|
|
|
|
*
|
|
|
|
|
* @param value The state to set the relay.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Set(Value value);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the Relay State
|
|
|
|
|
*
|
|
|
|
|
* Gets the current state of the relay.
|
|
|
|
|
*
|
|
|
|
|
* When set to kForwardOnly or kReverseOnly, value is returned as kOn/kOff not
|
|
|
|
|
* kForward/kReverse (per the recommendation in Set).
|
|
|
|
|
*
|
|
|
|
|
* @return The current state of the relay as a Relay::Value
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
Value Get() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetChannel() const;
|
2015-07-09 03:24:31 -07:00
|
|
|
|
2018-11-22 21:15:26 -08:00
|
|
|
// MotorSafety interface
|
2015-07-09 03:24:31 -07:00
|
|
|
void StopMotor() override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
void GetDescription(wpi::raw_ostream& desc) const override;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
void InitSendable(SendableBuilder& builder) override;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
private:
|
2016-09-06 00:01:45 -07:00
|
|
|
int m_channel;
|
2015-06-25 15:07:55 -04:00
|
|
|
Direction m_direction;
|
2015-07-09 03:24:31 -07:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle;
|
|
|
|
|
HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|