Skip to content

Commit 3d497a6

Browse files
committed
add new APIs for go2 sport client and update go2_sport_client example
1 parent 0d86c54 commit 3d497a6

3 files changed

Lines changed: 157 additions & 1 deletion

File tree

example/go2/high_level/go2_sport_client.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ class TestOption:
2727
TestOption(name="switch_gait", id=7),
2828
TestOption(name="switch_gait", id=8),
2929
TestOption(name="balanced stand", id=9),
30-
TestOption(name="recovery", id=10)
30+
TestOption(name="recovery", id=10),
31+
TestOption(name="recovery", id=10),
32+
TestOption(name="left flip", id=11),
33+
TestOption(name="back flip", id=12),
34+
TestOption(name="free walk", id=13),
35+
TestOption(name="free bound", id=14),
36+
TestOption(name="free avoid", id=15),
37+
TestOption(name="walk stair", id=16),
38+
TestOption(name="walk upright", id=17),
39+
TestOption(name="cross step", id=18),
40+
TestOption(name="free jump", id=19)
3141
]
3242

3343
class UserInterface:
@@ -105,5 +115,56 @@ def terminal_handle(self):
105115
sport_client.BalanceStand()
106116
elif test_option.id == 10:
107117
sport_client.RecoveryStand()
118+
elif test_option.id == 11:
119+
ret = sport_client.LeftFlip()
120+
print("ret: ",ret)
121+
elif test_option.id == 12:
122+
ret = sport_client.BackFlip()
123+
print("ret: ",ret)
124+
elif test_option.id == 13:
125+
ret = sport_client.FreeWalk(True)
126+
print("ret: ",ret)
127+
elif test_option.id == 14:
128+
ret = sport_client.FreeBound(True)
129+
print("ret: ",ret)
130+
time.sleep(2)
131+
ret = sport_client.FreeBound(False)
132+
print("ret: ",ret)
133+
elif test_option.id == 14:
134+
ret = sport_client.FreeBound(True)
135+
print("ret: ",ret)
136+
time.sleep(2)
137+
ret = sport_client.FreeBound(False)
138+
print("ret: ",ret)
139+
elif test_option.id == 15:
140+
ret = sport_client.FreeAvoid(True)
141+
print("ret: ",ret)
142+
time.sleep(2)
143+
ret = sport_client.FreeAvoid(False)
144+
print("ret: ",ret)
145+
elif test_option.id == 16:
146+
ret = sport_client.WalkStair(True)
147+
print("ret: ",ret)
148+
time.sleep(10)
149+
ret = sport_client.WalkStair(False)
150+
print("ret: ",ret)
151+
elif test_option.id == 17:
152+
ret = sport_client.WalkUpright(True)
153+
print("ret: ",ret)
154+
time.sleep(4)
155+
ret = sport_client.WalkUpright(False)
156+
print("ret: ",ret)
157+
elif test_option.id == 18:
158+
ret = sport_client.CrossStep(True)
159+
print("ret: ",ret)
160+
time.sleep(4)
161+
ret = sport_client.CrossStep(False)
162+
print("ret: ",ret)
163+
elif test_option.id == 19:
164+
ret = sport_client.FreeJump(True)
165+
print("ret: ",ret)
166+
time.sleep(4)
167+
ret = sport_client.FreeJump(False)
168+
print("ret: ",ret)
108169

109170
time.sleep(1)

unitree_sdk2py/go2/sport/sport_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,20 @@
4949
SPORT_API_ID_GETSTATE = 1034
5050
SPORT_API_ID_ECONOMICGAIT = 1035
5151
SPORT_API_ID_HEART = 1036
52+
ROBOT_SPORT_API_ID_DANCE3 = 1037
53+
ROBOT_SPORT_API_ID_DANCE4 = 1038
54+
ROBOT_SPORT_API_ID_HOPSPINLEFT = 1039
55+
ROBOT_SPORT_API_ID_HOPSPINRIGHT = 1040
5256

57+
ROBOT_SPORT_API_ID_LEFTFLIP = 1042
58+
ROBOT_SPORT_API_ID_BACKFLIP = 1044
59+
ROBOT_SPORT_API_ID_FREEWALK = 1045
60+
ROBOT_SPORT_API_ID_FREEBOUND = 1046
61+
ROBOT_SPORT_API_ID_FREEJUMP = 1047
62+
ROBOT_SPORT_API_ID_FREEAVOID = 1048
63+
ROBOT_SPORT_API_ID_WALKSTAIR = 1049
64+
ROBOT_SPORT_API_ID_WALKUPRIGHT = 1050
65+
ROBOT_SPORT_API_ID_CROSSSTEP = 1051
5366

5467
"""
5568
" error code

unitree_sdk2py/go2/sport/sport_client.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ def Init(self):
7373
self._RegistApi(SPORT_API_ID_ECONOMICGAIT, 0)
7474
self._RegistApi(SPORT_API_ID_HEART, 0)
7575

76+
self._RegistApi(ROBOT_SPORT_API_ID_LEFTFLIP, 0)
77+
self._RegistApi(ROBOT_SPORT_API_ID_BACKFLIP, 0)
78+
self._RegistApi(ROBOT_SPORT_API_ID_FREEWALK, 0)
79+
self._RegistApi(ROBOT_SPORT_API_ID_FREEBOUND, 0)
80+
self._RegistApi(ROBOT_SPORT_API_ID_FREEJUMP, 0)
81+
self._RegistApi(ROBOT_SPORT_API_ID_FREEAVOID, 0)
82+
self._RegistApi(ROBOT_SPORT_API_ID_WALKSTAIR, 0)
83+
self._RegistApi(ROBOT_SPORT_API_ID_WALKUPRIGHT, 0)
84+
self._RegistApi(ROBOT_SPORT_API_ID_CROSSSTEP, 0)
85+
7686
# 1001
7787
def Damp(self):
7888
p = {}
@@ -361,4 +371,76 @@ def Heart(self):
361371
p = {}
362372
parameter = json.dumps(p)
363373
code, data = self._Call(SPORT_API_ID_HEART, parameter)
374+
return code
375+
376+
# 1042
377+
def LeftFlip(self):
378+
p = {}
379+
p["data"] = True
380+
parameter = json.dumps(p)
381+
code, data = self._Call(ROBOT_SPORT_API_ID_LEFTFLIP, parameter)
382+
return code
383+
384+
# 1044
385+
def BackFlip(self):
386+
p = {}
387+
p["data"] = True
388+
parameter = json.dumps(p)
389+
code, data = self._Call(ROBOT_SPORT_API_ID_BACKFLIP, parameter)
390+
return code
391+
392+
# 1045
393+
def FreeWalk(self, flag: bool):
394+
p = {}
395+
p["data"] = True
396+
parameter = json.dumps(p)
397+
code, data = self._Call(ROBOT_SPORT_API_ID_FREEWALK, parameter)
398+
return code
399+
400+
# 1046
401+
def FreeBound(self, flag: bool):
402+
p = {}
403+
p["data"] = flag
404+
parameter = json.dumps(p)
405+
code, data = self._Call(ROBOT_SPORT_API_ID_FREEBOUND, parameter)
406+
return code
407+
408+
# 1047
409+
def FreeJump(self, flag: bool):
410+
p = {}
411+
p["data"] = flag
412+
parameter = json.dumps(p)
413+
code, data = self._Call(ROBOT_SPORT_API_ID_FREEJUMP, parameter)
414+
return code
415+
416+
# 1048
417+
def FreeAvoid(self, flag: bool):
418+
p = {}
419+
p["data"] = flag
420+
parameter = json.dumps(p)
421+
code, data = self._Call(ROBOT_SPORT_API_ID_FREEAVOID, parameter)
422+
return code
423+
424+
# 1049
425+
def WalkStair(self, flag: bool):
426+
p = {}
427+
p["data"] = flag
428+
parameter = json.dumps(p)
429+
code, data = self._Call(ROBOT_SPORT_API_ID_WALKSTAIR, parameter)
430+
return code
431+
432+
# 1050
433+
def WalkUpright(self, flag: bool):
434+
p = {}
435+
p["data"] = flag
436+
parameter = json.dumps(p)
437+
code, data = self._Call(ROBOT_SPORT_API_ID_WALKUPRIGHT, parameter)
438+
return code
439+
440+
# 1051
441+
def CrossStep(self, flag: bool):
442+
p = {}
443+
p["data"] = flag
444+
parameter = json.dumps(p)
445+
code, data = self._Call(ROBOT_SPORT_API_ID_CROSSSTEP, parameter)
364446
return code

0 commit comments

Comments
 (0)