All Downloads are FREE. Search and download functionalities are using the official Maven repository.

zaber.motion.ascii.Lockstep Maven / Gradle / Ivy

Go to download

A library that aims to provide easy-to-use API for communication with Zaber devices using Zaber ASCII Protocol.

There is a newer version: 6.7.0
Show newest version
// ===== THIS FILE IS GENERATED FROM A TEMPLATE ===== //
// ============== DO NOT EDIT DIRECTLY ============== //

package zaber.motion.ascii;

import zaber.motion.ArrayUtility;
import zaber.motion.Units;
import zaber.motion.protobufs.Main;
import zaber.motion.gateway.Call;
import zaber.motion.exceptions.MotionLibException;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * Represents a lockstep group with this ID on a device.
 * A lockstep group is a movement synchronized pair of axes on a device.
 */
public class Lockstep {
    private Device device;

    /**
     * @return Device that controls this lockstep group.
     */
    public Device getDevice() {
        return this.device;
    }

    private int lockstepGroupId;

    /**
     * @return The number that identifies the lockstep group on the device.
     */
    public int getLockstepGroupId() {
        return this.lockstepGroupId;
    }

    public Lockstep(
        Device device, int lockstepGroupId) {
        this.device = device;
        this.lockstepGroupId = lockstepGroupId;
    }

    /**
     * Activate the lockstep group on the axes specified.
     * @param axes The numbers of axes in the lockstep group.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture enableAsync(
        int... axes) {
        Main.LockstepEnableRequest.Builder builder = Main.LockstepEnableRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        builder = builder.addAllAxes(
            Arrays.asList(ArrayUtility.toObjectArray(axes))
        );
        return Call.callAsync("device/lockstep_enable", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Activate the lockstep group on the axes specified.
     * @param axes The numbers of axes in the lockstep group.
     */
    public void enable(
        int... axes) {
        try {
            enableAsync(axes).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Disable the lockstep group.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture disableAsync() {
        Main.LockstepDisableRequest.Builder builder = Main.LockstepDisableRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        return Call.callAsync("device/lockstep_disable", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Disable the lockstep group.
     */
    public void disable() {
        try {
            disableAsync().get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Stops ongoing lockstep group movement. Decelerates until zero speed.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture stopAsync(
        boolean waitUntilIdle) {
        Main.LockstepStopRequest.Builder builder = Main.LockstepStopRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        builder = builder.setWaitUntilIdle(waitUntilIdle);
        return Call.callAsync("device/lockstep_stop", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Stops ongoing lockstep group movement. Decelerates until zero speed.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture stopAsync() {
        return stopAsync(true);
    }

    /**
     * Stops ongoing lockstep group movement. Decelerates until zero speed.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     */
    public void stop(
        boolean waitUntilIdle) {
        try {
            stopAsync(waitUntilIdle).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Stops ongoing lockstep group movement. Decelerates until zero speed.
     */
    public void stop() {
        stop(true);
    }

    /**
     * Retracts the axes of the lockstep group until a home associated with an individual axis is detected.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture homeAsync(
        boolean waitUntilIdle) {
        Main.LockstepHomeRequest.Builder builder = Main.LockstepHomeRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        builder = builder.setWaitUntilIdle(waitUntilIdle);
        return Call.callAsync("device/lockstep_home", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Retracts the axes of the lockstep group until a home associated with an individual axis is detected.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture homeAsync() {
        return homeAsync(true);
    }

    /**
     * Retracts the axes of the lockstep group until a home associated with an individual axis is detected.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     */
    public void home(
        boolean waitUntilIdle) {
        try {
            homeAsync(waitUntilIdle).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Retracts the axes of the lockstep group until a home associated with an individual axis is detected.
     */
    public void home() {
        home(true);
    }

    /**
     * Move the first axis of the lockstep group to an absolute position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Absolute position.
     * @param unit Units of position.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveAbsoluteAsync(
        double position, Units unit, boolean waitUntilIdle) {
        Main.LockstepMoveRequest.Builder builder = Main.LockstepMoveRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());
        builder = builder.setType(Main.LockstepMoveRequest.MoveType.ABS);

        builder = builder.setArg(position);
        builder = builder.setUnit(unit.getName());
        builder = builder.setWaitUntilIdle(waitUntilIdle);
        return Call.callAsync("device/lockstep_move", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Move the first axis of the lockstep group to an absolute position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Absolute position.
     * @param unit Units of position.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveAbsoluteAsync(
        double position, Units unit) {
        return moveAbsoluteAsync(position, unit, true);
    }

    /**
     * Move the first axis of the lockstep group to an absolute position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Absolute position.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveAbsoluteAsync(
        double position) {
        return moveAbsoluteAsync(position, Units.NATIVE, true);
    }

    /**
     * Move the first axis of the lockstep group to an absolute position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Absolute position.
     * @param unit Units of position.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     */
    public void moveAbsolute(
        double position, Units unit, boolean waitUntilIdle) {
        try {
            moveAbsoluteAsync(position, unit, waitUntilIdle).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Move the first axis of the lockstep group to an absolute position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Absolute position.
     * @param unit Units of position.
     */
    public void moveAbsolute(
        double position, Units unit) {
        moveAbsolute(position, unit, true);
    }

    /**
     * Move the first axis of the lockstep group to an absolute position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Absolute position.
     */
    public void moveAbsolute(
        double position) {
        moveAbsolute(position, Units.NATIVE, true);
    }

    /**
     * Move the first axis of the lockstep group to a position relative to its current position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Relative position.
     * @param unit Units of position.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveRelativeAsync(
        double position, Units unit, boolean waitUntilIdle) {
        Main.LockstepMoveRequest.Builder builder = Main.LockstepMoveRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());
        builder = builder.setType(Main.LockstepMoveRequest.MoveType.REL);

        builder = builder.setArg(position);
        builder = builder.setUnit(unit.getName());
        builder = builder.setWaitUntilIdle(waitUntilIdle);
        return Call.callAsync("device/lockstep_move", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Move the first axis of the lockstep group to a position relative to its current position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Relative position.
     * @param unit Units of position.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveRelativeAsync(
        double position, Units unit) {
        return moveRelativeAsync(position, unit, true);
    }

    /**
     * Move the first axis of the lockstep group to a position relative to its current position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Relative position.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveRelativeAsync(
        double position) {
        return moveRelativeAsync(position, Units.NATIVE, true);
    }

    /**
     * Move the first axis of the lockstep group to a position relative to its current position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Relative position.
     * @param unit Units of position.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     */
    public void moveRelative(
        double position, Units unit, boolean waitUntilIdle) {
        try {
            moveRelativeAsync(position, unit, waitUntilIdle).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Move the first axis of the lockstep group to a position relative to its current position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Relative position.
     * @param unit Units of position.
     */
    public void moveRelative(
        double position, Units unit) {
        moveRelative(position, unit, true);
    }

    /**
     * Move the first axis of the lockstep group to a position relative to its current position.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param position Relative position.
     */
    public void moveRelative(
        double position) {
        moveRelative(position, Units.NATIVE, true);
    }

    /**
     * Moves the first axis of the lockstep group at the specified speed.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param velocity Movement velocity.
     * @param unit Units of velocity.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveVelocityAsync(
        double velocity, Units unit) {
        Main.LockstepMoveRequest.Builder builder = Main.LockstepMoveRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());
        builder = builder.setType(Main.LockstepMoveRequest.MoveType.VEL);

        builder = builder.setArg(velocity);
        builder = builder.setUnit(unit.getName());
        return Call.callAsync("device/lockstep_move", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Moves the first axis of the lockstep group at the specified speed.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param velocity Movement velocity.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveVelocityAsync(
        double velocity) {
        return moveVelocityAsync(velocity, Units.NATIVE);
    }

    /**
     * Moves the first axis of the lockstep group at the specified speed.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param velocity Movement velocity.
     * @param unit Units of velocity.
     */
    public void moveVelocity(
        double velocity, Units unit) {
        try {
            moveVelocityAsync(velocity, unit).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Moves the first axis of the lockstep group at the specified speed.
     * The other axes in the lockstep group maintain their offsets throughout movement.
     * @param velocity Movement velocity.
     */
    public void moveVelocity(
        double velocity) {
        moveVelocity(velocity, Units.NATIVE);
    }

    /**
     * Moves the axes to the maximum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.max for all axes in the group.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveMaxAsync(
        boolean waitUntilIdle) {
        Main.LockstepMoveRequest.Builder builder = Main.LockstepMoveRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());
        builder = builder.setType(Main.LockstepMoveRequest.MoveType.MAX);

        builder = builder.setWaitUntilIdle(waitUntilIdle);
        return Call.callAsync("device/lockstep_move", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Moves the axes to the maximum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.max for all axes in the group.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveMaxAsync() {
        return moveMaxAsync(true);
    }

    /**
     * Moves the axes to the maximum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.max for all axes in the group.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     */
    public void moveMax(
        boolean waitUntilIdle) {
        try {
            moveMaxAsync(waitUntilIdle).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Moves the axes to the maximum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.max for all axes in the group.
     */
    public void moveMax() {
        moveMax(true);
    }

    /**
     * Moves the axes to the minimum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.min for all axes in the group.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveMinAsync(
        boolean waitUntilIdle) {
        Main.LockstepMoveRequest.Builder builder = Main.LockstepMoveRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());
        builder = builder.setType(Main.LockstepMoveRequest.MoveType.MIN);

        builder = builder.setWaitUntilIdle(waitUntilIdle);
        return Call.callAsync("device/lockstep_move", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Moves the axes to the minimum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.min for all axes in the group.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture moveMinAsync() {
        return moveMinAsync(true);
    }

    /**
     * Moves the axes to the minimum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.min for all axes in the group.
     * @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
     */
    public void moveMin(
        boolean waitUntilIdle) {
        try {
            moveMinAsync(waitUntilIdle).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Moves the axes to the minimum valid position.
     * The axes in the lockstep group maintain their offsets throughout movement.
     * Respects lim.min for all axes in the group.
     */
    public void moveMin() {
        moveMin(true);
    }

    /**
     * Waits until the lockstep group stops moving.
     * @param throwErrorOnFault Determines whether to throw error when fault is observed.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture waitUntilIdleAsync(
        boolean throwErrorOnFault) {
        Main.LockstepWaitUntilIdleRequest.Builder builder = Main.LockstepWaitUntilIdleRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        builder = builder.setThrowErrorOnFault(throwErrorOnFault);
        return Call.callAsync("device/lockstep_wait_until_idle", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Waits until the lockstep group stops moving.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture waitUntilIdleAsync() {
        return waitUntilIdleAsync(true);
    }

    /**
     * Waits until the lockstep group stops moving.
     * @param throwErrorOnFault Determines whether to throw error when fault is observed.
     */
    public void waitUntilIdle(
        boolean throwErrorOnFault) {
        try {
            waitUntilIdleAsync(throwErrorOnFault).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Waits until the lockstep group stops moving.
     */
    public void waitUntilIdle() {
        waitUntilIdle(true);
    }

    /**
     * Returns bool indicating whether the lockstep group is executing a motion command.
     * @return A CompletableFuture that can be completed to get the result:
     * True if the axes are currently executing a motion command.
     */
    public CompletableFuture isBusyAsync() {
        Main.LockstepIsBusyRequest.Builder builder = Main.LockstepIsBusyRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        CompletableFuture response = Call.callAsync(
            "device/lockstep_is_busy",
            builder.build(),
            Main.LockstepIsBusyResponse.parser());
        return response
            .thenApply(r -> r.getIsBusy());
    }

    /**
     * Returns bool indicating whether the lockstep group is executing a motion command.
     * @return True if the axes are currently executing a motion command.
     */
    public boolean isBusy() {
        try {
            return isBusyAsync().get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * @deprecated Use GetAxisNumbers instead.
     *
     * Gets the axes of the lockstep group.
     * @return A CompletableFuture that can be completed to get the result:
     * LockstepAxes instance which contains the axes numbers of the lockstep group.
     */
    @Deprecated
    public CompletableFuture getAxesAsync() {
        Main.LockstepGetAxesRequest.Builder builder = Main.LockstepGetAxesRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        CompletableFuture response = Call.callAsync(
            "device/lockstep_get_axes",
            builder.build(),
            Main.LockstepGetAxesResponse.parser());
        return response
            .thenApply(r -> LockstepAxes.fromProtobuf(r.getAxes()));
    }

    /**
     * @deprecated Use GetAxisNumbers instead.
     *
     * Gets the axes of the lockstep group.
     * @return LockstepAxes instance which contains the axes numbers of the lockstep group.
     */
    public LockstepAxes getAxes() {
        try {
            return getAxesAsync().get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Gets the axis numbers of the lockstep group.
     * @return A CompletableFuture that can be completed to get the result:
     * Axis numbers in order specified when enabling lockstep.
     */
    public CompletableFuture getAxisNumbersAsync() {
        Main.LockstepGetAxisNumbersRequest.Builder builder = Main.LockstepGetAxisNumbersRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        CompletableFuture response = Call.callAsync(
            "device/lockstep_get_axis_numbers",
            builder.build(),
            Main.LockstepGetAxisNumbersResponse.parser());
        return response
            .thenApply(r -> ArrayUtility.toPrimitiveArray(r.getAxesList().stream().toArray(Integer[]::new)));
    }

    /**
     * Gets the axis numbers of the lockstep group.
     * @return Axis numbers in order specified when enabling lockstep.
     */
    public int[] getAxisNumbers() {
        try {
            return getAxisNumbersAsync().get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Gets the initial offsets of secondary axes of an enabled lockstep group.
     * @param unit Units of position.
     * @return A CompletableFuture that can be completed to get the result:
     * Initial offset for each axis of the lockstep group.
     */
    public CompletableFuture getOffsetsAsync(
        Units unit) {
        Main.LockstepGetOffsetsRequest.Builder builder = Main.LockstepGetOffsetsRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        builder = builder.setUnit(unit.getName());
        CompletableFuture response = Call.callAsync(
            "device/lockstep_get_offsets",
            builder.build(),
            Main.LockstepGetOffsetsResponse.parser());
        return response
            .thenApply(r -> ArrayUtility.toPrimitiveArray(r.getOffsetsList().stream().toArray(Double[]::new)));
    }

    /**
     * Gets the initial offsets of secondary axes of an enabled lockstep group.
     * @return A CompletableFuture that can be completed to get the result:
     * Initial offset for each axis of the lockstep group.
     */
    public CompletableFuture getOffsetsAsync() {
        return getOffsetsAsync(Units.NATIVE);
    }

    /**
     * Gets the initial offsets of secondary axes of an enabled lockstep group.
     * @param unit Units of position.
     * @return Initial offset for each axis of the lockstep group.
     */
    public double[] getOffsets(
        Units unit) {
        try {
            return getOffsetsAsync(unit).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Gets the initial offsets of secondary axes of an enabled lockstep group.
     * @return Initial offset for each axis of the lockstep group.
     */
    public double[] getOffsets() {
        return getOffsets(Units.NATIVE);
    }

    /**
     * Gets the twists of secondary axes of an enabled lockstep group.
     * @param unit Units of position.
     * @return A CompletableFuture that can be completed to get the result:
     * Difference between the initial offset and the actual offset for each axis of the lockstep group.
     */
    public CompletableFuture getTwistsAsync(
        Units unit) {
        Main.LockstepGetTwistsRequest.Builder builder = Main.LockstepGetTwistsRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        builder = builder.setUnit(unit.getName());
        CompletableFuture response = Call.callAsync(
            "device/lockstep_get_twists",
            builder.build(),
            Main.LockstepGetTwistsResponse.parser());
        return response
            .thenApply(r -> ArrayUtility.toPrimitiveArray(r.getTwistsList().stream().toArray(Double[]::new)));
    }

    /**
     * Gets the twists of secondary axes of an enabled lockstep group.
     * @return A CompletableFuture that can be completed to get the result:
     * Difference between the initial offset and the actual offset for each axis of the lockstep group.
     */
    public CompletableFuture getTwistsAsync() {
        return getTwistsAsync(Units.NATIVE);
    }

    /**
     * Gets the twists of secondary axes of an enabled lockstep group.
     * @param unit Units of position.
     * @return Difference between the initial offset and the actual offset for each axis of the lockstep group.
     */
    public double[] getTwists(
        Units unit) {
        try {
            return getTwistsAsync(unit).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Gets the twists of secondary axes of an enabled lockstep group.
     * @return Difference between the initial offset and the actual offset for each axis of the lockstep group.
     */
    public double[] getTwists() {
        return getTwists(Units.NATIVE);
    }

    /**
     * Checks if the lockstep group is currently enabled on the device.
     * @return A CompletableFuture that can be completed to get the result:
     * True if a lockstep group with this ID is enabled on the device.
     */
    public CompletableFuture isEnabledAsync() {
        Main.LockstepIsEnabledRequest.Builder builder = Main.LockstepIsEnabledRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        CompletableFuture response = Call.callAsync(
            "device/lockstep_is_enabled",
            builder.build(),
            Main.LockstepIsEnabledResponse.parser());
        return response
            .thenApply(r -> r.getIsEnabled());
    }

    /**
     * Checks if the lockstep group is currently enabled on the device.
     * @return True if a lockstep group with this ID is enabled on the device.
     */
    public boolean isEnabled() {
        try {
            return isEnabledAsync().get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof MotionLibException) {
                throw (MotionLibException) e.getCause();
            } else {
                throw new MotionLibException(e.getCause());
            }
        } catch (InterruptedException e) {
            throw new MotionLibException(e);
        }
    }

    /**
     * Returns a string which represents the enabled lockstep group.
     * @return String which represents the enabled lockstep group.
     */
    public String toString() {
        Main.LockstepToStringRequest.Builder builder = Main.LockstepToStringRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setLockstepGroupId(getLockstepGroupId());

        Main.LockstepToStringResponse response = Call.callSync(
            "device/lockstep_to_string",
            builder.build(),
            Main.LockstepToStringResponse.parser());
        return response.getToStr();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy