Common Methods

Prints variables.

Supports recursive printing of table type variables. Automatically adds a newline after printing.

  • Function: print from the lua module
  • Parameters:
    1. params: [any] Content to print, multiple can be passed
  • Returns: none

Example

print("hello", 1, {x=1, y=2})

Sync

Synchronization. Waits for the robot to complete its current motion.

By default, instructions marked with auto_sync automatically call this sync instruction before execution.

WARNING

It is strongly recommended to use disable_auto_sync() to disable auto sync, and manually call sync() where motion completion needs to be waited for.

  • Function: sync from the lua module
  • Parameters: none
  • Returns: none

Example

movej({j1=0, j2=1.57, j3=-1.57, j4=0, j5=3.14, j6=3.14}, 1.0, 0.2, 0, 0)
sync() -- Wait for motion to complete

Disable Auto Sync 3.1

After calling this API, subsequent instructions marked with auto_sync will no longer automatically call sync() to wait for motion completion.

WARNING

It is strongly recommended to use disable_auto_sync() to disable auto sync, and manually call sync() where motion completion needs to be waited for.

  • Function: disable_auto_sync from the lua module
  • Parameters: none
  • Returns: none

Example

disable_auto_sync()
movej({j1=0, j2=1.57, j3=-1.57, j4=0, j5=3.14, j6=3.14}, 1.0, 0.2, 0, 0)
print("movej not finish") -- Prints immediately before motion completes
sync() -- Manually wait for motion to complete

Enable Auto Sync 3.1

After calling this API, subsequent instructions marked with auto_sync will automatically call sync() to wait for motion completion.

WARNING

Has compatibility issues with Cooperative Multitasking, not recommended. It is strongly recommended to use disable_auto_sync() to disable auto sync, and manually call sync() where motion completion needs to be waited for.

  • Function: enable_auto_sync from the lua module
  • Parameters: none
  • Returns: none

Example

enable_auto_sync()
movej({j1=0, j2=1.57, j3=-1.57, j4=0, j5=3.14, j6=3.14}, 1.0, 0.2, 0, 0)
print("movej had finish") -- Automatically waits for motion to complete before printing

Sync Run 3.1.21

Sets auto_sync only within the function, without affecting the auto sync setting outside the function.

WARNING

Has compatibility issues with Cooperative Multitasking, not recommended. It is strongly recommended to use disable_auto_sync() to disable auto sync, and manually call sync() where motion completion needs to be waited for.

  • Function: sync_run from the lua module
  • Parameters:
    1. f: [function] The function to run
    2. auto_sync: [bool] Whether to enable auto_sync inside the function. Optional, default true
    3. args: [any] Arguments passed to function f, optional
  • Returns: [any] Return value of function f

Example

ret = sync_run(function()
  ret = scene("10001")
  return ret
end, false)

Get Timestamp

Gets millisecond timestamp.

  • Function: timestamp from the lua module
  • Parameters: none
  • Returns: [int] Millisecond timestamp

Example

print(timestamp())

Wait auto_sync

Robot waits for a specified duration.

  • Function: wait from the lua module
  • Parameters:
    1. time: [int] Duration in milliseconds
  • Returns: none

Example

wait(1000) -- Wait 1 second

Real-time Wait

Sleeps for the specified number of milliseconds via the real-time scheduler, for scenarios requiring precise time control.

  • Function: rt_sleep from the lua module
  • Parameters:
    1. time: [int] Duration in milliseconds
  • Returns: none

Example

rt_sleep(10)

Sleep

Blocks the current task for the specified number of milliseconds.

  • Function: sleep from the lua module
  • Parameters:
    1. time: [int] Duration in milliseconds
  • Returns: none

Example

sleep(1000) -- Sleep for 1 second

Sleep Forever

Blocks the current task permanently until it is terminated.

  • Function: sleep_forever from the lua module
  • Parameters: none
  • Returns: none

Example

sleep_forever()

Wait Until auto_sync

Robot waits for a specified duration until a condition is met.

  • Function: wait_until from the lua module
  • Parameters:
    1. fn: [function] Condition to wait for, checked once per cycle until fn() returns true
  • Returns: none

Example

wait_until(function()
  return get_di(0) == 1
end)