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')

Initialize SDK

Only needs to be initialized once after importing the SDK

  • Function name: Function init in the [lebai_sdk] module
  • Parameters: None
  • Return: None

Example Program

lebai_sdk = require('lebai_sdk')
lebai_sdk.init()

SDK Version

Get the SDK version number.

  • Function name: Function version in the [lebai_sdk] module
  • Parameters: None
  • Return: [str] Version number

Example Program

version = lebai_sdk.version()
print(version)

Get Timestamp

Get the current system timestamp (milliseconds).

  • Function name: Function timestamp in the [lebai_sdk] module
  • Parameters: None
  • Return: [int] Millisecond timestamp

Example Program

timestamp = lebai_sdk.timestamp()
print(timestamp)

Sleep

Block sleep for the specified number of milliseconds.

  • Function name: Function sleep_ms in the [lebai_sdk] module
  • Parameters:
    1. ms: [int] Sleep time (milliseconds)
  • Return: None

Example Program

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_devices in the [lebai_sdk] module
  • Parameters:
    1. time: [float] Scan duration (seconds)
  • Return: [DeviceInfo] Device information list, containing name device name, ip IP address, mac MAC address, online whether online

Example Program

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 connect in the [lebai_sdk] module
  • Parameters:
    1. ip: [str] Lebai robot arm IP address
    2. port: [bool | int] Port selection — None or False for real robot (default 3031), True for simulator (3030), int for custom port. Optional, default None
    3. option: [ConnectOption] Connection options, e.g. {"request_timeout": 60}. Optional, default None
  • 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)

Get Connection Status

  • Function name: Method is_connected under [Robot]
  • Parameters: None
  • Return: [bool] Whether in connected state

Example Program

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_disconnect under [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

Call Arbitrary RPC Method

Call any JSON-RPC method, used to call low-level interfaces not yet encapsulated by the SDK.

  • Function name: Method call under [Robot]
  • Parameters:
    1. method: [str] RPC method name
    2. param: [str] Parameter JSON string. Optional, default None
  • Return: [str] Result JSON string

Example Program

res = lebai:call("get_robot_state", nil)
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 subscribe under [Robot]
  • Parameters:
    1. method: [str] Subscription method name
    2. 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 next under [RobotSubscription]
  • Parameters: None
  • Return: [str] Push data JSON string; returns None when 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