Skip to content

Commit 0f17096

Browse files
committed
update g1 api and g1_loco_client_example example
1 parent 3d497a6 commit 0f17096

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

example/g1/high_level/g1_loco_client_example.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class TestOption:
2121
TestOption(name="move rotate", id=5),
2222
TestOption(name="low stand", id=6),
2323
TestOption(name="high stand", id=7),
24-
TestOption(name="zero torque", id=8)
24+
TestOption(name="zero torque", id=8),
25+
TestOption(name="wave hand1", id=9), # wave hand without turning around
26+
TestOption(name="wave hand2", id=10), # wave hand and trun around
27+
TestOption(name="shake hand", id=11),
2528
]
2629

2730
class UserInterface:
@@ -95,5 +98,13 @@ def terminal_handle(self):
9598
sport_client.HighStand()
9699
elif test_option.id == 8:
97100
sport_client.ZeroTorque()
101+
elif test_option.id == 9:
102+
sport_client.WaveHand()
103+
elif test_option.id == 10:
104+
sport_client.WaveHand(True)
105+
elif test_option.id == 11:
106+
sport_client.ShakeHand()
107+
time.sleep(3)
108+
sport_client.ShakeHand()
98109

99110
time.sleep(1)

unitree_sdk2py/g1/loco/g1_loco_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ROBOT_API_ID_LOCO_SET_SWING_HEIGHT = 7103
2626
ROBOT_API_ID_LOCO_SET_STAND_HEIGHT = 7104
2727
ROBOT_API_ID_LOCO_SET_VELOCITY = 7105
28+
ROBOT_API_ID_LOCO_SET_ARM_TASK = 7106
2829

2930
"""
3031
" error code

unitree_sdk2py/g1/loco/g1_loco_client.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class LocoClient(Client):
1010
def __init__(self):
1111
super().__init__(LOCO_SERVICE_NAME, False)
12-
12+
self.first_shake_hand_stage_ = -1
1313

1414
def Init(self):
1515
# set api version
@@ -28,6 +28,7 @@ def Init(self):
2828
self._RegistApi(ROBOT_API_ID_LOCO_SET_SWING_HEIGHT, 0)
2929
self._RegistApi(ROBOT_API_ID_LOCO_SET_STAND_HEIGHT, 0)
3030
self._RegistApi(ROBOT_API_ID_LOCO_SET_VELOCITY, 0)
31+
self._RegistApi(ROBOT_API_ID_LOCO_SET_ARM_TASK, 0)
3132

3233
# 7101
3334
def SetFsmId(self, fsm_id: int):
@@ -62,6 +63,14 @@ def SetVelocity(self, vx: float, vy: float, omega: float, duration: float = 1.0)
6263
parameter = json.dumps(p)
6364
code, data = self._Call(ROBOT_API_ID_LOCO_SET_VELOCITY, parameter)
6465
return code
66+
67+
# 7106
68+
def SetTaskId(self, task_id: float):
69+
p = {}
70+
p["data"] = task_id
71+
parameter = json.dumps(p)
72+
code, data = self._Call(ROBOT_API_ID_LOCO_SET_ARM_TASK, parameter)
73+
return code
6574

6675
def Damp(self):
6776
self.SetFsmId(1)
@@ -98,4 +107,18 @@ def Move(self, vx: float, vy: float, vyaw: float, continous_move: bool = False):
98107

99108
def BalanceStand(self, balance_mode: int):
100109
self.SetBalanceMode(balance_mode)
110+
111+
def WaveHand(self, turn_flag: bool = False):
112+
self.SetTaskId(1 if turn_flag else 0)
113+
114+
def ShakeHand(self, stage: int = -1):
115+
if stage == 0:
116+
self.first_shake_hand_stage_ = False
117+
self.SetTaskId(2)
118+
elif stage == 1:
119+
self.first_shake_hand_stage_ = True
120+
self.SetTaskId(3)
121+
else:
122+
self.first_shake_hand_stage_ = not self.first_shake_hand_stage_
123+
return self.SetTaskId(3 if self.first_shake_hand_stage_ else 2)
101124

0 commit comments

Comments
 (0)