mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[hal] Add a unified PCM object (#3331)
This commit is contained in:
@@ -1,185 +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 <hal/Types.h>
|
||||
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SendableBuilder;
|
||||
|
||||
/**
|
||||
* Class for operating a compressor connected to a %PCM (Pneumatic Control
|
||||
* Module).
|
||||
*
|
||||
* The PCM will automatically run in closed loop mode by default whenever a
|
||||
* Solenoid object is created. For most cases, a Compressor object does not need
|
||||
* to be instantiated or used in a robot program. This class is only required in
|
||||
* cases where the robot program needs a more detailed status of the compressor
|
||||
* or to enable/disable closed loop control.
|
||||
*
|
||||
* Note: you cannot operate the compressor directly from this class as doing so
|
||||
* would circumvent the safety provided by using the pressure switch and closed
|
||||
* loop control. You can only turn off closed loop control, thereby stopping
|
||||
* the compressor from operating.
|
||||
*/
|
||||
class Compressor : public Sendable, public SendableHelper<Compressor> {
|
||||
public:
|
||||
/**
|
||||
* Constructor. The default PCM ID is 0.
|
||||
*
|
||||
* @param module The PCM ID to use (0-62)
|
||||
*/
|
||||
explicit Compressor(int pcmID = SensorUtil::GetDefaultSolenoidModule());
|
||||
|
||||
~Compressor() override = default;
|
||||
|
||||
Compressor(Compressor&&) = default;
|
||||
Compressor& operator=(Compressor&&) = default;
|
||||
|
||||
/**
|
||||
* Starts closed-loop control. Note that closed loop control is enabled by
|
||||
* default.
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* Stops closed-loop control. Note that closed loop control is enabled by
|
||||
* default.
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* Check if compressor output is active.
|
||||
*
|
||||
* @return true if the compressor is on
|
||||
*/
|
||||
bool Enabled() const;
|
||||
|
||||
/**
|
||||
* Check if the pressure switch is triggered.
|
||||
*
|
||||
* @return true if pressure is low
|
||||
*/
|
||||
bool GetPressureSwitchValue() const;
|
||||
|
||||
/**
|
||||
* Query how much current the compressor is drawing.
|
||||
*
|
||||
* @return The current through the compressor, in amps
|
||||
*/
|
||||
double GetCompressorCurrent() const;
|
||||
|
||||
/**
|
||||
* Enables or disables automatically turning the compressor on when the
|
||||
* pressure is low.
|
||||
*
|
||||
* @param on Set to true to enable closed loop control of the compressor.
|
||||
* False to disable.
|
||||
*/
|
||||
void SetClosedLoopControl(bool on);
|
||||
|
||||
/**
|
||||
* Returns true if the compressor will automatically turn on when the
|
||||
* pressure is low.
|
||||
*
|
||||
* @return True if closed loop control of the compressor is enabled. False if
|
||||
* disabled.
|
||||
*/
|
||||
bool GetClosedLoopControl() const;
|
||||
|
||||
/**
|
||||
* Query if the compressor output has been disabled due to high current draw.
|
||||
*
|
||||
* @return true if PCM is in fault state : Compressor Drive is
|
||||
* disabled due to compressor current being too high.
|
||||
*/
|
||||
bool GetCompressorCurrentTooHighFault() const;
|
||||
|
||||
/**
|
||||
* Query if the compressor output has been disabled due to high current draw
|
||||
* (sticky).
|
||||
*
|
||||
* A sticky fault will not clear on device reboot, it must be cleared through
|
||||
* code or the webdash.
|
||||
*
|
||||
* @return true if PCM sticky fault is set : Compressor Drive is
|
||||
* disabled due to compressor current being too high.
|
||||
*/
|
||||
bool GetCompressorCurrentTooHighStickyFault() const;
|
||||
|
||||
/**
|
||||
* Query if the compressor output has been disabled due to a short circuit
|
||||
* (sticky).
|
||||
*
|
||||
* A sticky fault will not clear on device reboot, it must be cleared through
|
||||
* code or the webdash.
|
||||
*
|
||||
* @return true if PCM sticky fault is set : Compressor output
|
||||
* appears to be shorted.
|
||||
*/
|
||||
bool GetCompressorShortedStickyFault() const;
|
||||
|
||||
/**
|
||||
* Query if the compressor output has been disabled due to a short circuit.
|
||||
*
|
||||
* @return true if PCM is in fault state : Compressor output
|
||||
* appears to be shorted.
|
||||
*/
|
||||
bool GetCompressorShortedFault() const;
|
||||
|
||||
/**
|
||||
* Query if the compressor output does not appear to be wired (sticky).
|
||||
*
|
||||
* A sticky fault will not clear on device reboot, it must be cleared through
|
||||
* code or the webdash.
|
||||
*
|
||||
* @return true if PCM sticky fault is set : Compressor does not
|
||||
* appear to be wired, i.e. compressor is not drawing enough current.
|
||||
*/
|
||||
bool GetCompressorNotConnectedStickyFault() const;
|
||||
|
||||
/**
|
||||
* Query if the compressor output does not appear to be wired.
|
||||
*
|
||||
* @return true if PCM is in fault state : Compressor does not
|
||||
* appear to be wired, i.e. compressor is not drawing enough current.
|
||||
*/
|
||||
bool GetCompressorNotConnectedFault() const;
|
||||
|
||||
/**
|
||||
* Clear ALL sticky faults inside PCM that Compressor is wired to.
|
||||
*
|
||||
* If a sticky fault is set, then it will be persistently cleared. Compressor
|
||||
* drive maybe momentarily disable while flags are being cleared. Care should
|
||||
* be taken to not call this too frequently, otherwise normal compressor
|
||||
* functionality may be prevented.
|
||||
*
|
||||
* If no sticky faults are set then this call will have no effect.
|
||||
*/
|
||||
void ClearAllPCMStickyFaults();
|
||||
|
||||
/**
|
||||
* Gets module number (CAN ID).
|
||||
*
|
||||
* @return Module number
|
||||
*/
|
||||
int GetModule() const;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
hal::Handle<HAL_CompressorHandle> m_compressorHandle;
|
||||
|
||||
private:
|
||||
void SetCompressor(bool on);
|
||||
int m_module;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/SolenoidBase.h"
|
||||
#include "frc/PneumaticsBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -21,30 +23,16 @@ class SendableBuilder;
|
||||
* The DoubleSolenoid class is typically used for pneumatics solenoids that
|
||||
* have two positions controlled by two separate channels.
|
||||
*/
|
||||
class DoubleSolenoid : public SolenoidBase,
|
||||
public Sendable,
|
||||
public SendableHelper<DoubleSolenoid> {
|
||||
class DoubleSolenoid : public Sendable, public SendableHelper<DoubleSolenoid> {
|
||||
public:
|
||||
enum Value { kOff, kForward, kReverse };
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Uses the default PCM ID of 0.
|
||||
*
|
||||
* @param forwardChannel The forward channel number on the PCM (0..7).
|
||||
* @param reverseChannel The reverse channel number on the PCM (0..7).
|
||||
*/
|
||||
explicit DoubleSolenoid(int forwardChannel, int reverseChannel);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM.
|
||||
* @param forwardChannel The forward channel on the PCM to control (0..7).
|
||||
* @param reverseChannel The reverse channel on the PCM to control (0..7).
|
||||
*/
|
||||
DoubleSolenoid(int moduleNumber, int forwardChannel, int reverseChannel);
|
||||
DoubleSolenoid(PneumaticsBase& module, int forwardChannel,
|
||||
int reverseChannel);
|
||||
DoubleSolenoid(PneumaticsBase* module, int forwardChannel,
|
||||
int reverseChannel);
|
||||
DoubleSolenoid(std::shared_ptr<PneumaticsBase> module, int forwardChannel,
|
||||
int reverseChannel);
|
||||
|
||||
~DoubleSolenoid() override;
|
||||
|
||||
@@ -89,26 +77,26 @@ class DoubleSolenoid : public SolenoidBase,
|
||||
int GetRevChannel() const;
|
||||
|
||||
/**
|
||||
* Check if the forward solenoid is blacklisted.
|
||||
* Check if the forward solenoid is Disabled.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and disabled until
|
||||
* power cycle, or until faults are cleared.
|
||||
* If a solenoid is shorted, it is added to the DisabledList and disabled
|
||||
* until power cycle, or until faults are cleared.
|
||||
*
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
* @return If solenoid is disabled due to short.
|
||||
*/
|
||||
bool IsFwdSolenoidBlackListed() const;
|
||||
bool IsFwdSolenoidDisabled() const;
|
||||
|
||||
/**
|
||||
* Check if the reverse solenoid is blacklisted.
|
||||
* Check if the reverse solenoid is Disabled.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and disabled until
|
||||
* power cycle, or until faults are cleared.
|
||||
* If a solenoid is shorted, it is added to the DisabledList and disabled
|
||||
* until power cycle, or until faults are cleared.
|
||||
*
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
* @return If solenoid is disabled due to short.
|
||||
*/
|
||||
bool IsRevSolenoidBlackListed() const;
|
||||
bool IsRevSolenoidDisabled() const;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
@@ -117,8 +105,8 @@ class DoubleSolenoid : public SolenoidBase,
|
||||
int m_reverseChannel; // The reverse channel on the module to control.
|
||||
int m_forwardMask; // The mask for the forward channel.
|
||||
int m_reverseMask; // The mask for the reverse channel.
|
||||
hal::Handle<HAL_SolenoidHandle> m_forwardHandle;
|
||||
hal::Handle<HAL_SolenoidHandle> m_reverseHandle;
|
||||
int m_mask;
|
||||
std::shared_ptr<PneumaticsBase> m_module;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
28
wpilibc/src/main/native/include/frc/PneumaticsBase.h
Normal file
28
wpilibc/src/main/native/include/frc/PneumaticsBase.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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 <units/time.h>
|
||||
|
||||
namespace frc {
|
||||
class PneumaticsBase {
|
||||
public:
|
||||
virtual ~PneumaticsBase() = default;
|
||||
|
||||
virtual void SetSolenoids(int mask, int values) = 0;
|
||||
|
||||
virtual int GetSolenoids() const = 0;
|
||||
|
||||
virtual int GetModuleNumber() const = 0;
|
||||
|
||||
virtual int GetSolenoidDisabledList() const = 0;
|
||||
|
||||
virtual void FireOneShot(int index) = 0;
|
||||
|
||||
virtual void SetOneShotDuration(int index, units::second_t duration) = 0;
|
||||
|
||||
virtual bool CheckSolenoidChannel(int channel) const = 0;
|
||||
};
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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 <hal/Types.h>
|
||||
|
||||
#include "PneumaticsBase.h"
|
||||
|
||||
namespace frc {
|
||||
class PneumaticsControlModule : public PneumaticsBase {
|
||||
public:
|
||||
PneumaticsControlModule();
|
||||
explicit PneumaticsControlModule(int module);
|
||||
|
||||
~PneumaticsControlModule() override;
|
||||
|
||||
PneumaticsControlModule(PneumaticsControlModule&&) = default;
|
||||
PneumaticsControlModule& operator=(PneumaticsControlModule&&) = default;
|
||||
|
||||
bool GetCompressor();
|
||||
|
||||
void SetClosedLoopControl(bool enabled);
|
||||
|
||||
bool GetClosedLoopControl();
|
||||
|
||||
bool GetPressureSwitch();
|
||||
|
||||
double GetCompressorCurrent();
|
||||
|
||||
bool GetCompressorCurrentTooHighFault();
|
||||
bool GetCompressorCurrentTooHighStickyFault();
|
||||
bool GetCompressorShortedFault();
|
||||
bool GetCompressorShortedStickyFault();
|
||||
bool GetCompressorNotConnectedFault();
|
||||
bool GetCompressorNotConnectedStickyFault();
|
||||
|
||||
bool GetSolenoidVoltageFault();
|
||||
bool GetSolenoidVoltageStickyFault();
|
||||
|
||||
void ClearAllStickyFaults();
|
||||
|
||||
void SetSolenoids(int mask, int values) override;
|
||||
|
||||
int GetSolenoids() const override;
|
||||
|
||||
int GetModuleNumber() const override;
|
||||
|
||||
int GetSolenoidDisabledList() const override;
|
||||
|
||||
void FireOneShot(int index) override;
|
||||
|
||||
void SetOneShotDuration(int index, units::second_t duration) override;
|
||||
|
||||
bool CheckSolenoidChannel(int channel) const override;
|
||||
|
||||
private:
|
||||
int m_module;
|
||||
hal::Handle<HAL_CTREPCMHandle> m_handle;
|
||||
};
|
||||
} // namespace frc
|
||||
@@ -19,14 +19,7 @@ class SensorUtil final {
|
||||
*
|
||||
* @return The number of the default solenoid module.
|
||||
*/
|
||||
static int GetDefaultSolenoidModule();
|
||||
|
||||
/**
|
||||
* Check that the solenoid module number is valid. module numbers are 0-based
|
||||
*
|
||||
* @return Solenoid module is valid and present
|
||||
*/
|
||||
static bool CheckSolenoidModule(int moduleNumber);
|
||||
static int GetDefaultCTREPCMModule();
|
||||
|
||||
/**
|
||||
* Check that the digital channel number is valid.
|
||||
@@ -78,13 +71,6 @@ class SensorUtil final {
|
||||
*/
|
||||
static bool CheckAnalogOutputChannel(int channel);
|
||||
|
||||
/**
|
||||
* Verify that the solenoid channel number is within limits.
|
||||
*
|
||||
* @return Solenoid channel is valid
|
||||
*/
|
||||
static bool CheckSolenoidChannel(int channel);
|
||||
|
||||
/**
|
||||
* Verify that the power distribution channel number is within limits.
|
||||
*
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Types.h>
|
||||
#include <units/time.h>
|
||||
|
||||
#include "frc/SolenoidBase.h"
|
||||
#include "frc/PneumaticsBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -21,24 +23,11 @@ class SendableBuilder;
|
||||
* The Solenoid class is typically used for pneumatics solenoids, but could be
|
||||
* used for any device within the current spec of the PCM.
|
||||
*/
|
||||
class Solenoid : public SolenoidBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Solenoid> {
|
||||
class Solenoid : public Sendable, public SendableHelper<Solenoid> {
|
||||
public:
|
||||
/**
|
||||
* Constructor using the default PCM ID (0).
|
||||
*
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
explicit Solenoid(int channel);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM the solenoid is attached to
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
Solenoid(int moduleNumber, int channel);
|
||||
Solenoid(PneumaticsBase& module, int channel);
|
||||
Solenoid(PneumaticsBase* module, int channel);
|
||||
Solenoid(std::shared_ptr<PneumaticsBase> module, int channel);
|
||||
|
||||
~Solenoid() override;
|
||||
|
||||
@@ -73,16 +62,16 @@ class Solenoid : public SolenoidBase,
|
||||
int GetChannel() const;
|
||||
|
||||
/**
|
||||
* Check if solenoid is blacklisted.
|
||||
* Check if solenoid is Disabled.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and
|
||||
* If a solenoid is shorted, it is added to the DisabledList and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
*
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
*
|
||||
* @return If solenoid is disabled due to short.
|
||||
*/
|
||||
bool IsBlackListed() const;
|
||||
bool IsDisabled() const;
|
||||
|
||||
/**
|
||||
* Set the pulse duration in the PCM. This is used in conjunction with
|
||||
@@ -107,8 +96,9 @@ class Solenoid : public SolenoidBase,
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
hal::Handle<HAL_SolenoidHandle> m_solenoidHandle;
|
||||
int m_channel; // The channel on the module to control
|
||||
std::shared_ptr<PneumaticsBase> m_module;
|
||||
int m_mask;
|
||||
int m_channel;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -1,131 +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
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* SolenoidBase class is the common base class for the Solenoid and
|
||||
* DoubleSolenoid classes.
|
||||
*/
|
||||
class SolenoidBase {
|
||||
public:
|
||||
virtual ~SolenoidBase() = default;
|
||||
|
||||
/**
|
||||
* Get the CAN ID of the module this solenoid is connected to.
|
||||
*
|
||||
* @return the module number.
|
||||
*/
|
||||
int GetModuleNumber() const;
|
||||
|
||||
/**
|
||||
* Read all 8 solenoids as a single byte
|
||||
*
|
||||
* @param module the module to read from
|
||||
* @return The current value of all 8 solenoids on the module.
|
||||
*/
|
||||
static int GetAll(int module);
|
||||
|
||||
/**
|
||||
* Read all 8 solenoids as a single byte
|
||||
*
|
||||
* @return The current value of all 8 solenoids on the module.
|
||||
*/
|
||||
int GetAll() const;
|
||||
|
||||
/**
|
||||
* Reads complete solenoid blacklist for all 8 solenoids as a single byte.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
*
|
||||
* @param module the module to read from
|
||||
* @return The solenoid blacklist of all 8 solenoids on the module.
|
||||
*/
|
||||
static int GetPCMSolenoidBlackList(int module);
|
||||
|
||||
/**
|
||||
* Reads complete solenoid blacklist for all 8 solenoids as a single byte.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
*
|
||||
* @return The solenoid blacklist of all 8 solenoids on the module.
|
||||
*/
|
||||
int GetPCMSolenoidBlackList() const;
|
||||
|
||||
/**
|
||||
* @param module the module to read from
|
||||
* @return true if PCM sticky fault is set : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
static bool GetPCMSolenoidVoltageStickyFault(int module);
|
||||
|
||||
/**
|
||||
* @return true if PCM sticky fault is set : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
bool GetPCMSolenoidVoltageStickyFault() const;
|
||||
|
||||
/**
|
||||
* @param module the module to read from
|
||||
* @return true if PCM is in fault state : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
static bool GetPCMSolenoidVoltageFault(int module);
|
||||
|
||||
/**
|
||||
* @return true if PCM is in fault state : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
bool GetPCMSolenoidVoltageFault() const;
|
||||
|
||||
/**
|
||||
* Clear ALL sticky faults inside PCM that Compressor is wired to.
|
||||
*
|
||||
* If a sticky fault is set, then it will be persistently cleared. Compressor
|
||||
* drive maybe momentarily disable while flags are being cleared. Care should
|
||||
* be taken to not call this too frequently, otherwise normal compressor
|
||||
* functionality may be prevented.
|
||||
*
|
||||
* If no sticky faults are set then this call will have no effect.
|
||||
*
|
||||
* @param module the module to read from
|
||||
*/
|
||||
static void ClearAllPCMStickyFaults(int module);
|
||||
|
||||
/**
|
||||
* Clear ALL sticky faults inside PCM that Compressor is wired to.
|
||||
*
|
||||
* If a sticky fault is set, then it will be persistently cleared. Compressor
|
||||
* drive maybe momentarily disable while flags are being cleared. Care should
|
||||
* be taken to not call this too frequently, otherwise normal compressor
|
||||
* functionality may be prevented.
|
||||
*
|
||||
* If no sticky faults are set then this call will have no effect.
|
||||
*/
|
||||
void ClearAllPCMStickyFaults();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN PCM ID.
|
||||
*/
|
||||
explicit SolenoidBase(int pcmID);
|
||||
|
||||
SolenoidBase(SolenoidBase&&) = default;
|
||||
SolenoidBase& operator=(SolenoidBase&&) = default;
|
||||
|
||||
static constexpr int m_maxModules = 63;
|
||||
static constexpr int m_maxPorts = 8;
|
||||
|
||||
int m_moduleNumber; // PCM module number
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "frc/PneumaticsBase.h"
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -17,26 +18,21 @@ namespace sim {
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
class PCMSim {
|
||||
class CTREPCMSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs with the default PCM module number (CAN ID).
|
||||
*/
|
||||
PCMSim();
|
||||
CTREPCMSim();
|
||||
|
||||
/**
|
||||
* Constructs from a PCM module number (CAN ID).
|
||||
*
|
||||
* @param module module number
|
||||
*/
|
||||
explicit PCMSim(int module);
|
||||
explicit CTREPCMSim(int module);
|
||||
|
||||
/**
|
||||
* Constructs from a Compressor object.
|
||||
*
|
||||
* @param compressor Compressor connected to PCM to simulate
|
||||
*/
|
||||
explicit PCMSim(const Compressor& compressor);
|
||||
explicit CTREPCMSim(const PneumaticsBase& pneumatics);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when a solenoid is initialized on a channel.
|
||||
@@ -46,17 +42,15 @@ class PCMSim {
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore>
|
||||
RegisterSolenoidInitializedCallback(int channel, NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if a solenoid has been initialized on a specific channel.
|
||||
*
|
||||
* @param channel the channel to check
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetSolenoidInitialized(int channel) const;
|
||||
bool GetInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether a solenoid has been initialized on a specific channel.
|
||||
@@ -64,7 +58,7 @@ class PCMSim {
|
||||
* @param channel the channel
|
||||
* @param solenoidInitialized is there a solenoid initialized on that channel
|
||||
*/
|
||||
void SetSolenoidInitialized(int channel, bool solenoidInitialized);
|
||||
void SetInitialized(bool solenoidInitialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the solenoid output on a channel
|
||||
@@ -94,31 +88,6 @@ class PCMSim {
|
||||
*/
|
||||
void SetSolenoidOutput(int channel, bool solenoidOutput);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the compressor 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>
|
||||
RegisterCompressorInitializedCallback(NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check whether the compressor has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetCompressorInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether the compressor has been initialized.
|
||||
*
|
||||
* @param compressorInitialized whether the compressor is initialized
|
||||
*/
|
||||
void SetCompressorInitialized(bool compressorInitialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the compressor activates.
|
||||
*
|
||||
@@ -1,116 +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/DoubleSolenoid.h"
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
|
||||
namespace frc::sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
class DoubleSolenoidSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs for a solenoid on the default PCM.
|
||||
*
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
DoubleSolenoidSim(int fwd, int rev);
|
||||
|
||||
/**
|
||||
* Constructs for a solenoid on the given PCM.
|
||||
*
|
||||
* @param pcm the PCM the solenoid is connected to.
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
DoubleSolenoidSim(int module, int fwd, int rev);
|
||||
|
||||
/**
|
||||
* Constructs from a PCMSim object.
|
||||
*
|
||||
* @param pcm the PCM the solenoid is connected to.
|
||||
*/
|
||||
DoubleSolenoidSim(PCMSim& pcm, int fwd, int rev);
|
||||
|
||||
/**
|
||||
* Constructs for the given solenoid.
|
||||
*
|
||||
* @param solenoid the solenoid to simulate.
|
||||
*/
|
||||
explicit DoubleSolenoidSim(DoubleSolenoid& solenoid);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the forward solenoid is initialized.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterFwdInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if the forward solenoid has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetFwdInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether the forward solenoid has been initialized.
|
||||
*
|
||||
* @param initialized whether the solenoid is intiialized.
|
||||
*/
|
||||
void SetFwdInitialized(bool initialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the reverse solenoid is initialized.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterRevInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Define whether the reverse solenoid has been initialized.
|
||||
*
|
||||
* @param initialized whether the solenoid is intiialized.
|
||||
*/
|
||||
void SetRevInitialized(bool initialized);
|
||||
|
||||
/**
|
||||
* Check if the reverse solenoid has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetRevInitialized() const;
|
||||
|
||||
/**
|
||||
* Set the value of the double solenoid output.
|
||||
*
|
||||
* @param value The value to set (Off, Forward, Reverse)
|
||||
*/
|
||||
void Set(DoubleSolenoid::Value value);
|
||||
|
||||
/**
|
||||
* Check the value of the double solenoid output.
|
||||
*
|
||||
* @return the output value of the double solenoid.
|
||||
*/
|
||||
DoubleSolenoid::Value Get() const;
|
||||
|
||||
private:
|
||||
PCMSim m_pcm;
|
||||
int m_fwd;
|
||||
int m_rev;
|
||||
};
|
||||
} // namespace frc::sim
|
||||
@@ -1,104 +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/Solenoid.h"
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
|
||||
namespace frc::sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
class SolenoidSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs for a solenoid on the default PCM.
|
||||
*
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
explicit SolenoidSim(int channel);
|
||||
|
||||
/**
|
||||
* Constructs for the given solenoid.
|
||||
*
|
||||
* @param doubleSolenoid the solenoid to simulate.
|
||||
*/
|
||||
explicit SolenoidSim(Solenoid& solenoid);
|
||||
|
||||
/**
|
||||
* Constructs for a solenoid.
|
||||
*
|
||||
* @param module the CAN ID of the PCM the solenoid is connected to.
|
||||
* @param channel the solenoid channel.
|
||||
*
|
||||
* @see PCMSim#PCMSim(int)
|
||||
*/
|
||||
SolenoidSim(int module, int channel);
|
||||
|
||||
/**
|
||||
* Constructs for a solenoid on the given PCM.
|
||||
*
|
||||
* @param pcm the PCM the solenoid is connected to.
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
SolenoidSim(PCMSim& pcm, int channel);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when this solenoid is initialized.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if this solenoid has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether this solenoid has been initialized.
|
||||
*
|
||||
* @param initialized whether the solenoid is intiialized.
|
||||
*/
|
||||
void SetInitialized(bool initialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the output of this solenoid has changed.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial value
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterOutputCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check the solenoid output.
|
||||
*
|
||||
* @return the solenoid output
|
||||
*/
|
||||
bool GetOutput() const;
|
||||
|
||||
/**
|
||||
* Change the solenoid output.
|
||||
*
|
||||
* @param output the new solenoid output
|
||||
*/
|
||||
void SetOutput(bool output);
|
||||
|
||||
private:
|
||||
PCMSim m_pcm;
|
||||
int m_channel;
|
||||
};
|
||||
} // namespace frc::sim
|
||||
Reference in New Issue
Block a user