2026-02-03 13:36:52 +08:00
|
|
|
from clients._path_setup import ensure_paths
|
2025-11-13 03:01:00 +08:00
|
|
|
|
2026-02-03 13:36:52 +08:00
|
|
|
ensure_paths()
|
2025-11-13 03:01:00 +08:00
|
|
|
|
2026-02-03 13:36:52 +08:00
|
|
|
from google.protobuf import timestamp_pb2
|
2025-11-13 03:01:00 +08:00
|
|
|
|
|
|
|
|
from clients.base_client import RobotClientBase
|
2026-02-03 13:36:52 +08:00
|
|
|
from cmvr.api import common_pb2
|
|
|
|
|
from cmvr.api import dexhand_command_pb2 as pb
|
2025-11-13 03:01:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
handshake = [
|
|
|
|
|
{"id": 0, "value": 0.0},
|
|
|
|
|
{"id": 1, "value": 0.0},
|
|
|
|
|
{"id": 2, "value": 0.0},
|
|
|
|
|
{"id": 3, "value": 0.0},
|
2026-02-02 09:37:47 +08:00
|
|
|
{"id": 4, "value": 0.0},
|
|
|
|
|
{"id": 5, "value": 1.0},
|
2025-11-13 03:01:00 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
hand_open = [
|
2026-02-02 09:37:47 +08:00
|
|
|
{"id": 0, "value": 0.7},
|
|
|
|
|
{"id": 1, "value": 0.7},
|
|
|
|
|
{"id": 2, "value": 0.7},
|
|
|
|
|
{"id": 3, "value": 0.7},
|
|
|
|
|
{"id": 4, "value": 0.7},
|
2025-11-13 03:01:00 +08:00
|
|
|
{"id": 5, "value": 1.0},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
handshake_1 = [
|
|
|
|
|
{"id": 0, "value": 0.0},
|
|
|
|
|
{"id": 1, "value": 0.0},
|
|
|
|
|
{"id": 2, "value": 0.0},
|
|
|
|
|
{"id": 3, "value": 0.0},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
hand_touch = [
|
|
|
|
|
{"id": 0, "value": 0},
|
|
|
|
|
{"id": 1, "value": 0},
|
|
|
|
|
{"id": 2, "value": 0},
|
|
|
|
|
{"id": 3, "value": 1.0},
|
|
|
|
|
{"id": 4, "value": 0.3},
|
|
|
|
|
{"id": 5, "value": 0.3},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
class DexHandClient(RobotClientBase):
|
|
|
|
|
"""DexHand control client"""
|
|
|
|
|
|
|
|
|
|
def set_angles(self, angles: list, device_id="hc01"):
|
|
|
|
|
"""
|
|
|
|
|
angles: list of dicts, e.g.,
|
|
|
|
|
[
|
|
|
|
|
{"id": 0, "value": 0.5},
|
|
|
|
|
{"id": 1, "value": 0.8},
|
|
|
|
|
...
|
|
|
|
|
]
|
|
|
|
|
device_id: device ID
|
|
|
|
|
"""
|
|
|
|
|
# Construct request header
|
|
|
|
|
header = common_pb2.CommandHeader.Request()
|
|
|
|
|
header.device_id = device_id
|
|
|
|
|
ts = timestamp_pb2.Timestamp()
|
|
|
|
|
ts.GetCurrentTime()
|
|
|
|
|
header.timestamp.CopyFrom(ts)
|
|
|
|
|
|
|
|
|
|
# Construct FreedomValue list
|
|
|
|
|
values = [pb.FreedomValue(id=a["id"], value=a["value"]) for a in angles]
|
|
|
|
|
|
|
|
|
|
# Construct request
|
|
|
|
|
req = pb.SetDexHandAnglesCommand.Request(
|
|
|
|
|
header=header,
|
|
|
|
|
values=values
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Call RPC
|
|
|
|
|
try:
|
|
|
|
|
resp = self.stub_hand.SetDexHandAngle(req, timeout=10)
|
|
|
|
|
print("SetDexHandAngle RPC call succeeded")
|
|
|
|
|
print(f"Success: {resp.header.success}")
|
|
|
|
|
print(f"Error message: {resp.header.error_message}")
|
|
|
|
|
print(f"Timestamp: {resp.header.timestamp.seconds}")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print("SetDexHandAngle RPC call failed:", e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# Initialize client
|
|
|
|
|
client = DexHandClient()
|
|
|
|
|
|
|
|
|
|
# Example: set finger angles
|
|
|
|
|
angles = [
|
|
|
|
|
{"id": 0, "value": 0.0},
|
|
|
|
|
{"id": 1, "value": 0.0},
|
|
|
|
|
{"id": 2, "value": 0.0},
|
|
|
|
|
{"id": 3, "value": 1.0},
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# angles = [
|
|
|
|
|
#
|
|
|
|
|
# {"id": 4, "value": 0.0},
|
|
|
|
|
# {"id": 5, "value": 1.0},
|
|
|
|
|
#
|
|
|
|
|
# ]
|
|
|
|
|
|
|
|
|
|
# client.set_angles(hand_open, device_id="hand2")
|
2026-06-17 09:36:26 +08:00
|
|
|
client.set_angles(hand_touch, device_id="hand2")
|
2025-11-13 03:01:00 +08:00
|
|
|
# client.set_angles(handshake, device_id="hand1")
|
|
|
|
|
|
|
|
|
|
# Close client
|
|
|
|
|
client.close()
|