Motion control

The motion control service provides functions of the API's calling to control the device to perform various motions. As the motion control service agent, MotionManager provides the main API of the motion control service, which can be obtained through the RobotContext object.

MotionManager motionManager = aRobotContext.getSystemService(MotionManager.SERVICE);

Get the status of current motion.

Normally, the device only has two statuses, one is the reset status (RESET) and the other is the performing status (PERFORMING_ACTION)

Posture /* [1] */ posture = motionManager.getPosture();

[1]Posture parameter description

Attribute getter Descriptions
Posture.name Motion name
Posture.description Motion description

The following constants are only used to compare the current status of the device.

Constants Descriptions
Posture.RESET Reset status
Posture.PERFORMING_ACTION Perform motion status

Control device's motion

Under normal circumstances, some devices will create a series of preset actions tailored for themselves, such as applause, handshake, salute, etc. Through motion control services, users can directly call these preset motions. When using it you can choose to perform one or more motions serially. The usage methods will be introduced one by one below.

Perform a specific motion using Uri. Use the following code to make the device perform a “hug” motion.

Uri actionUri = Uri.parse("action://ubtrobot/hug"); /* [2] */
promise /* [1] */ = motionManager.performAction(actionUri)
    .progress(new ProgressCallback<PerformingProgress>() {
        @Override
        public void onProgress(PerformingProgress/* [3] */ performingProgress) {
            // There will be multiple callbacks during the performance of the motion
        }
    })
    .done(new DoneCallback<Void>() {
        @Override
        public void onDone(Void aVoid) {
            // Motion performance completed
        }
    })
    .fail(new FailCallback<PerformingException>() {
        @Override
        public void onFail(PerformingException e) {
            // Motion performance failed
        }
    });

[1]Return the asynchronous object that performs the movement operation, fetches the result and cancels the processing through this object. See Promise for specific usage.

[2]Uri of the motion

[3] The PerformingProgress object of theasynchronous callback describes the progress information of the device movement, including:

Constants Descriptions
PerformingProgress.PROGRESS_BEGAN Start of motion execution
PerformingProgress.PROGRESS_ENDED End of motion execution

Perform a specific motion in accordance with the parameters. Use the following code to make it execute the “goodbye” motion three times at an interval of three seconds.

Uri uri = Uri.parse("action://ubtrobot/goodbye"); 
PerformingOption/* [1] */ option = new PerformingOption.Builder(uri)
    .setLoops(3)
    .setOffsetTime(3000)
    .build();
promise = motionManager.performAction(option);

[1] The PerformingOption object is constructed by PerformingOption.Builder, the construction parameters are described as follows:

Methods Type Descriptions Default value
Builder.constructor(Uri) Uri Uri of the motion NULL
Builder.setLoops(loop) int Number of repetitions 1
Builder.setOffsetTime(offsetTime) float Interval of execution 0
Builder.setSpeed(speed) float Speed of execution 0

Perform multiple motions serially Use the following two methods to perform this action. First perform a "hug" motion, and then take three seconds as the interval.

Uri hugUri = Uri.parse("action://ubtrobot/goodbye"); 
PerformingOption option1 = new PerformingOption.Builder(hugUri)
    .setLoops(1)
    .build();

Uri goodbyeUri = Uri.parse("action://ubtrobot/goodbye"); 
PerformingOption option2 = new PerformingOption.Builder(goodbyeUri)
    .setLoops(3)
    .setOffsetTime(3000)
    .build();

// Method one
promise = motionManager.performActionSerially(option1, option2);

// Method two
ArrayList<PerformingOption> optionList = new ArrayList<>();
optionList.add(option1);
optionList.add(option2);
promise = motionManager.performActionSerially(optionList);

Determine if the device is currently performing the motion

motionManager.isPerformingAction();

List of motions

Motion name ID
applause applause
celebrate celebrate
goodbye goodbye
nod nod
hug hug
shake hand shankhand
Go right guideright
Go left guideleft
Swing arm swingarm
Search around searching
Gaze tiaowang
surprise surprise
shy shy
Grow tall zhanggao
daze fadai
Chit-chat Talk1-talk24 talk1
talk2
talk3
talk4
talk5
talk6
talk7
talk8
talk9
talk10
talk11
talk12
talk13
talk14
talk15
talk16
talk17
talk18
talk19
talk20
talk21
talk22
talk23
talk24