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:
@@ -99,8 +99,8 @@ public class PCMTest extends AbstractComsSetup {
|
||||
public void testSolenoid() throws Exception {
|
||||
reset();
|
||||
|
||||
Solenoid solenoid1 = new Solenoid(pcm, 0);
|
||||
Solenoid solenoid2 = new Solenoid(pcm, 1);
|
||||
Solenoid solenoid1 = new Solenoid(PneumaticsModuleType.CTREPCM, 0);
|
||||
Solenoid solenoid2 = new Solenoid(PneumaticsModuleType.CTREPCM, 1);
|
||||
|
||||
solenoid1.set(false);
|
||||
solenoid2.set(false);
|
||||
@@ -147,7 +147,7 @@ public class PCMTest extends AbstractComsSetup {
|
||||
*/
|
||||
@Test
|
||||
public void doubleSolenoid() {
|
||||
DoubleSolenoid solenoid = new DoubleSolenoid(pcm, 0, 1);
|
||||
DoubleSolenoid solenoid = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 0, 1);
|
||||
|
||||
solenoid.set(DoubleSolenoid.Value.kOff);
|
||||
Timer.delay(kSolenoidDelayTime);
|
||||
@@ -177,8 +177,8 @@ public class PCMTest extends AbstractComsSetup {
|
||||
public void testOneShot() throws Exception {
|
||||
reset();
|
||||
|
||||
Solenoid solenoid1 = new Solenoid(pcm, 0);
|
||||
Solenoid solenoid2 = new Solenoid(pcm, 1);
|
||||
Solenoid solenoid1 = new Solenoid(PneumaticsModuleType.CTREPCM, 0);
|
||||
Solenoid solenoid2 = new Solenoid(PneumaticsModuleType.CTREPCM, 1);
|
||||
|
||||
solenoid1.set(false);
|
||||
solenoid2.set(false);
|
||||
|
||||
Reference in New Issue
Block a user