Search in sources :

Example 11 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class MathUtils method getLowerLeftCorner.

public static Position getLowerLeftCorner(List<PartialPosition> points) {
    UnitUtils.Units units = points.get(0).getUnits();
    Position minPos = new Position(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_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()));
    }
    return new Position(minPos.getX(), minPos.getY(), minPos.getZ(), 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 12 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class MathUtilsTest method orientationWithPointsInCounterClockwiseOrder.

@Test
public void orientationWithPointsInCounterClockwiseOrder() {
    PartialPosition p1 = new PartialPosition(0d, 0d, UnitUtils.Units.MM);
    PartialPosition p2 = new PartialPosition(-1d, 1d, UnitUtils.Units.MM);
    PartialPosition p3 = new PartialPosition(-1d, 0d, UnitUtils.Units.MM);
    int orientation = MathUtils.orientation(p1, p2, p3);
    assertEquals(MathUtils.COUNTER_CLOCKWISE, orientation);
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Test(org.junit.Test)

Example 13 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class TinyGUtils method generateSetWorkPositionCommand.

/**
 * Generates a command for setting the axis to a position in the current coordinate system
 *
 * @param controllerStatus the current controller status
 * @param gcodeState       the current gcode state
 * @param positions        the position to set
 * @return a command for setting the position
 */
public static String generateSetWorkPositionCommand(ControllerStatus controllerStatus, GcodeState gcodeState, PartialPosition positions) {
    int offsetCode = WorkCoordinateSystem.fromGCode(gcodeState.offset).getPValue();
    UnitUtils.Units currentUnits = gcodeState.getUnits();
    Position machineCoord = controllerStatus.getMachineCoord().getPositionIn(currentUnits);
    PartialPosition.Builder offsets = PartialPosition.builder().setUnits(currentUnits);
    for (Map.Entry<Axis, Double> position : positions.getPositionIn(currentUnits).getAll().entrySet()) {
        double axisOffset = -(position.getValue() - machineCoord.get(position.getKey()));
        offsets.setValue(position.getKey(), axisOffset);
    }
    return "G10 L2 P" + offsetCode + " " + offsets.build().getFormattedGCode();
}
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) Map(java.util.Map) Axis(com.willwinder.universalgcodesender.model.Axis)

Example 14 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class JogService method adjustManualLocationABC.

/**
 * Adjusts the rotation axis location.
 * @param a direction.
 * @param b direction.
 * @param c direction.
 */
public void adjustManualLocationABC(int a, int b, int c) {
    try {
        double feedRate = getFeedRate();
        double stepSize = getStepSizeABC();
        Units preferredUnits = getUnits();
        Double da = a == 0 ? null : a * stepSize;
        Double db = b == 0 ? null : b * stepSize;
        Double dc = c == 0 ? null : c * stepSize;
        backend.adjustManualLocation(new PartialPosition(null, null, null, da, db, dc, preferredUnits), feedRate);
    } catch (Exception e) {
    // NotifyDescriptor nd = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
    // DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

Example 15 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class JogService method adjustManualLocationZ.

/**
 * Adjusts the Z axis location.
 * @param z direction.
 */
public void adjustManualLocationZ(int z) {
    try {
        double stepSize = getStepSizeZ();
        if (!useStepSizeZ()) {
            stepSize = getStepSizeXY();
        }
        double feedRate = getSettings().getJogFeedRate();
        Units preferredUnits = getSettings().getPreferredUnits();
        backend.adjustManualLocation(new PartialPosition(null, null, z * stepSize, preferredUnits), feedRate);
    } catch (Exception e) {
    // NotifyDescriptor nd = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
    // DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

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