跳到主要内容

笛卡尔到点完整示例

本示例演示使用 move_point() 将左臂末端移动到相对当前位姿抬高 3 cm 的 base frame 目标再返回。move_point() 会对目标末端位姿求 IK,在关节空间中规划路径并执行点到点运动;末端路径不保证为直线。目标由当前读取的末端位姿加有限偏移生成,不使用硬编码绝对位姿。

涉及状态: JointStand、upper_body_tele_task

涉及接口: move_joint()、move_point()、wait_until_idle()、get_cartesian_state()

Python
import math
import os
import time

os.environ.setdefault("FASTDDS_BUILTIN_TRANSPORTS", "UDPv4") # 机器人上运行必须设置

from fourier_aurora_client import AuroraClient
from movetools_session import MoveToolsSession

Z_OFFSET = 0.03 # 末端 Z 向偏移(m),保持在小幅范围内


def wait_fsm(client, expected, timeout_s=8.0):
deadline = time.monotonic() + timeout_s
while client.get_fsm_state() != expected:
if time.monotonic() >= deadline:
raise RuntimeError(f"state {expected} not reached")
time.sleep(0.05)


def check_result(result, name):
if not result.success:
raise RuntimeError(f"{name} failed: {result.code} {result.message}")


def wait_and_check(movetools, name):
movetools.wait_until_idle()
movetools.raise_if_error()
print(f"{name} complete")


def normalized_pose(pose):
pose = list(pose)
norm = math.sqrt(sum(q * q for q in pose[3:]))
return pose[:3] + [q / norm for q in pose[3:]]


client = AuroraClient.get_instance(
domain_id=123, # 必须与当前 AuroraCore 的 DDS domain 一致
robot_name="grw",
)
movetools = MoveToolsSession(client, robot_name="grw")
started = False

try:
input("Press Enter to switch to JointStand...")
client.set_fsm_state(1)
wait_fsm(client, 1)
time.sleep(2.0)

input("Press Enter to switch to upper_body_tele_task...")
client.set_fsm_state(4)
wait_fsm(client, 4)
time.sleep(1.0)

movetools.start()
started = True

# 读取当前左臂末端位姿(base 系)并归一化四元数,作为起点
start_pose = normalized_pose(client.get_cartesian_state("left_manipulator", "pose"))
print(f"start pose: {[round(v, 4) for v in start_pose]}")

target_pose = start_pose[:2] + [start_pose[2] + Z_OFFSET] + start_pose[3:]

input("Press Enter to run move_point...")
result = movetools.move_point(
groups=["left_manipulator"],
target_poses={"left_end_effector_link": target_pose},
expect_vel=150,
frame="base",
)
check_result(result, "move_point")
wait_and_check(movetools, "move_point")

moved_pose = normalized_pose(client.get_cartesian_state("left_manipulator", "pose"))
print(f"z delta reached: {round(moved_pose[2] - start_pose[2], 4)}")

input("Press Enter to return to the start pose...")
result = movetools.move_point(
groups=["left_manipulator"],
target_poses={"left_end_effector_link": start_pose},
expect_vel=150,
frame="base",
)
check_result(result, "move_point back")
wait_and_check(movetools, "move_point back")

finally:
if started:
movetools.stop()
if client.get_fsm_state() != 3:
client.set_fsm_state(3) # 回到策略站立状态
wait_fsm(client, 3)
client.close()