grpc_client/clients/calibrateZeroQ.py
lgv fb9f589446 feat: add Xiaozhao robot controls and refresh AprilTag assets
Add Xiaozhao arms and head models, device selection, and fresh GetPose queries
with configurable end links. Reset polling, commands, and plots on device changes.

Expose MoveJ jerk and joint zero calibration, improve joint naming and plot
handling, and cover model switching and request lifecycles with regression tests.

Update AprilTag generation to default to PDF and include the refreshed exports,
model meshes, and existing workspace artifacts.
2026-11-18 20:19:14 +08:00

77 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import argparse
from clients._path_setup import ensure_paths
ensure_paths()
from google.protobuf import timestamp_pb2
from clients.base_client import RobotClientBase
from cmvr.api import common_pb2
from cmvr.api import arm_command_pb2 as pb
from cmvr.api import arm_service_pb2_grpc as rpc
class CalibrateZeroQClient(RobotClientBase):
"""Client to send calibrateZeroQ command"""
def send(self, device_id="right_arm", joint_name="") -> bool:
joint_name = joint_name.strip()
if not joint_name:
print("calibrateZeroQ failed: joint_name must not be empty")
return False
# Construct request header
header = common_pb2.CommandHeader.Request()
header.device_id = device_id
ts = timestamp_pb2.Timestamp()
ts.GetCurrentTime()
header.timestamp.CopyFrom(ts)
# Construct CalibrateZeroQ request
req = pb.CalibrateZeroQ.Request(
header=header,
joint_name=joint_name
)
# Call RPC
try:
resp = self.stub.calibrateZeroQ(req, timeout=10)
feedback = resp.header
print(f"calibrateZeroQ joint: {joint_name}, device: {device_id}")
print(f"Success: {feedback.success}")
print(f"Error message: {feedback.error_message}")
print(f"Timestamp: {feedback.timestamp.seconds}")
if feedback.success:
print("calibrateZeroQ succeeded")
return True
print(f"calibrateZeroQ failed: {feedback.error_message or 'Server reported failure'}")
return False
except Exception as e:
print("calibrateZeroQ RPC call failed:", e)
return False
if __name__ == "__main__":
# 创建命令行参数解析器
parser = argparse.ArgumentParser(description='Send calibrateZeroQ command to robot')
parser.add_argument('--device_id', type=str, default='right_arm',
help='Device ID (default: right_arm)')
parser.add_argument('--joint_name', type=str, required=True,
help='Joint name to calibrate zero position')
# 解析命令行参数
args = parser.parse_args()
if not args.joint_name.strip():
parser.error("--joint_name must not be empty")
# 初始化客户端
client = CalibrateZeroQClient()
# 发送calibrateZeroQ命令,使用命令行传入的参数
try:
success = client.send(device_id=args.device_id, joint_name=args.joint_name)
finally:
# 关闭客户端
client.close()
raise SystemExit(0 if success else 1)