use of com.willwinder.universalgcodesender.model.events.ControllerStateEvent in project Universal-G-Code-Sender by winder.
the class ProgressBarPrinter method UGSEvent.
@Override
public void UGSEvent(UGSEvent event) {
if (event instanceof FileStateEvent) {
FileStateEvent fileStateEvent = (FileStateEvent) event;
if (fileStateEvent.getFileState() == FileState.FILE_LOADED) {
pb = new ProgressBarBuilder().setStyle(ProgressBarStyle.UNICODE_BLOCK).setInitialMax(100).setTaskName(backend.getGcodeFile().getName()).setPrintStream(System.out).build();
} else if (fileStateEvent.getFileState() == FileState.FILE_STREAM_COMPLETE) {
if (pb != null) {
pb.maxHint(backend.getNumRows());
pb.stepTo(backend.getNumCompletedRows());
pb.close();
pb = null;
}
}
} else if (event instanceof ControllerStateEvent && pb != null) {
ControllerStateEvent controllerStateEvent = (ControllerStateEvent) event;
if (controllerStateEvent.getState() == ControllerState.HOLD) {
pb.setExtraMessage("[PAUSED] 'ENTER' to resume");
} else {
pb.setExtraMessage("[" + controllerStateEvent.getState() + "]");
}
} else if (event instanceof CommandEvent) {
if (pb != null) {
pb.maxHint(backend.getNumRows());
pb.stepTo(backend.getNumCompletedRows());
}
}
}
use of com.willwinder.universalgcodesender.model.events.ControllerStateEvent in project Universal-G-Code-Sender by winder.
the class SendStatusPanel method UGSEvent.
@Override
public void UGSEvent(com.willwinder.universalgcodesender.model.UGSEvent evt) {
// Look for a send beginning.
if (evt instanceof ControllerStateEvent && ((ControllerStateEvent) evt).getState() == ControllerState.RUN) {
if (backend.isSendingFile()) {
beginSend();
}
} else // On file loaded event, reset the rows.
if (evt instanceof FileStateEvent) {
FileStateEvent fileStateEvent = (FileStateEvent) evt;
if (fileStateEvent.getFileState() == FILE_LOADED) {
resetSentRowLabels();
} else if (fileStateEvent.getFileState() == FILE_STREAM_COMPLETE) {
update();
endSend();
}
} else if (evt instanceof CommandEvent) {
CommandEvent commandEvent = ((CommandEvent) evt);
GcodeCommand command = commandEvent.getCommand();
if ((commandEvent.getCommandEventType() == CommandEventType.COMMAND_SENT || commandEvent.getCommandEventType() == CommandEventType.COMMAND_SKIPPED) && command.hasComment()) {
latestCommentValueLabel.setText(command.getComment());
}
}
}
use of com.willwinder.universalgcodesender.model.events.ControllerStateEvent in project Universal-G-Code-Sender by winder.
the class ProbeServiceTest method testProbeServiceXYZ.
@Test
public void testProbeServiceXYZ() throws Exception {
doReturn(true).when(backend).isIdle();
ProbeService ps = new ProbeService(backend);
ProbeParameters pc = new ProbeParameters(1, new Position(5, 5, 5, Units.MM), 10, 10, 0., 1, 1, 1, 100, 25, 5, Units.MM, G55);
ps.performXYZProbe(pc);
Position probeY = new Position(2.0, 2.0, 0, Units.MM);
Position probeX = new Position(1.0, 1.0, 0, Units.MM);
Position probeZ = new Position(0., 0., 3.0, Units.MM);
// Events to transition between states.
ps.UGSEvent(new ProbeEvent(probeZ));
ps.UGSEvent(new ProbeEvent(probeZ));
ps.UGSEvent(new ProbeEvent(probeX));
ps.UGSEvent(new ProbeEvent(probeX));
ps.UGSEvent(new ProbeEvent(probeY));
ps.UGSEvent(new ProbeEvent(probeY));
ps.UGSEvent(new ControllerStateEvent(ControllerState.IDLE, ControllerState.RUN));
InOrder order = inOrder(backend);
order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X0Y0Z0");
// Probe Z axis
order.verify(backend, times(1)).probe("Z", pc.feedRate, pc.zSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 Z" + retractDistance(pc.zSpacing, pc.retractAmount));
order.verify(backend, times(1)).probe("Z", pc.feedRateSlow, pc.zSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z0.0");
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + -pc.xSpacing);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z" + pc.zSpacing);
// probe X axis
order.verify(backend, times(1)).probe("X", pc.feedRate, pc.xSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 X" + retractDistance(pc.ySpacing, pc.retractAmount));
order.verify(backend, times(1)).probe("X", pc.feedRateSlow, pc.xSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + -pc.xSpacing);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y" + -pc.ySpacing);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + pc.xSpacing);
// probe Y axis
order.verify(backend, times(1)).probe("Y", pc.feedRate, pc.ySpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 Y" + retractDistance(pc.ySpacing, pc.retractAmount));
order.verify(backend, times(1)).probe("Y", pc.feedRateSlow, pc.ySpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z0.0");
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X0.0 Y0.0");
// Verify the correct offset
double radius = pc.probeDiameter / 2;
double xDir = ((pc.xSpacing > 0) ? -1 : 1);
double yDir = ((pc.ySpacing > 0) ? -1 : 1);
double xProbeOffset = pc.startPosition.x - probeX.x + xDir * (radius + Math.abs(pc.xOffset));
double yProbeOffset = pc.startPosition.y - probeY.y + yDir * (radius + Math.abs(pc.yOffset));
double zProbeOffset = pc.startPosition.z - probeZ.z;
order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X" + Utils.formatter.format(xProbeOffset) + "Y" + Utils.formatter.format(yProbeOffset) + "Z" + Utils.formatter.format(zProbeOffset));
}
use of com.willwinder.universalgcodesender.model.events.ControllerStateEvent in project Universal-G-Code-Sender by winder.
the class ProbeServiceTest method testProbeServiceOutside.
@Test
public void testProbeServiceOutside() throws Exception {
doReturn(true).when(backend).isIdle();
ProbeService ps = new ProbeService(backend);
ProbeParameters pc = new ProbeParameters(1, new Position(5, 5, 5, Units.MM), 10, 10, 0., 1, 1, 1, 100, 25, 5, Units.MM, G55);
ps.performOutsideCornerProbe(pc);
Position probeY = new Position(2.0, 2.0, 0, Units.MM);
Position probeX = new Position(1.0, 1.0, 0, Units.MM);
// Events to transition between states.
ps.UGSEvent(new ProbeEvent(probeY));
ps.UGSEvent(new ProbeEvent(probeY));
ps.UGSEvent(new ProbeEvent(probeX));
ps.UGSEvent(new ProbeEvent(probeX));
ps.UGSEvent(new ControllerStateEvent(ControllerState.IDLE, ControllerState.DISCONNECTED));
InOrder order = inOrder(backend);
order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X0Y0");
// probe Y axis
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + pc.xSpacing);
order.verify(backend, times(1)).probe("Y", pc.feedRate, pc.ySpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 Y" + retractDistance(pc.ySpacing, pc.retractAmount));
order.verify(backend, times(1)).probe("Y", pc.feedRateSlow, pc.ySpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y0.0");
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X0.0");
// probe X axis
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y" + pc.ySpacing);
order.verify(backend, times(1)).probe("X", pc.feedRate, pc.xSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 X" + retractDistance(pc.ySpacing, pc.retractAmount));
order.verify(backend, times(1)).probe("X", pc.feedRateSlow, pc.xSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X0.0");
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y0.0");
// Verify the correct offset
double radius = pc.probeDiameter / 2;
double xDir = ((pc.xSpacing > 0) ? -1 : 1);
double yDir = ((pc.ySpacing > 0) ? -1 : 1);
double xProbeOffset = pc.startPosition.x - probeX.x + xDir * (radius + Math.abs(pc.xOffset));
double yProbeOffset = pc.startPosition.y - probeY.y + yDir * (radius + Math.abs(pc.yOffset));
order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X" + Utils.formatter.format(xProbeOffset) + "Y" + Utils.formatter.format(yProbeOffset));
}
use of com.willwinder.universalgcodesender.model.events.ControllerStateEvent in project Universal-G-Code-Sender by winder.
the class ProbeServiceTest method testZProbe.
private void testZProbe(ProbeParameters pc) throws Exception {
ProbeService ps = new ProbeService(backend);
ps.performZProbe(pc);
Position probeZ = new Position(5, 5, 3, Units.MM);
ps.UGSEvent(new ProbeEvent(probeZ));
ps.UGSEvent(new ProbeEvent(probeZ));
ps.UGSEvent(new ControllerStateEvent(ControllerState.IDLE, ControllerState.RUN));
InOrder order = inOrder(backend);
order.verify(backend, times(1)).probe("Z", pc.feedRate, pc.zSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G20 G0 Z" + retractDistance(pc.zSpacing, pc.retractAmount));
order.verify(backend, times(1)).probe("Z", pc.feedRateSlow, pc.zSpacing, pc.units);
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G20 G0 Z0.0");
double zDir = Math.signum(pc.zSpacing) * -1;
double zProbedOffset = zDir * pc.zOffset;
Position startPositionInUnits = pc.startPosition.getPositionIn(pc.units);
double zPosition = startPositionInUnits.z - probeZ.getPositionIn(pc.units).z + zProbedOffset;
order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P1 Z" + Utils.formatter.format(zPosition));
}
Aggregations