[hal, wpilib] Remove relay (#7695)

This commit is contained in:
Thad House
2025-01-16 23:20:07 -08:00
committed by GitHub
parent d9f8fded09
commit 5017393b3a
54 changed files with 1 additions and 3115 deletions

View File

@@ -1,128 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include <string>
#include <hal/Relay.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/MotorSafety.h"
namespace frc {
/**
* Class for Spike style relay outputs.
*
* Relays are intended to be connected to spikes or similar relays. The relay
* 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
* speed. It also allows the two channels (forward and reverse) to be used
* independently for something that does not care about voltage polarity (like
* a solenoid).
*/
class Relay : public MotorSafety,
public wpi::Sendable,
public wpi::SendableHelper<Relay> {
public:
/**
* The state to drive a Relay to.
*/
enum Value {
/// Off.
kOff,
/// On.
kOn,
/// Forward.
kForward,
/// Reverse.
kReverse
};
/**
* The Direction(s) that a relay is configured to operate in.
*/
enum Direction {
/// Both directions are valid.
kBothDirections,
/// Only forward is valid.
kForwardOnly,
/// Only reverse is valid.
kReverseOnly
};
/**
* 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.
*/
explicit Relay(int channel, Direction direction = kBothDirections);
Relay(Relay&&) = default;
Relay& operator=(Relay&&) = default;
/**
* Free the resource associated with a relay.
*
* The relay channels are set to free and the relay output is turned off.
*/
~Relay() override;
/**
* 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.
*/
void Set(Value value);
/**
* 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
*/
Value Get() const;
int GetChannel() const;
// MotorSafety interface
void StopMotor() override;
std::string GetDescription() const override;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
int m_channel;
Direction m_direction;
hal::Handle<HAL_RelayHandle, HAL_FreeRelayPort> m_forwardHandle;
hal::Handle<HAL_RelayHandle, HAL_FreeRelayPort> m_reverseHandle;
};
} // namespace frc

View File

@@ -38,16 +38,6 @@ class SensorUtil final {
*/
static bool CheckDigitalChannel(int channel);
/**
* Check that the relay channel number is valid.
*
* Verify that the channel number is one of the legal channel numbers. Channel
* numbers are 0-based.
*
* @return Relay channel is valid
*/
static bool CheckRelayChannel(int channel);
/**
* Check that the digital channel number is valid.
*
@@ -82,7 +72,6 @@ class SensorUtil final {
static int GetNumAnalogInputs();
static int GetNumAnalogOuputs();
static int GetNumPwmChannels();
static int GetNumRelayChannels();
};
} // namespace frc

View File

@@ -1,145 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include "frc/simulation/CallbackStore.h"
namespace frc {
class Relay;
namespace sim {
/**
* Class to control a simulated relay.
*/
class RelaySim {
public:
/**
* Constructs from a Relay object.
*
* @param relay Relay to simulate
*/
explicit RelaySim(const Relay& relay);
/**
* Constructs from a relay channel number.
*
* @param channel Channel number
*/
explicit RelaySim(int channel);
/**
* Register a callback to be run when the forward direction is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterInitializedForwardCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the forward direction has been initialized.
*
* @return true if initialized
*/
bool GetInitializedForward() const;
/**
* Define whether the forward direction has been initialized.
*
* @param initializedForward whether this object is initialized
*/
void SetInitializedForward(bool initializedForward);
/**
* Register a callback to be run when the reverse direction is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterInitializedReverseCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the reverse direction has been initialized.
*
* @return true if initialized
*/
bool GetInitializedReverse() const;
/**
* Define whether the reverse direction has been initialized.
*
* @param initializedReverse whether this object is initialized
*/
void SetInitializedReverse(bool initializedReverse);
/**
* Register a callback to be run when the forward direction changes state.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterForwardCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the forward direction is active.
*
* @return true if active
*/
bool GetForward() const;
/**
* Set whether the forward direction is active.
*
* @param forward true to make active
*/
void SetForward(bool forward);
/**
* Register a callback to be run when the reverse direction changes state.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterReverseCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the reverse direction is active.
*
* @return true if active
*/
bool GetReverse() const;
/**
* Set whether the reverse direction is active.
*
* @param reverse true to make active
*/
void SetReverse(bool reverse);
/**
* Reset all simulation data.
*/
void ResetData();
private:
int m_index;
};
} // namespace sim
} // namespace frc