Initialize Instance
WARNING
Due to communication instability and other reasons, errors may occur. In most cases, the error handling mechanism is needed to catch errors and prevent abnormal exits.
Import SDK
Select the programming language to use and import lebai_sdk
Example Program
lebai_sdk = require('lebai_sdk')
import lebai_sdk
Initialize SDK
Only needs to be initialized once after importing the SDK
- Function name: Function
initin the [lebai_sdk] module - Parameters: None
- Return: None
Example Program
lebai_sdk = require('lebai_sdk')
lebai_sdk.init()
import lebai_sdk
lebai_sdk.init()
SDK Version
Get the SDK version number.
- Function name: Function
versionin the [lebai_sdk] module - Parameters: None
- Return: [str] Version number
Example Program
version = lebai_sdk.version()
print(version)
version = lebai_sdk.version()
print(version)
Get Timestamp
Get the current system timestamp (milliseconds).
- Function name: Function
timestampin the [lebai_sdk] module - Parameters: None
- Return: [int] Millisecond timestamp
Example Program
timestamp = lebai_sdk.timestamp()
print(timestamp)
timestamp = lebai_sdk.timestamp()
print(timestamp)
Sleep
Block sleep for the specified number of milliseconds.
- Function name: Function
sleep_msin the [lebai_sdk] module - Parameters:
- ms: [int] Sleep time (milliseconds)
- Return: None
Example Program
lebai_sdk.sleep_ms(1000)
lebai_sdk.sleep_ms(1000)
Device Discovery
WARNING
This function is based on mDNS technology. The JavaScript SDK for web frontend development does not support this function.
Continuously discover surrounding devices for the specified duration. After the duration ends, return a list of all online robots in the surrounding area.
- Function name: Function
discover_devicesin the [lebai_sdk] module - Parameters:
- time: [float] Scan duration (seconds)
- Return: [DeviceInfo] Device information list, containing
namedevice name,ipIP address,macMAC address,onlinewhether online
Example Program
devices = lebai_sdk.discover_devices(3)
print(devices)
devices = lebai_sdk.discover_devices(3)
print(devices)
Connect Device
Connect to the Lebai robot arm via IP addressing. Supports LAN IP (e.g. "192.168.2.101") or frpc remote address (e.g. "user:passwd@xxx.nodes.lebai.ltd").
- Function name: Function
connectin the [lebai_sdk] module - Parameters:
- ip: [str] Lebai robot arm IP address
- port: [bool | int] Port selection —
NoneorFalsefor real robot (default 3031),Truefor simulator (3030),intfor custom port. Optional, defaultNone - option: [ConnectOption] Connection options, e.g.
{"request_timeout": 60}. Optional, defaultNone
- Return: [Robot] Robot arm instance, subsequent robot control methods need to use this instance
Example Program
lebai_sdk = require('lebai_sdk')
lebai_sdk.init()
robot_ip = "192.168.4.118"
lebai = lebai_sdk.connect(robot_ip, false)
import lebai_sdk
lebai_sdk.init()
import nest_asyncio
nest_asyncio.apply()
robot_ip = "192.168.4.118"
lebai = lebai_sdk.connect(robot_ip, False)
Get Connection Status
- Function name: Method
is_connectedunder [Robot] - Parameters: None
- Return: [bool] Whether in connected state
Example Program
connected = lebai:is_connected()
print(connected)
connected = lebai.is_connected()
print(connected)
Wait for Disconnect
Block wait for device disconnection. Commonly used for reconnection after device disconnection.
- Function name: Method
wait_disconnectunder [Robot] - Parameters: None
- Return: [str] Device disconnection reason
Example Program
disconnect_reason = lebai:wait_disconnect()
print(disconnect_reason)
lebai = lebai_sdk.connect("192.168.2.3", false) -- Reconnect
disconnect_reason = lebai.wait_disconnect()
print(disconnect_reason)
lebai = lebai_sdk.connect("192.168.2.3", False) # Reconnect
Call Arbitrary RPC Method
Call any JSON-RPC method, used to call low-level interfaces not yet encapsulated by the SDK.
- Function name: Method
callunder [Robot] - Parameters:
- method: [str] RPC method name
- param: [str] Parameter JSON string. Optional, default
None
- Return: [str] Result JSON string
Example Program
res = lebai:call("get_robot_state", nil)
print(res)
res = lebai.call("get_robot_state")
print(res)
Subscribe RPC Method
Subscribe to RPC method push data (sub_<method> / unsub_<method>). Suitable for scenarios requiring real-time robot status, IO changes, etc.
- Function name: Method
subscribeunder [Robot] - Parameters:
- method: [str] Subscription method name
- param: [str] Parameter JSON string. Optional, default
None
- Return: [RobotSubscription] Subscription object, can repeatedly call
next()to get push data
Get Next Push Data
- Function name: Method
nextunder [RobotSubscription] - Parameters: None
- Return: [str] Push data JSON string; returns
Nonewhen subscription ends
Example Program
sub = lebai:subscribe("robot_state", nil)
while true do
local data = sub:next()
if data == nil then
break
end
print(data)
end
sub = lebai.subscribe("robot_state")
while True:
data = sub.next()
if data is None:
break
print(data)
