Python SDK Interface Examples
WARNING
- Only supports Python 3.7 and above
- For regular calling method, please install lebai-sdk:
pip install lebai_sdk
- For asynchronous coroutine calling method (AsyncIO and async/await), please install lebai-sdk-asyncio:
pip install lebai_sdk_asyncio
Initialization and Connection
Device Discovery
WARNING
This feature is based on mDNS technology. JavaScript SDK for Web frontend development does not support this feature.
devices = lebai_sdk.discover_devices(time)
Continuously discover nearby devices for a duration, then return the names, IP addresses, and MAC addresses of all discovered devices.
Parameters
time
Duration in seconds
Returns
- List of discovered device objects, each containing device name, IP, and MAC address as a dictionary
name
Device nameip
Device IP addressmac
Device MAC address
Example
import lebai_sdk
lebai_sdk.init()
import nest_asyncio
nest_asyncio.apply()
devices = lebai_sdk.discover_devices(3)
print(devices)
# Output:
# [{'name': 'lebai-3wbgvM', 'mac': 'b4:4b:d6:5e:55:1c', 'ip': '10.20.17.1', 'online': True}]
Initialize Object
WARNING
Due to communication instability, IP errors, and other reasons, errors may occur. In most cases, error handling mechanisms are needed to catch errors and prevent abnormal exits.
lebai = lebai_sdk.connect(ip, simu)
Connect to the Lebai robotic arm.
Parameters
ip
IP address of the Lebai robotic armsimu
Whether to connect in simulation mode. Optional, defaults to real mode
Returns
lebai
Robotic arm instance for subsequent control methods
Example
import lebai_sdk
lebai_sdk.init()
# If encountering event loop related RuntimeError, try adding the following 2 lines
# import nest_asyncio
# nest_asyncio.apply()
# Set robot IP address, modify according to actual robot IP
robot_ip = "192.168.4.145"
# Create instance
lebai = lebai_sdk.connect(robot_ip, False)
Get Connection Status
connected = lebai.is_connected()
Returns connection status. Used to determine if currently connected. Connection will be lost if arm is restarted.
- Returns
connected
Connection status
Wait for Disconnect
disconnect_reason = lebai.wait_disconnect()
Returns the reason for disconnection after connection is lost. Used to determine disconnect reason and reconnect.
- Returns
disconnect_reason
Reason for disconnection
Status Data
Get Robot State
robot_state = lebai.get_robot_state()
Returns current robot state.
- Returns
robot_state
Robot state
State details:
Code | State | Description |
---|---|---|
-1 | ERROR | Robot software control system exception |
0 | DISCONNECTED | Robot hardware communication failure |
1 | ESTOP | Robot in emergency stop state |
2 | BOOTING | Robot initializing |
3 | ROBOT_OFF | Robot power not enabled |
4 | ROBOT_ON | Robot power enabled |
5 | IDLE | Robot in idle state |
6 | PAUSED | Robot in paused state |
7 | MOVING | Robot in motion |
8 | UPDATING | Robot system updating |
9 | STARTING | Robot startup process from init to idle |
10 | STOPPING | Robot transitioning from idle to stop |
11 | TEACHING | Robot in teaching mode |
12 | STOP | Robot in stop state (not emergency stop) |
Get Emergency Stop Reason
reason = lebai.get_estop_reason()
Returns the reason for robot emergency stop.
- Returns
reason
Emergency stop reason
Get Current Motion Data
kin_data = lebai.get_kin_data()
Returns current robot position and velocity information.
- Returns
kin_data
Dictionary containing motion data
Dictionary contains:
actual_joint_pose
Actual joint positionactual_joint_speed
Actual joint velocityactual_tcp_pose
Actual tool positiontarget_tcp_pose
Target tool position- And other motion-related data
Robot System Control
Start System
lebai.start_sys()
Enable joint motion after robot power-up initialization. After successful execution, robot transitions to idle state.
Stop System
lebai.stop_sys()
Stop the robotic arm system. Robot transitions to stopped state after successful execution.
Power Down
lebai.powerdown()
Shut down the robot and control box, disconnecting network connection.
Reboot
lebai.reboot()
Restart the control box, equivalent to pressing the power button to shut down and restart.
Emergency Stop
lebai.estop()
Immediately disable robot arm and apply brakes. Arm will stop motion and require start_sys() to re-enable.
Motion
Teaching Mode
lebai.teach_mode()
Enter teaching (free drive) mode when robot is in idle state. In teaching mode, robot joints can be freely dragged.
Exit Teaching Mode
lebai.end_teach_mode()
Exit teaching mode and return to idle state.
Joint Motion
motion_id = lebai.movej(p, a, v, t, r)
Parameters
p
Position parameter (list for joint angles or dict for Cartesian coordinates)a
Joint acceleration (rad/s2)v
Joint velocity (rad/s)t
Motion time (s)r
Blending radius (m)
Returns
motion_id
Motion command ID
Linear Motion
motion_id = lebai.movel(p, a, v, t, r)
Linear motion in tool space.
Wait for Motion Complete
lebai.wait_move(motion_id)
Wait for motion command to complete.
Get Motion State
move_state = lebai.get_motion_state(motion_id)
Get motion state: "WAIT", "RUNNING", or "FINISHED".
Gripper
Initialize Gripper
lebai.init_claw(must)
Initialize gripper with stroke confirmation.
Gripper Control
lebai.set_claw(force, amplitude)
Set gripper force and opening amplitude.
- Parameters
force
Force level (0-100)amplitude
Opening amplitude (0-100)
Get Gripper Status
claw_status = lebai.get_claw()
Returns gripper status dictionary.
Task Control
Start Task
task_id = lebai.start_task(scene_id, params, dir, is_parallel, loop_to)
Execute a Lua scene by scene ID.
- Parameters
scene_id
Scene IDparams
Parameters to passdir
Scene directoryis_parallel
Whether to execute in parallelloop_to
Number of repetitions
Wait for Task
stdout = lebai.wait_task(task_id)
Wait for task completion and return output.
Get Task State
state = lebai.get_task_state(task_id)
Get task execution state.
IO Control
Set Digital Output
lebai.set_do(device, pin, value)
Set digital output pin state.
- Parameters
device
Device type ("ROBOT", "FLANGE", etc.)pin
Pin number (starting from 0)value
Value to set (0 or 1)
Get Digital Input
value = lebai.get_di(device, pin)
Get digital input pin state.
Position and Pose
Forward Kinematics
cart = lebai.kinematics_forward(jpose)
Convert joint angles to Cartesian coordinates.
Inverse Kinematics
joints = lebai.kinematics_inverse(pose, joints)
Convert Cartesian coordinates to joint angles.
Pose Transformation
c = lebai.pose_trans(a, b)
Transform pose B relative to coordinate frame A to world coordinates.
Pose Inverse
c = lebai.pose_inverse(a)
Calculate inverse of pose transformation matrix.
Pose Addition
pose = lebai.pose_add(base, delta, frame)
Add pose offset to base pose in specified frame.
Robot Configuration
Set TCP
lebai.set_tcp(tcp)
Set Tool Center Point coordinates relative to flange.
Get TCP
tcp = lebai.get_tcp()
Get current TCP settings.
Set Velocity Factor
lebai.set_velocity_factor(factor)
Set velocity scaling factor (0-100%).
Set Payload
lebai.set_payload(mass, cog)
Set end-effector payload mass and center of gravity.
Set Gravity
lebai.set_gravity(gravity)
Set gravity direction for robot installation orientation.
Signal Interaction
Set Signal
lebai.set_signal(index, value)
Set signal value by index (0-255).
Get Signal
value = lebai.get_signal(index)
Get signal value by index.