Program Control

Call Scene auto_sync

Loads a scene as a function and calls it within the current task.

Calls a scene by passing its ID. The scene can be a timeline scene or a Lua scene.

  • Function: scene from the lua module
  • Parameters:
    1. scene_id: [str] Scene ID
    2. params: [list[any]] Input parameters. Optional, default empty
    3. dir: [str] Workspace name. Optional, default root directory
  • Returns: [any] Scene return value

Example

Scene 10001:

local params = ...
print("params: ", params)

-- Set global variable
var_test = {
    name = "Xiao Wu",
    age = 16
}
return 4, 5, 6

Scene 10002:

print(scene(10001, {1, 2, 3})) -- Print scene return value
print(var_test) -- Print global variable

Start Task

Starts a new task, waits for the new task to start running, then returns the new task's task_id.

Serial tasks execute in queue, only one serial task can run at a time. Subsequent tasks will only run after the previous task completes, fails, or is terminated.

Parallel tasks execute immediately, multiple parallel tasks can run simultaneously, with independent environment variables.

Unlike scene, start_task creates a new thread to execute the task.

WARNING

  • When the started scene contains motion related APIs, must start as serial task (is_parallel is false)
  • In serial tasks, must start as parallel task (is_parallel is true), otherwise it will block
  • Function: start_task from the lua module
  • Parameters:
    1. scene_id: [str] Scene ID
    2. params: [list[str]] Parameters, string array. Optional, default empty
    3. dir: [str] Workspace name. Optional, default root directory
    4. is_parallel: [bool] Whether to execute in parallel. Optional, default false (serial)
    5. loop_to: [int] Repeat execution count. Optional, default 1, 0 means infinite
  • Returns: [int] Task ID (task_id)

Example

task_id = start_task("10024", nil, nil, false, 1) -- Serial execution task

Get All Task IDs

  • Function: get_task_list from the lua module
  • Parameters: none
  • Returns: [list[int]] All incomplete task IDs

Example

print(get_task_list())

Get Serial Task ID 3.1.18

  • Function: get_main_task_id from the lua module
  • Parameters: none
  • Returns: [int] Serial task ID. Returns nil when no serial task exists

Example

task_id = get_main_task_id()

Get Current Task ID

  • Function: get_task_id from the lua module
  • Parameters: none
  • Returns: [int] Current task ID

Example

print(get_task_id())

Wait for Task Completion

Note: Do not wait for yourself, waiting for yourself will never complete.

  • Function: wait_task from the lua module
  • Parameters:
    1. task_id: [int] Task ID returned by start_task. Optional, defaults to serial task
  • Returns: [str] All print output of the task

Example

stdout = wait_task(task_id)
print(stdout)

Get Task State

  • Function: get_task_state from the lua module
  • Parameters:
    1. task_id: [int] Task ID. Optional, defaults to serial task
  • Returns: [str] Task state: "NONE" no task; "WAIT" queuing; "RUNNING" running; "PAUSE" paused; "SUCCESS" ran successfully; "INTERRUPTING" stopping; "INTERRUPT" stopped; "FAIL" ran failed

Example

state = get_task_state(task_id)
print(state)

Stop Task

Stops the specified task. When stopping a serial task, stop_move is automatically called to stop motion.

  • Function: cancel_task from the lua module
  • Parameters:
    1. task_id: [int] Task ID. Optional, defaults to serial task
  • Returns: [bool] Whether executed successfully

Example

cancel_task(get_task_id())

Pause Task

Pauses the specified task. When pausing a serial task, pause_move is automatically called to pause motion.

  • Function: pause_task from the lua module
  • Parameters:
    1. task_id: [int] Task ID. Optional, defaults to serial task
  • Returns: [bool] Whether executed successfully

Example

pause_task(get_task_id())

Compatibility Note

pause is an alias for this function.

Resume Task

Resumes the specified task. When resuming a serial task, resume_move is automatically called to resume motion.

  • Function: resume_task from the lua module
  • Parameters:
    1. task_id: [int] Task ID. Optional, defaults to serial task
  • Returns: [bool] Whether executed successfully

Example

resume_task(get_task_id())

Compatibility Note

resume is an alias for this function.