Skip to content
⚙ Development Guide > SDK > API

Examples#

When connecting to P7 for the first time, run a read-only example first. After confirming that the service and state are readable, proceed to control-authority, mode, and motion examples. Any code that can cause motion must be run only after the work cell is cleared, the tool and payload are confirmed, limits are checked, and the physical emergency stop is ready for immediate operation.

Read-Only State Check#

The following example uses gRPC, waits up to 5 s for an available service state, and then reads joint and firmware information. It does not acquire control authority, switch modes, or send a motion command.

import time

from arm_p7_sdk import AirbotClient


def wait_for_service(client: AirbotClient, timeout_s: float = 5.0):
    deadline = time.monotonic() + timeout_s
    while time.monotonic() < deadline:
        state = client.get_service_state()
        if state is not None and state.valid and state.service_state:
            return state
        time.sleep(0.1)
    raise RuntimeError("P7 服务状态在限定时间内不可用")


with AirbotClient(
    backend="grpc",
    host="P7_IP_ADDRESS",
    port=50071,
) as client:
    service = wait_for_service(client)
    print("FSM:", service.fsm_state)
    print("controller:", service.controller_state)
    print("joints:", client.get_arm_joint_state())
    print("firmware:", client.get_firmware_info())

Replace P7_IP_ADDRESS with the current complete-system address. Joint or firmware getters may still return None; do not replace missing data with an all-zero array or a guessed version. See API Reference for getters and return types.

Control Code Structure#

The following structure demonstrates only the order for control authority and cleanup; it does not send a motion target. Actual calls must also add state, units, limits, completion criteria, and exception-stop logic appropriate to the interface.

from arm_p7_sdk import AirbotClient, Controller


with AirbotClient(
    host="P7_IP_ADDRESS",
    port=50071,
    client_name="my-p7-controller",
) as client:
    if not client.acquire_control(lease_ms=15_000, renew_period_s=5.0):
        raise RuntimeError("无法获取控制权")

    mode_selected = False
    try:
        # 完成安全检查后,按任务切换模式并发送目标。
        pass
    finally:
        if mode_selected:
            client.switch_controller(Controller.idle, timeout_ms=5_000)
        client.release_control()

release_control() does not stop an already accepted planned trajectory. Switch back to idle normally and release the lease only after confirming that motion has completed or stopped.

Choose an Example by Task#

Task Example Entry Point Read First
Acquire, release, or hand over control authority control commands Control Authority (Lease)
Switch modes or read the current mode control mode commands Control Modes
Read eight categories of state state getter commands API Reference
Single joint motion move_joint example PTP Point-to-Point Planning
PTP, LIN, CIRCLE, or waypoint motion Corresponding Cartesian and waypoint examples PTP / LIN / CIRC / Multi-Segment Trajectory Blending
EEF motion move_eef example EEFState (End-Effector State)
Software emergency stop, error clearing, or return to zero recovery commands Motor Error Code Troubleshooting

Amplitude limits and numeric values in examples only protect the input format; they do not provide a safety guarantee for any work cell. A site-specific assessment remains mandatory before operating real hardware.