diff options
author | smcauliffe <smcauliffe> | 2006-05-09 11:43:41 +0000 |
---|---|---|
committer | smcauliffe <smcauliffe@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2006-05-09 11:43:41 +0000 |
commit | 9f249b5cf022ef9a89b61f909235a69719e7f7b1 (patch) | |
tree | 9c3608eb5367598e37a2eed3508037727bff47d1 | |
parent | c33236912cc1f8a0791e9a020bd0f038b9777cfe (diff) | |
download | reprap-9f249b5cf022ef9a89b61f909235a69719e7f7b1.tar.gz reprap-9f249b5cf022ef9a89b61f909235a69719e7f7b1.zip |
Progress commit on testing for repraps
git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap@296 cb376a5e-1013-0410-a455-b6b1f9ac8223
12 files changed, 276 insertions, 19 deletions
diff --git a/branches/sm-unittesting/.settings/org.eclipse.jdt.core.prefs b/branches/sm-unittesting/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..8d011bae --- /dev/null +++ b/branches/sm-unittesting/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,47 @@ +#Tue May 09 22:56:59 NZST 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
diff --git a/branches/sm-unittesting/Reprap_Custom_suite_c9d431a9.xml b/branches/sm-unittesting/Reprap_Custom_suite_c9d431a9.xml new file mode 100644 index 00000000..ffaebbed --- /dev/null +++ b/branches/sm-unittesting/Reprap_Custom_suite_c9d431a9.xml @@ -0,0 +1,14 @@ +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> +<suite name="Custom suite"> + <test verbose="2" name="Reprap" annotations="javadoc"> + <groups> + <run> + <include name="all"/> + </run> + </groups> + <classes> + <class name="org.reprap.geometry.polygons.PolygonTest"/> + <class name="org.reprap.machines.ReprapTest"/> + </classes> + </test> +</suite> diff --git a/branches/sm-unittesting/src/org/reprap/Main.java b/branches/sm-unittesting/src/org/reprap/Main.java index 0b718f7f..ca383704 100644 --- a/branches/sm-unittesting/src/org/reprap/Main.java +++ b/branches/sm-unittesting/src/org/reprap/Main.java @@ -312,10 +312,13 @@ public class Main { Producer producer = new Producer(preview, builder); producer.produce(); + double moved = producer.getTotalDistanceMoved(); + double extruded = producer.getTotalDistanceExtruded(); producer.dispose(); cancelMenuItem.setEnabled(false); produceProduce.setEnabled(true); - JOptionPane.showMessageDialog(mainFrame, "Production complete"); + JOptionPane.showMessageDialog(mainFrame, "Production complete. Total distance travelled=" + + moved + ". Total distance extruded=" + extruded); } catch (Exception ex) { JOptionPane.showMessageDialog(mainFrame, "Production exception: " + ex); diff --git a/branches/sm-unittesting/src/org/reprap/Printer.java b/branches/sm-unittesting/src/org/reprap/Printer.java index b0e8f769..ec3ffa8b 100644 --- a/branches/sm-unittesting/src/org/reprap/Printer.java +++ b/branches/sm-unittesting/src/org/reprap/Printer.java @@ -38,4 +38,16 @@ public interface Printer { public double getX(); public double getY(); public double getZ(); + + /** + * Get the total distance moved (whether extruding or not) + * @return a double representing the distance travelled (mm) + */ + public double getTotalDistanceMoved(); + + /** + * Get the total distance moved while extruding + * @return a double representing the distance travelled (mm) + */ + public double getTotalDistanceExtruded(); } diff --git a/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java b/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java index 34e19e13..6375878c 100644 --- a/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java +++ b/branches/sm-unittesting/src/org/reprap/comms/port/TestPort.java @@ -1,8 +1,12 @@ package org.reprap.comms.port;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
import java.util.HashMap;
import org.reprap.Device;
@@ -11,17 +15,43 @@ import org.reprap.comms.snap.SNAPAddress; public class TestPort implements Port {
private HashMap deviceMap;
+ private PipedOutputStream out;
+ private PipedInputStream in;
- public TestPort() {
+ private TestPortHandler handler;
+ private Thread handlerThread;
+
+
+ public TestPort() throws IOException {
deviceMap = new HashMap();
+ out = new PipedOutputStream();
+ in = new PipedInputStream();
+
+ PipedInputStream farsideInput = new PipedInputStream();
+ PipedOutputStream farsideOutput = new PipedOutputStream();
+ out.connect(farsideInput);
+ in.connect(farsideOutput);
+
+ handler = new TestPortHandler(farsideInput, farsideOutput);
+
+ handlerThread = new Thread() {
+ public void run() {
+ handler.watch();
+ }
+ };
+ handlerThread.start();
+
+ }
+
+ public void dispose() {
}
public OutputStream getOutputStream() throws IOException {
- return System.out;
+ return out;
}
public InputStream getInputStream() throws IOException {
- return System.in;
+ return in;
}
public void close() {
diff --git a/branches/sm-unittesting/src/org/reprap/comms/port/TestPortHandler.java b/branches/sm-unittesting/src/org/reprap/comms/port/TestPortHandler.java new file mode 100644 index 00000000..243b2b22 --- /dev/null +++ b/branches/sm-unittesting/src/org/reprap/comms/port/TestPortHandler.java @@ -0,0 +1,41 @@ +package org.reprap.comms.port;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+import org.reprap.comms.snap.SNAPPacket;
+
+public class TestPortHandler {
+
+ PipedInputStream in;
+ PipedOutputStream out;
+
+ public TestPortHandler(PipedInputStream in, PipedOutputStream out) {
+ this.in = in;
+ this.out = out;
+ }
+
+ public void watch() {
+ SNAPPacket packet = new SNAPPacket();
+ for(;;) {
+ try {
+ int data = in.read();
+ if (packet.receiveByte((byte)data)) {
+ // Process a packet and prepare for a new one
+ processPacket(packet);
+ packet = new SNAPPacket();
+ }
+ } catch(Exception ex) {
+ System.out.println("PIC side simulator exception: " + ex);
+ }
+ }
+ }
+
+ private void processPacket(SNAPPacket packet) {
+ System.out.println("Packet received from " + packet.getSourceAddress() +
+ " to " + packet.getDestinationAddress());
+
+ }
+
+}
diff --git a/branches/sm-unittesting/src/org/reprap/comms/snap/SNAPPacket.java b/branches/sm-unittesting/src/org/reprap/comms/snap/SNAPPacket.java index 7cf2815f..034135c7 100755 --- a/branches/sm-unittesting/src/org/reprap/comms/snap/SNAPPacket.java +++ b/branches/sm-unittesting/src/org/reprap/comms/snap/SNAPPacket.java @@ -22,11 +22,11 @@ public class SNAPPacket { private boolean complete = false; - SNAPPacket() { + public SNAPPacket() { buffer = new byte[maxSize]; } - SNAPPacket(SNAPAddress srcAddress, SNAPAddress destAddress, byte [] payload) { + public SNAPPacket(SNAPAddress srcAddress, SNAPAddress destAddress, byte [] payload) { buffer = new byte[payload.length + offset_payload + 1]; buffer[offset_sync] = syncMarker; buffer[offset_hdb2] = 0x51; diff --git a/branches/sm-unittesting/src/org/reprap/geometry/Producer.java b/branches/sm-unittesting/src/org/reprap/geometry/Producer.java index 8b6d4cff..6509722f 100644 --- a/branches/sm-unittesting/src/org/reprap/geometry/Producer.java +++ b/branches/sm-unittesting/src/org/reprap/geometry/Producer.java @@ -87,6 +87,15 @@ public class Producer { reprap.terminate(); } + + public double getTotalDistanceMoved() { + return reprap.getTotalDistanceMoved(); + } + + public double getTotalDistanceExtruded() { + return reprap.getTotalDistanceExtruded(); + } + public void dispose() { reprap.dispose(); diff --git a/branches/sm-unittesting/src/org/reprap/machines/MachineFactory.java b/branches/sm-unittesting/src/org/reprap/machines/MachineFactory.java index 1b267f63..ba153d41 100644 --- a/branches/sm-unittesting/src/org/reprap/machines/MachineFactory.java +++ b/branches/sm-unittesting/src/org/reprap/machines/MachineFactory.java @@ -5,6 +5,9 @@ import java.util.Properties; import org.reprap.Printer; import org.reprap.ReprapException; +import org.reprap.comms.port.Port; +import org.reprap.comms.port.SerialPort; +import org.reprap.comms.port.TestPort; /** * @@ -13,6 +16,8 @@ import org.reprap.ReprapException; */ public class MachineFactory { + private static final int defaultBaudRate = 19200; ///< Default baud rate if none is specified + private MachineFactory() { } @@ -22,9 +27,21 @@ public class MachineFactory { // appropriate type based on the local configuration. String geometry = props.getProperty("Geometry"); + + String portType = props.getProperty("PortType"); + Port port; + if (portType == null || portType == "serial") { + String commPortName = props.getProperty("Port"); + int baudRate = defaultBaudRate; + if (props.containsKey("BaudRate")) + baudRate = Integer.parseInt(props.getProperty("BaudRate")); + port = new SerialPort(commPortName, baudRate); + } else if (portType == "test") { + port = new TestPort(); + } else throw new Exception("Unknown port type " + portType); if (geometry.compareToIgnoreCase("cartesian") == 0) - return new Reprap(props); + return new Reprap(props, port); else if (geometry.compareToIgnoreCase("nullcartesian") == 0) return new NullCartesianMachine(props); else diff --git a/branches/sm-unittesting/src/org/reprap/machines/NullCartesianMachine.java b/branches/sm-unittesting/src/org/reprap/machines/NullCartesianMachine.java index 08ff15dc..1a294e72 100644 --- a/branches/sm-unittesting/src/org/reprap/machines/NullCartesianMachine.java +++ b/branches/sm-unittesting/src/org/reprap/machines/NullCartesianMachine.java @@ -8,9 +8,12 @@ import org.reprap.ReprapException; import org.reprap.gui.Previewer; public class NullCartesianMachine implements CartesianPrinter { - + private Previewer previewer = null; + double totalDistanceMoved = 0.0; + double totalDistanceExtruded = 0.0; + double currentX, currentY, currentZ; public NullCartesianMachine(Properties config) { @@ -30,6 +33,10 @@ public class NullCartesianMachine implements CartesianPrinter { public void moveTo(double x, double y, double z) throws ReprapException, IOException { if (isCancelled()) return; + totalDistanceMoved += segmentLength(x - currentX, y - currentY); + if (z != currentZ) + totalDistanceMoved += Math.abs(currentZ - z); + currentX = x; currentY = y; currentZ = z; @@ -40,6 +47,12 @@ public class NullCartesianMachine implements CartesianPrinter { previewer.addSegment(currentX, currentY, currentZ, x, y, z); if (isCancelled()) return; + double distance = segmentLength(x - currentX, y - currentY); + if (z != currentZ) + distance += Math.abs(currentZ - z); + totalDistanceExtruded += distance; + totalDistanceMoved += distance; + currentX = x; currentY = y; currentZ = z; @@ -79,11 +92,14 @@ public class NullCartesianMachine implements CartesianPrinter { } public boolean isCancelled() { - return previewer.isCancelled(); + if (previewer != null) + return previewer.isCancelled(); + return false; } public void initialise() { - previewer.reset(); + if (previewer != null) + previewer.reset(); } public double getX() { @@ -98,4 +114,21 @@ public class NullCartesianMachine implements CartesianPrinter { return currentZ; } + /* (non-Javadoc) + * @see org.reprap.Printer#getTotalDistanceMoved() + */ + public double getTotalDistanceMoved() { + return totalDistanceMoved; + } + + /* (non-Javadoc) + * @see org.reprap.Printer#getTotalDistanceExtruded() + */ + public double getTotalDistanceExtruded() { + return totalDistanceExtruded; + } + + public double segmentLength(double x, double y) { + return Math.sqrt(x*x + y*y); + } } diff --git a/branches/sm-unittesting/src/org/reprap/machines/Reprap.java b/branches/sm-unittesting/src/org/reprap/machines/Reprap.java index 3a6abe46..79d36a7e 100644 --- a/branches/sm-unittesting/src/org/reprap/machines/Reprap.java +++ b/branches/sm-unittesting/src/org/reprap/machines/Reprap.java @@ -7,7 +7,6 @@ import org.reprap.CartesianPrinter; import org.reprap.ReprapException; import org.reprap.comms.Communicator; import org.reprap.comms.port.Port; -import org.reprap.comms.port.SerialPort; import org.reprap.comms.snap.SNAPAddress; import org.reprap.comms.snap.SNAPCommunicator; import org.reprap.devices.GenericExtruder; @@ -23,7 +22,6 @@ import org.reprap.gui.Previewer; */ public class Reprap implements CartesianPrinter { private final int localNodeNumber = 0; - private final int baudRate = 19200; private Communicator communicator; private Previewer previewer = null; @@ -32,6 +30,9 @@ public class Reprap implements CartesianPrinter { private GenericStepperMotor motorY; private GenericStepperMotor motorZ; + double totalDistanceMoved = 0.0; + double totalDistanceExtruded = 0.0; + private LinePrinter layer; double scaleX, scaleY, scaleZ; @@ -45,7 +46,7 @@ public class Reprap implements CartesianPrinter { final boolean dummyZ = true; ///< Don't perform Z operations. Should be removed later. - public Reprap(Properties config) throws Exception { + public Reprap(Properties config, Port port) throws Exception { int axes = Integer.parseInt(config.getProperty("AxisCount")); if (axes != 3) throw new Exception("A Reprap printer must contain 3 axes"); @@ -53,10 +54,7 @@ public class Reprap implements CartesianPrinter { if (extruders < 1) throw new Exception("A Reprap printer must contain at least one extruder"); - String commPortName = config.getProperty("Port"); - SNAPAddress myAddress = new SNAPAddress(localNodeNumber); - Port port = new SerialPort(commPortName, baudRate); communicator = new SNAPCommunicator(port, myAddress); motorX = new GenericStepperMotor(communicator, @@ -99,10 +97,16 @@ public class Reprap implements CartesianPrinter { if (isCancelled()) return; layer.moveTo(convertToStepX(x), convertToStepY(y), speed); + totalDistanceMoved += segmentLength(x - currentX, y - currentY); + if (z != currentZ) { + totalDistanceMoved += Math.abs(currentZ - z); if (!dummyZ) motorZ.seekBlocking(speed, convertToStepZ(z)); currentZ = z; } + currentX = x; + currentY = y; + currentZ = z; } public void printTo(double x, double y, double z) throws ReprapException, IOException { @@ -127,6 +131,9 @@ public class Reprap implements CartesianPrinter { // Print a simple vertical extrusion // TODO extrusion speed should be based on actual head speed // which depends on the angle of the line + double distance = Math.abs(currentZ - z); + totalDistanceExtruded += distance; + totalDistanceMoved += distance; extruder.setExtrusion(speedExtruder); if (!dummyZ) motorZ.seekBlocking(speed, convertToStepZ(z)); extruder.setExtrusion(0); @@ -135,7 +142,12 @@ public class Reprap implements CartesianPrinter { } // Otherwise printing only in X/Y plane + double distance = segmentLength(x - currentX, y - currentY); + totalDistanceExtruded += distance; + totalDistanceMoved += distance; layer.printTo(convertToStepX(x), convertToStepY(y), speed, speedExtruder); + currentX = x; + currentY = y; } public void selectMaterial(int materialIndex) { @@ -278,6 +290,24 @@ public class Reprap implements CartesianPrinter { public double getZ() { return currentZ; } + + /* (non-Javadoc) + * @see org.reprap.Printer#getTotalDistanceMoved() + */ + public double getTotalDistanceMoved() { + return totalDistanceMoved; + } + + /* (non-Javadoc) + * @see org.reprap.Printer#getTotalDistanceExtruded() + */ + public double getTotalDistanceExtruded() { + return totalDistanceExtruded; + } + + public double segmentLength(double x, double y) { + return Math.sqrt(x*x + y*y); + } } diff --git a/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java b/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java index 9fa0125a..5dc08d8c 100644 --- a/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java +++ b/branches/sm-unittesting/src/org/reprap/machines/ReprapTest.java @@ -5,6 +5,11 @@ import java.util.Properties; import org.reprap.Printer;
import org.testng.Assert;
+/**
+ *
+ * @testng.configuration groups = "comms,all,all-offline"
+ *
+ */
public class ReprapTest {
private Printer printer;
@@ -12,9 +17,22 @@ public class ReprapTest { * @testng.configuration beforeSuite = "true"
*/
public void setUp() throws Exception {
+ // Set up a configuration for testing
Properties props = new Properties();
+ props.setProperty("PortType", "test"); // Don't use a real port!
props.setProperty("Geometry", "cartesian");
- printer = MachineFactory.create();
+ props.setProperty("AxisCount", "3");
+ props.setProperty("ExtruderCount", "1");
+ props.setProperty("Axis1Address", "2");
+ props.setProperty("Axis2Address", "3");
+ props.setProperty("Axis3Address", "4");
+ props.setProperty("Axis1Torque", "100");
+ props.setProperty("Axis2Torque", "100");
+ props.setProperty("Axis3Torque", "100");
+ props.setProperty("Extruder1Address", "8");
+ props.setProperty("Extruder1Beta", "5000");
+ props.setProperty("Extruder1Rz", "100000");
+ printer = MachineFactory.create(props);
}
/**
@@ -23,11 +41,14 @@ public class ReprapTest { public void tearDown() {
printer.dispose();
}
-
+
/**
* @testng.test groups = "comms,all,all-offline"
*/
- public void testBasic() {
+ public void testReprapBasic() throws Exception {
+ printer.moveTo(0, 0, 0);
+ printer.moveTo(10, 10, 0);
+ Assert.assertEquals(printer.getX(), 10.0, 0.001);
}
}
|