mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal, wpilib] Switch PCM to be a single object that is allowed to be duplicated (#3475)
Having PCM as a singleton is a problem, as multiple things need to use it, and that gets really ugly. This changes PCM's to be a reference counted object, that can be passed around and constructed from multiple places. In Java, this is using a map to hold a data store with a ref count, and allocating new objects any time a duplicate is requested. In C++, this uses a trick constructor to store a PCM instance in the data store itself. This instance can then be passed to base objects using std::shared_ptr's aliasing constructor, which means constructing a solenoid from a PCM is not allocating after the 1st one. This did require removing sendable from PCM. A compressor class was added back in to act as sendable for the PCM. After this change is finished, the only change RobotBuilder and Team Code would require is passing a module type to solenoid constructors. Co-authored-by: sciencewhiz <sciencewhiz@users.noreply.github.com>
This commit is contained in:
@@ -8,17 +8,15 @@ import static edu.wpi.first.wpilibj.DoubleSolenoid.Value.kForward;
|
||||
import static edu.wpi.first.wpilibj.DoubleSolenoid.Value.kReverse;
|
||||
|
||||
import edu.wpi.first.wpilibj.DoubleSolenoid;
|
||||
import edu.wpi.first.wpilibj.PneumaticsControlModule;
|
||||
import edu.wpi.first.wpilibj.PneumaticsModuleType;
|
||||
import edu.wpi.first.wpilibj.examples.hatchbotinlined.Constants.HatchConstants;
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
/** A hatch mechanism actuated by a single {@link edu.wpi.first.wpilibj.DoubleSolenoid}. */
|
||||
public class HatchSubsystem extends SubsystemBase {
|
||||
private final PneumaticsControlModule m_controlModule =
|
||||
new PneumaticsControlModule(HatchConstants.kHatchSolenoidModule);
|
||||
private final DoubleSolenoid m_hatchSolenoid =
|
||||
new DoubleSolenoid(
|
||||
m_controlModule,
|
||||
PneumaticsModuleType.CTREPCM,
|
||||
HatchConstants.kHatchSolenoidPorts[0],
|
||||
HatchConstants.kHatchSolenoidPorts[1]);
|
||||
|
||||
|
||||
@@ -8,17 +8,15 @@ import static edu.wpi.first.wpilibj.DoubleSolenoid.Value.kForward;
|
||||
import static edu.wpi.first.wpilibj.DoubleSolenoid.Value.kReverse;
|
||||
|
||||
import edu.wpi.first.wpilibj.DoubleSolenoid;
|
||||
import edu.wpi.first.wpilibj.PneumaticsControlModule;
|
||||
import edu.wpi.first.wpilibj.PneumaticsModuleType;
|
||||
import edu.wpi.first.wpilibj.examples.hatchbottraditional.Constants.HatchConstants;
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
/** A hatch mechanism actuated by a single {@link DoubleSolenoid}. */
|
||||
public class HatchSubsystem extends SubsystemBase {
|
||||
private final PneumaticsControlModule m_controlModule =
|
||||
new PneumaticsControlModule(HatchConstants.kHatchSolenoidModule);
|
||||
private final DoubleSolenoid m_hatchSolenoid =
|
||||
new DoubleSolenoid(
|
||||
m_controlModule,
|
||||
PneumaticsModuleType.CTREPCM,
|
||||
HatchConstants.kHatchSolenoidPorts[0],
|
||||
HatchConstants.kHatchSolenoidPorts[1]);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat;
|
||||
|
||||
import edu.wpi.first.wpilibj.PneumaticsControlModule;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
@@ -30,8 +29,6 @@ public class Robot extends TimedRobot {
|
||||
Command m_autonomousCommand;
|
||||
public static OI oi;
|
||||
|
||||
public static PneumaticsControlModule pneumaticsModule = new PneumaticsControlModule(1);
|
||||
|
||||
// Initialize the subsystems
|
||||
public static DriveTrain drivetrain = new DriveTrain();
|
||||
public static Collector collector = new Collector();
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.PneumaticsModuleType;
|
||||
import edu.wpi.first.wpilibj.Solenoid;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Victor;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Collector extends Subsystem {
|
||||
private final MotorController m_rollerMotor = new Victor(6);
|
||||
private final DigitalInput m_ballDetector = new DigitalInput(10);
|
||||
private final DigitalInput m_openDetector = new DigitalInput(6);
|
||||
private final Solenoid m_piston = new Solenoid(Robot.pneumaticsModule, 1);
|
||||
private final Solenoid m_piston = new Solenoid(PneumaticsModuleType.CTREPCM, 1);
|
||||
|
||||
/** Create a new collector subsystem. */
|
||||
public Collector() {
|
||||
|
||||
@@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.examples.pacgoat.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DoubleSolenoid;
|
||||
import edu.wpi.first.wpilibj.PneumaticsModuleType;
|
||||
import edu.wpi.first.wpilibj.Solenoid;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
|
||||
/**
|
||||
* The Shooter subsystem handles shooting. The mechanism for shooting is slightly complicated
|
||||
@@ -21,9 +21,9 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
*/
|
||||
public class Shooter extends Subsystem {
|
||||
// Devices
|
||||
DoubleSolenoid m_piston1 = new DoubleSolenoid(Robot.pneumaticsModule, 3, 4);
|
||||
DoubleSolenoid m_piston2 = new DoubleSolenoid(Robot.pneumaticsModule, 5, 6);
|
||||
Solenoid m_latchPiston = new Solenoid(Robot.pneumaticsModule, 2);
|
||||
DoubleSolenoid m_piston1 = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 3, 4);
|
||||
DoubleSolenoid m_piston2 = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 5, 6);
|
||||
Solenoid m_latchPiston = new Solenoid(PneumaticsModuleType.CTREPCM, 2);
|
||||
DigitalInput m_piston1ReedSwitchFront = new DigitalInput(9);
|
||||
DigitalInput m_piston1ReedSwitchBack = new DigitalInput(11);
|
||||
// NOTE: currently ignored in simulation
|
||||
|
||||
@@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.examples.solenoid;
|
||||
|
||||
import edu.wpi.first.wpilibj.DoubleSolenoid;
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.PneumaticsControlModule;
|
||||
import edu.wpi.first.wpilibj.PneumaticsModuleType;
|
||||
import edu.wpi.first.wpilibj.Solenoid;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
|
||||
@@ -24,13 +24,12 @@ import edu.wpi.first.wpilibj.TimedRobot;
|
||||
public class Robot extends TimedRobot {
|
||||
private final Joystick m_stick = new Joystick(0);
|
||||
|
||||
private final PneumaticsControlModule m_pneumaticsModule = new PneumaticsControlModule(0);
|
||||
|
||||
// Solenoid corresponds to a single solenoid.
|
||||
private final Solenoid m_solenoid = new Solenoid(m_pneumaticsModule, 0);
|
||||
private final Solenoid m_solenoid = new Solenoid(PneumaticsModuleType.CTREPCM, 0);
|
||||
|
||||
// DoubleSolenoid corresponds to a double solenoid.
|
||||
private final DoubleSolenoid m_doubleSolenoid = new DoubleSolenoid(m_pneumaticsModule, 1, 2);
|
||||
private final DoubleSolenoid m_doubleSolenoid =
|
||||
new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 1, 2);
|
||||
|
||||
private static final int kSolenoidButton = 1;
|
||||
private static final int kDoubleSolenoidForward = 2;
|
||||
|
||||
Reference in New Issue
Block a user