Search in sources :

Example 21 with PartialPosition

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());
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Test(org.junit.Test)

Example 22 with PartialPosition

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());
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Test(org.junit.Test)

Example 23 with PartialPosition

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);
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) Position(com.willwinder.universalgcodesender.model.Position) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition)

Example 24 with PartialPosition

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());
}
Also used : InOrder(org.mockito.InOrder) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test)

Example 25 with PartialPosition

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());
}
Also used : InOrder(org.mockito.InOrder) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test)

Aggregations

PartialPosition (com.willwinder.universalgcodesender.model.PartialPosition)36 Test (org.junit.Test)19 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)10 List (java.util.List)8 InOrder (org.mockito.InOrder)8 Position (com.willwinder.universalgcodesender.model.Position)7 Collectors (java.util.stream.Collectors)6 CentralLookup (com.willwinder.ugs.nbp.lib.lookup.CentralLookup)4 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)4 UGSEventListener (com.willwinder.universalgcodesender.listeners.UGSEventListener)4 BackendAPI (com.willwinder.universalgcodesender.model.BackendAPI)4 UGSEvent (com.willwinder.universalgcodesender.model.UGSEvent)4 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)4 ControllerStateEvent (com.willwinder.universalgcodesender.model.events.ControllerStateEvent)4 FileStateEvent (com.willwinder.universalgcodesender.model.events.FileStateEvent)4 LoaderDialogHelper (com.willwinder.universalgcodesender.uielements.helpers.LoaderDialogHelper)4 com.willwinder.universalgcodesender.utils (com.willwinder.universalgcodesender.utils)4 GcodeViewParse (com.willwinder.universalgcodesender.visualizer.GcodeViewParse)4 LineSegment (com.willwinder.universalgcodesender.visualizer.LineSegment)4 VisualizerUtils (com.willwinder.universalgcodesender.visualizer.VisualizerUtils)4