Skip to content Skip to main navigation Skip to footer

Electric Gate Capability

Introduction

The API lets you open and close the electric gate and query its status.

There are two ways to operate the electric gate; Method 2 is recommended. Controlling the electric gate has one requirement: after you send a command to control the electric gate, you must wait until that command succeeds before sending a second command. Method 2 has built-in safeguards: if a command has been sent and has not finished yet, a second command fails immediately with an error and does not affect the first command. With Method 1, you have to implement this logic check yourself.

Method 1 Open or Close the Electric Gate The API requires release library 9.7 or later

Note: Before sending an open or close command, it is best to query the current gate status and only open or close the doors when the electric gate is not running. The running status value of the electric gate is Definition.CAN_DOOR_STATUS_RUNNING; see the “Query Compartment Door Status” command for details. If you call the status query API immediately after sending an open or close command, you will not get the status. We recommend registering a listener as shown below; when the open/closed status of the compartment doors changes, the listener responds.

RobotApi.getInstance().setElectricDoorCtrl(0, doorCmd, new CommandListener() {
    @Override
    public void onResult(int result, String message, String extraData) {
        super.onResult(result, message, extraData);
        Log.d(TAG, "setElectricDoorCtrl result:" + result + " message:" + message);
        if (result == 1 && TextUtils.equals(message, Definition.SUCCEED)) {
            Log.d(TAG, "onResult: The electric door is controlled successfully");
        } else {
            Log.d(TAG, "onResult: The electric door is controlled failed");
        }
    }
});

doorCmd parameter:

Definition.CAN_DOOR_DOOR1_DOOR2_OPEN Open the upper compartment doors

Definition.CAN_DOOR_DOOR1_DOOR2_CLOSE Close the upper compartment doors

Definition.CAN_DOOR_DOOR3_DOOR4_OPEN Open the lower compartment doors

Definition.CAN_DOOR_DOOR3_DOOR4_CLOSE Close the lower compartment doors

Definition.CAN_DOOR_ALL_OPEN Open all compartment doors (debugging command; not recommended unless necessary)

Definition.CAN_DOOR_ALL_CLOSE Close all compartment doors (debugging command; not recommended unless necessary)

Method 2 Open or Close the Electric Gate The API requires release library 10.3 or later

         RobotApi.getInstance().startControlElectricDoor(0, doorCmd, new ActionListener() {
                    @Override
                    public void onResult(int result, String message, String extraData) {
                        Log.d(TAG, "startControlElectricDoor result:" + result + " message:" + message);
                        LogTools.info("startControlElectricDoor result:" + result + " message:" + message);
                        if (result == Definition.RESULT_OK) {
                            //Control succeeded
                            Log.d(TAG, "startControlElectricDoor success");
                        } else {
                            //Control failed
                            Log.d(TAG, "startControlElectricDoor failed");
                        }
                    }

                    @Override
                    public void onError(int errorCode, String errorString, String extraData) {
                        Log.d(TAG, "startControlElectricDoor onError: errorCode:" + errorCode + " errorString:" + errorString);
                        if (errorCode == Definition.ERROR_ELECTRIC_DOOR_BLOCK) {
                            //Upper and lower doors blocked (a hand or something else is caught)
                            Log.d(TAG, "startControlElectricDoor onError: electric door block");
                        } else if (errorCode == Definition.ERROR_ELECTRIC_DOOR_UPPER_BLOCK) {
                            //Upper door blocked (a hand or something else is caught in the upper door)
                            Log.d(TAG, "startControlElectricDoor onError: electric door upper block");
                        } else if (errorCode == Definition.ERROR_ELECTRIC_DOOR_LOWER_BLOCK) {
                            //Lower door blocked (a hand or something else is caught in the upper door)
                            Log.d(TAG, "startControlElectricDoor onError: electric door lower block");
                        } else if (errorCode == Definition.ERROR_ELECTRIC_DOOR_TIMEOUT) {
                            //Door control command timed out
                            Log.d(TAG, "startControlElectricDoor onError: electric door timeout");
                        }
                    }

                    @Override
                    public void onStatusUpdate(int status, String data, String extraData) {
                        Log.d(TAG, "onStatusUpdate: status:" + status + " data:" + data);
                        if (status == Definition.STATUS_ELECTRIC_DOOR_BLOCK) {
                            //Upper and lower doors blocked (a hand or something else is caught); you can show a pinch warning
                            Log.d(TAG, "onStatusUpdate: electric door block");
                        } else if (status == Definition.STATUS_ELECTRIC_DOOR_UPPER_BLOCK) {
                            //Upper door blocked (a hand or something else is caught in the upper door); you can show a pinch warning
                            Log.d(TAG, "onStatusUpdate: electric door upper block");
                        } else if (status == Definition.STATUS_ELECTRIC_DOOR_LOWER_BLOCK) {
                            //Lower door blocked (a hand or something else is caught in the upper door); you can show a pinch warning
                            Log.d(TAG, "onStatusUpdate: electric door lower block");
                        }
                    }
                });

doorCmd parameter:

Definition.CAN_DOOR_DOOR1_DOOR2_OPEN Open the upper compartment doors

Definition.CAN_DOOR_DOOR1_DOOR2_CLOSE Close the upper compartment doors

Definition.CAN_DOOR_DOOR3_DOOR4_OPEN Open the lower compartment doors

Definition.CAN_DOOR_DOOR3_DOOR4_CLOSE Close the lower compartment doors

Definition.CAN_DOOR_ALL_OPEN Open all compartment doors

Definition.CAN_DOOR_ALL_CLOSE Close all compartment doors

The following commands require ROM version 11.3

Definition.CAN_DOOR_DOOR1_OPEN Open the upper left compartment door

Definition.CAN_DOOR_DOOR1_CLOSE Close the upper left compartment door

Definition.CAN_DOOR_DOOR2_OPEN Open the upper right compartment door

Definition.CAN_DOOR_DOOR2_CLOSE Close the upper right compartment door

Definition.CAN_DOOR_DOOR3_OPEN Open the lower left compartment door

Definition.CAN_DOOR_DOOR3_CLOSE Close the lower left compartment door

Definition.CAN_DOOR_DOOR4_OPEN Open the lower right compartment door

Definition.CAN_DOOR_DOOR4_CLOSE Close the lower right compartment door

Register a Compartment Door Status Listener

Register an electric gate status listener to get the electric gate status. Register it wherever your business logic needs it.
When the electric gate status changes, the onStatusUpdate method is called back; for example, the electric gate status changes after you call the open or close command.
If you need to get the electric gate status at an arbitrary time, call the getElectricDoorStatus method.

//For handling the listener, refer to the handling in the getElectricDoorStatus method
RobotApi.getInstance().registerStatusListener(Definition.STATUS_CAN_ELECTRIC_DOOR_CTRL, statusListener);

Remove the Compartment Door Listener

When you no longer need the gate status, remove the listener to prevent memory leaks.

RobotApi.getInstance().unregisterStatusListener(statusListener);

Query Compartment Door Status

You can call this method at any time to query the compartment door status.

RobotApi.getInstance().getElectricDoorStatus(0, new CommandListener() {
            @Override
            public void onResult(int result, String message, String extraData) {
                super.onResult(result, message, extraData);
                Log.d(TAG, "getElectricDoorStatus result:" + result + " message:" + message);
                if (result == 1 && !TextUtils.isEmpty(message)) {
                    CanElectricDoorBean doorBean = GsonUtil.fromJson(message, CanElectricDoorBean.class);
                    //door1 and door2 are the two upper compartment doors; door3 and door4 are the two lower compartment doors
                    //Status of the upper compartment doors
                    if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_RUNNING || doorBean.getDoor2() ==                                                                                 Definition.CAN_DOOR_STATUS_RUNNING) {
                        Log.d(TAG, "upper door is running");
                        //Do not send open or close commands while the compartment doors are moving
                    }
                    if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_OPEN && doorBean.getDoor2() == Definition.CAN_DOOR_STATUS_OPEN) {
                        Log.d(TAG, "upper door is open");
                    }
                    if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_CLOSE && doorBean.getDoor2() == Definition.CAN_DOOR_STATUS_CLOSE) {
                        Log.d(TAG, "upper door is close");
                    }
                    //Status of the lower compartment doors
                    if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_RUNNING || doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_RUNNING) {
                        Log.d(TAG, "lower door is running");
                        //Do not send open or close commands while the compartment doors are moving
                    }
                    if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_OPEN && doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_OPEN) {
                        Log.d(TAG, "lower door is open");
                    }
                    if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_CLOSE && doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_CLOSE) {
                        Log.d(TAG, "lower door is close");
                    }

                    //Door stall status; a stall may occur when opening or closing the doors
                    //Blocked while closing
                    if (doorBean.getUpStatus() == Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE) {
                        Log.d(TAG, "upper door is block and bounce");
                    }
                    if (doorBean.getDownStatus() == Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE) {
                        Log.d(TAG, "lower door is block and bounce");
                    }
                    //Blocked while opening
                    if (doorBean.getUpStatus() == Definition.CAN_DOOR_STATUS_BLOCKING_STOP) {
                        Log.d(TAG, "upper door is blocking stop");
                    }
                    if (doorBean.getDownStatus() == Definition.CAN_DOOR_STATUS_BLOCKING_STOP) {
                        Log.d(TAG, "lower door is blocking stop");
                    }
                } else {
                    Log.d(TAG, "getElectricDoorStatus onResult: Failure to get status");
                }
            }
        });

Status codes:

Definition.CAN_DOOR_STATUS_RUNNING: the electric gate is executing a task

Definition.CAN_DOOR_STATUS_OPEN: compartment door open

Definition.CAN_DOOR_STATUS_CLOSE: compartment door closed

Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE: blocked while closing (if this happens, remove the obstruction and try again)

Definition.CAN_DOOR_STATUS_BLOCKING_STOP: blocked while opening (if this happens, remove the obstruction and try again)

Usage notes:

The upper compartment has two doors, returned as door1 and door2; the lower compartment has two doors, returned as door3 and door4.

To check the upper compartment status, evaluate door1 and door2 together; to check the lower compartment status, evaluate door3 and door4 together.

If you query immediately after sending an open or close command, the compartment doors are still opening or closing, so you will not get the expected opened or closed status. Wait a while before querying.

For detailed usage, see the Demo

GreetingBotGreetingBot 2GreetingBot MiniLuckiBotLuckiBot ProBigScreenBotLuckiBot Pro Autodoor
NoNoNoNoNoNoYes