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

zaber.motion.ascii.AllAxes 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.protobufs.Main;
import zaber.motion.gateway.Call;
import zaber.motion.exceptions.MotionLibException;

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

/**
 * Represents all axes of motion associated with a device.
 */
public class AllAxes {
    private Device device;

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

    public AllAxes(
        Device device) {
        this.device = device;
    }

    /**
     * Homes all axes. Axes return to their homing positions.
     * @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.DeviceHomeRequest.Builder builder = Main.DeviceHomeRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setAxis(0);

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

    /**
     * Homes all axes. Axes return to their homing positions.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture homeAsync() {
        return homeAsync(true);
    }

    /**
     * Homes all axes. Axes return to their homing positions.
     * @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);
        }
    }

    /**
     * Homes all axes. Axes return to their homing positions.
     */
    public void home() {
        home(true);
    }

    /**
     * Stops ongoing axes 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.DeviceStopRequest.Builder builder = Main.DeviceStopRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setAxis(0);

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

    /**
     * Stops ongoing axes 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 axes 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 axes movement. Decelerates until zero speed.
     */
    public void stop() {
        stop(true);
    }

    /**
     * Waits until all axes of device stop 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.DeviceWaitUntilIdleRequest.Builder builder = Main.DeviceWaitUntilIdleRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setAxis(0);

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

    /**
     * Waits until all axes of device stop moving.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture waitUntilIdleAsync() {
        return waitUntilIdleAsync(true);
    }

    /**
     * Waits until all axes of device stop 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 all axes of device stop moving.
     */
    public void waitUntilIdle() {
        waitUntilIdle(true);
    }

    /**
     * Parks the device in anticipation of turning the power off.
     * It can later be powered on, unparked, and moved without first having to home it.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture parkAsync() {
        Main.DeviceParkRequest.Builder builder = Main.DeviceParkRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setAxis(0);

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

    /**
     * Parks the device in anticipation of turning the power off.
     * It can later be powered on, unparked, and moved without first having to home it.
     */
    public void park() {
        try {
            parkAsync().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);
        }
    }

    /**
     * Unparks the device. The device will now be able to move.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture unparkAsync() {
        Main.DeviceParkRequest.Builder builder = Main.DeviceParkRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setAxis(0);

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

    /**
     * Unparks the device. The device will now be able to move.
     */
    public void unpark() {
        try {
            unparkAsync().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 bool indicating whether any axis is executing a motion command.
     * @return A CompletableFuture that can be completed to get the result:
     * True if any axis is currently executing a motion command.
     */
    public CompletableFuture isBusyAsync() {
        Main.DeviceIsBusyRequest.Builder builder = Main.DeviceIsBusyRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setAxis(0);

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

    /**
     * Returns bool indicating whether any axis is executing a motion command.
     * @return True if any axis is 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);
        }
    }

    /**
     * Returns a string that represents the axes.
     * @return A string that represents the axes.
     */
    public String toString() {
        Main.ToStringRequest.Builder builder = Main.ToStringRequest.newBuilder();
        builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
        builder = builder.setDevice(getDevice().getDeviceAddress());
        builder = builder.setAxis(0);

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


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy