Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions strongback-testing/src/org/strongback/mock/Mock.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@
*/
public class Mock {

/**
* Create a mock power panel.
*
* @return the mock power panel; never null
*/
public static MockPowerPanel powerPanel() {
return new MockPowerPanel(16);
}

/**
* Create a mock pneumatics module. This method can be called more than once to represent a robot with multiple pneumatics
* modules.
*
* @return the mock pneumatics module; never null
*/
public static MockPneumaticsModule pnuematicsModule() {
return new MockPneumaticsModule();
}

/**
* Create a mock clock.
*
Expand Down Expand Up @@ -175,6 +194,7 @@ public static MockSolenoid manualSolenoid() {

/**
* Create a relay that operates instantaneously.
*
* @return the mock relay; never null
*/
public static MockRelay relay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public MockAccelerometer setAcceleration(double accel) {
return this;
}

@Override
public String toString() {
return Double.toString(getAcceleration()) + " g/s\u00B2";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public MockAngleSensor setAngle(double angle) {
return this;
}

@Override
public String toString() {
return Double.toString(getAngle()) + "\u00B0";
}
}
4 changes: 4 additions & 0 deletions strongback-testing/src/org/strongback/mock/MockClock.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ public long currentTimeInMicros() {
return ticker.get();
}

@Override
public String toString() {
return Long.toString(currentTimeInMillis()) + " ms";
}
}
5 changes: 5 additions & 0 deletions strongback-testing/src/org/strongback/mock/MockCompass.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ public MockCompass setAngle(double angle) {
super.setValue(angle);
return this;
}

@Override
public String toString() {
return Double.toString(getHeading()) + "\u00B0 heading (" + getAngle() + "\u00B0)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public MockCurrentSensor setCurrent(double currentInAmps) {
return this;
}

@Override
public String toString() {
return Double.toString(getCurrent()) + "A";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public MockDistanceSensor setDistanceInFeet(double distance) {
return setDistanceInInches(distance * 12.0);
}

@Override
public String toString() {
return Double.toString(getDistanceInInches()) + " inches";
}
}
6 changes: 6 additions & 0 deletions strongback-testing/src/org/strongback/mock/MockMotor.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public MockMotor setSpeed(double speed) {
return this;
}

@Override
public MockMotor invert() {
return new MockMotor(speed) {
@Override
Expand All @@ -58,4 +59,9 @@ public double getSpeed() {
};
}


@Override
public String toString() {
return Double.toString(getSpeed());
}
}
175 changes: 175 additions & 0 deletions strongback-testing/src/org/strongback/mock/MockPneumaticsModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* Strongback
* Copyright 2015, Strongback and individual contributors by the @authors tag.
* See the COPYRIGHT.txt in the distribution for a full listing of individual
* contributors.
*
* Licensed under the MIT License; you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.strongback.mock;

import org.strongback.components.Fuse;
import org.strongback.components.PneumaticsModule;
import org.strongback.components.Switch;

/**
* A mock implementation of the {@link PneumaticsModule} that allows the caller to control the {@link #lowPressureSwitch()}.
* When the module's {@link #automaticMode()} is enabled, then triggering the {@link #lowPressureSwitch() low pressure switch}
* will start the compressor, and {@link MockSwitch#setNotTriggered() un-triggering} the {@link #lowPressureSwitch() low
* pressure switch} will stop the compressor.
*
* @author Randall Hauch
*/
public class MockPneumaticsModule implements PneumaticsModule {

public static double COMPRESSOR_CURRENT_WHEN_RUNNING = 10.0;

private final StickyFaults stickyFaults = new StickyFaults();
private final MockFaults instantaneousFaults = new MockFaults(stickyFaults);
private final MockCurrentSensor current = new MockCurrentSensor();
private final MockSwitch running = new MockSwitch().setNotTriggered();
private final MockSwitch lowPressure = new MockSwitch() {
@Override
public MockSwitch setTriggered(boolean triggered) {
super.setTriggered(triggered);
if (automatic.isOn()) {
// The caller is manually triggering the switch, but this affects whether compressor runs ...
runCompressor(triggered);
}
return this;
}
};
private final MockRelay automatic = new MockRelay() {
@Override
public MockRelay off() {
super.off();
runCompressor(false);
return this;
}

@Override
public MockRelay on() {
super.on();
return this;
}
};

public MockPneumaticsModule() {
automatic.on();
lowPressure.setNotTriggered();
}

private void runCompressor( boolean isRunning ) {
if ( isRunning ) {
running.setTriggered(isRunning);
current.setCurrent(COMPRESSOR_CURRENT_WHEN_RUNNING);
} else {
running.setNotTriggered();
current.setCurrent(0.0);
}
}

@Override
public MockCurrentSensor compressorCurrent() {
return current;
}

@Override
public Switch compressorRunningSwitch() {
return running;
}

@Override
public MockSwitch lowPressureSwitch() {
return lowPressure;
}

@Override
public MockRelay automaticMode() {
return automatic;
}

/**
* These faults clear immediately after they are {@link Fuse#trigger() triggered}.
* @see #compressorStickyFaults()
*/
@Override
public MockFaults compressorFaults() {
return instantaneousFaults;
}

@Override
public Faults compressorStickyFaults() {
return stickyFaults;
}

@Override
public MockPneumaticsModule clearStickyFaults() {
stickyFaults.reset();
return this;
}

private void triggerFault( MockSwitch stickySwitch ) {
// Any fault should always stop the compressor ...
stickySwitch.setTriggered();
runCompressor(false);
}

public class MockFaults implements Faults {
private final Fuse currentTooHigh;
private final Fuse notConnected;
private final Fuse shorted;
protected MockFaults( StickyFaults sticky ) {
// These should trip the sticky faults and then immediately reset ...
currentTooHigh = Fuse.instantaneous(()->triggerFault(sticky.currentTooHigh));
notConnected = Fuse.instantaneous(()->triggerFault(sticky.notConnected));
shorted = Fuse.instantaneous(()->triggerFault(sticky.shorted));
}

@Override
public Fuse currentTooHigh() {
return currentTooHigh;
}
@Override
public Fuse notConnected() {
return notConnected;
}
@Override
public Fuse shorted() {
return shorted;
}
}

protected static class StickyFaults implements Faults {
private final MockSwitch currentTooHigh = new MockSwitch().setNotTriggered();
private final MockSwitch notConnected = new MockSwitch().setNotTriggered();
private final MockSwitch shorted = new MockSwitch().setNotTriggered();

@Override
public Switch currentTooHigh() {
return currentTooHigh;
}
@Override
public Switch notConnected() {
return notConnected;
}
@Override
public Switch shorted() {
return shorted;
}
protected void reset() {
currentTooHigh.setNotTriggered();
notConnected.setNotTriggered();
shorted.setNotTriggered();
}
}

}
66 changes: 66 additions & 0 deletions strongback-testing/src/org/strongback/mock/MockPowerPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Strongback
* Copyright 2015, Strongback and individual contributors by the @authors tag.
* See the COPYRIGHT.txt in the distribution for a full listing of individual
* contributors.
*
* Licensed under the MIT License; you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.strongback.mock;

import java.util.ArrayList;
import java.util.List;

import org.strongback.components.PowerPanel;

/**
* A mock implementation of the {@link PowerPanel}, which has 16 channels
* @author Randall Hauch
*/
public class MockPowerPanel implements PowerPanel {

private final List<MockCurrentSensor> channels;
private final MockTemperatureSensor temperature = new MockTemperatureSensor().setTemperature(72.0);
private final MockCurrentSensor totalCurrent = new MockCurrentSensor().setCurrent(10.0);
private final MockVoltageSensor voltage = new MockVoltageSensor().setVoltage(12.0);

/**
* Create a mock power panel with the specified number of channels.
* @param numChannels the number of channels; must be positive
*/
public MockPowerPanel( int numChannels ) {
channels = new ArrayList<>(numChannels);
for ( int i= 0; i!= numChannels; ++i ) {
channels.add(new MockCurrentSensor());
}
}

@Override
public MockCurrentSensor getCurrentSensor(int channel) {
return channels.get(channel);
}

@Override
public MockTemperatureSensor getTemperatureSensor() {
return temperature;
}

@Override
public MockCurrentSensor getTotalCurrentSensor() {
return totalCurrent;
}

@Override
public MockVoltageSensor getVoltageSensor() {
return voltage;
}

}
5 changes: 5 additions & 0 deletions strongback-testing/src/org/strongback/mock/MockRelay.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public MockRelay switchingOn() {
public State state() {
return state;
}

@Override
public String toString() {
return state().name();
}
}
5 changes: 5 additions & 0 deletions strongback-testing/src/org/strongback/mock/MockSolenoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public MockSolenoid stop() {
direction = Direction.STOPPED;
return this;
}

@Override
public String toString() {
return getDirection().name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public MockTemperatureSensor setTemperature(double temp) {
return this;
}

@Override
public String toString() {
return Double.toString(getTemperatureInFahrenheit()) + "\u00B0F";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public class MockThreeAxisAccelerometer extends MockTwoAxisAccelerometer impleme
public MockAccelerometer getZDirection() {
return z;
}

@Override
public String toString() {
return "" + getXDirection().getAcceleration() + ", " + getYDirection().getAcceleration() + ", " + getZDirection().getAcceleration() + " g/s\u00B2";
}
}
Loading