mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[hal] Add a unified PCM object (#3331)
This commit is contained in:
@@ -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