Common Methods
Print Output auto_sync
Prints variables.
Supports recursive printing of table type variables. Automatically adds a newline after printing.
- Function:
printfrom the lua module - Parameters:
- 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:
syncfrom 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_syncfrom 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_syncfrom 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_runfrom the lua module - Parameters:
- f: [function] The function to run
- auto_sync: [bool] Whether to enable auto_sync inside the function. Optional, default
true - 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:
timestampfrom the lua module - Parameters: none
- Returns: [int] Millisecond timestamp
Example
print(timestamp())
Wait auto_sync
Robot waits for a specified duration.
- Function:
waitfrom the lua module - Parameters:
- 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_sleepfrom the lua module - Parameters:
- time: [int] Duration in milliseconds
- Returns: none
Example
rt_sleep(10)
Sleep
Blocks the current task for the specified number of milliseconds.
- Function:
sleepfrom the lua module - Parameters:
- 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_foreverfrom 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_untilfrom the lua module - Parameters:
- fn: [function] Condition to wait for, checked once per cycle until
fn()returnstrue
- fn: [function] Condition to wait for, checked once per cycle until
- Returns: none
Example
wait_until(function()
return get_di(0) == 1
end)
