use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class G2CoreControllerTest method jogMachineShouldTurnBackToIdleWhenDone.
@Test
public void jogMachineShouldTurnBackToIdleWhenDone() throws Exception {
// Given
when(communicator.isConnected()).thenReturn(true);
controller.jogMachine(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 1000d);
// receive IDLE
controller.rawResponseHandler("{\"sr\":{\"stat\": 1}}");
// Then
assertEquals(ControllerState.IDLE, controller.getControllerStatus().getState());
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class G2CoreControllerTest method jogMachineShouldEmulateRunStateAsJog.
@Test
public void jogMachineShouldEmulateRunStateAsJog() throws Exception {
// Given
when(communicator.isConnected()).thenReturn(true);
controller.jogMachine(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 1000d);
// When
// receive RUN
controller.rawResponseHandler("{\"sr\":{\"stat\": 5}}");
// Then
assertEquals(ControllerState.JOG, controller.getControllerStatus().getState());
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class MathUtils method getCenter.
/**
* Gets the center position given a list of line segments.
*
* @param points a list of points
* @return a new position in the center of the given points
*/
public static Position getCenter(List<PartialPosition> points) {
UnitUtils.Units units = points.get(0).getUnits();
Position minPos = new Position(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE, units);
Position maxPos = new Position(Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE, units);
for (PartialPosition point : points) {
PartialPosition positionInUnits = point.getPositionIn(units);
minPos.setX(Math.min(minPos.getX(), positionInUnits.getX()));
minPos.setY(Math.min(minPos.getY(), positionInUnits.getY()));
minPos.setZ(Math.min(minPos.getZ(), positionInUnits.getZ()));
maxPos.setX(Math.max(maxPos.getX(), positionInUnits.getX()));
maxPos.setY(Math.max(maxPos.getY(), positionInUnits.getY()));
maxPos.setZ(Math.max(maxPos.getZ(), positionInUnits.getZ()));
}
return new Position(minPos.getX() + ((maxPos.getX() - minPos.getX()) / 2), minPos.getY() + ((maxPos.getY() - minPos.getY()) / 2), minPos.getZ() + ((maxPos.getZ() - minPos.getZ()) / 2), units);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class TinyGControllerTest method jogMachineTo.
@Test
public void jogMachineTo() throws Exception {
// Given
when(communicator.isConnected()).thenReturn(true);
// Simulate that the machine is running in mm
controller.getCurrentGcodeState().units = Code.G21;
// When
InOrder orderVerifier = inOrder(communicator);
controller.jogMachineTo(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 1000);
// Then
orderVerifier.verify(communicator, times(1)).queueCommand(any(GcodeCommand.class));
orderVerifier.verify(communicator).streamCommands();
GcodeCommand command = queueCommandArgumentCaptor.getAllValues().get(0);
assertEquals("G21G90G1X1Y2Z3F1000", command.getCommandString());
assertTrue(command.isGenerated());
assertTrue(command.isTemporaryParserModalChange());
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class TinyGControllerTest method jogMachineWhenUsingInchesShouldConvertCoordinates.
@Test
public void jogMachineWhenUsingInchesShouldConvertCoordinates() throws Exception {
// Given
when(communicator.isConnected()).thenReturn(true);
// Simulate that the machine is running in inches
controller.getCurrentGcodeState().units = Code.G20;
// When
InOrder orderVerifier = inOrder(communicator);
controller.jogMachine(new PartialPosition(100., 100., 100., UnitUtils.Units.MM), 1000);
// Then
orderVerifier.verify(communicator, times(1)).queueCommand(any(GcodeCommand.class));
orderVerifier.verify(communicator).streamCommands();
GcodeCommand command = queueCommandArgumentCaptor.getAllValues().get(0);
assertEquals("G20G91G1X3.937Y3.937Z3.937F39.37", command.getCommandString());
assertTrue(command.isGenerated());
assertTrue(command.isTemporaryParserModalChange());
}
Aggregations