add new APIs for go2 sport client and update go2_sport_client example

This commit is contained in:
xiaoliangstd 2025-01-13 14:49:59 +08:00
parent 0d86c54625
commit 3d497a606d
3 changed files with 157 additions and 1 deletions

View File

@ -27,7 +27,17 @@ option_list = [
TestOption(name="switch_gait", id=7),
TestOption(name="switch_gait", id=8),
TestOption(name="balanced stand", id=9),
TestOption(name="recovery", id=10)
TestOption(name="recovery", id=10),
TestOption(name="recovery", id=10),
TestOption(name="left flip", id=11),
TestOption(name="back flip", id=12),
TestOption(name="free walk", id=13),
TestOption(name="free bound", id=14),
TestOption(name="free avoid", id=15),
TestOption(name="walk stair", id=16),
TestOption(name="walk upright", id=17),
TestOption(name="cross step", id=18),
TestOption(name="free jump", id=19)
]
class UserInterface:
@ -105,5 +115,56 @@ if __name__ == "__main__":
sport_client.BalanceStand()
elif test_option.id == 10:
sport_client.RecoveryStand()
elif test_option.id == 11:
ret = sport_client.LeftFlip()
print("ret: ",ret)
elif test_option.id == 12:
ret = sport_client.BackFlip()
print("ret: ",ret)
elif test_option.id == 13:
ret = sport_client.FreeWalk(True)
print("ret: ",ret)
elif test_option.id == 14:
ret = sport_client.FreeBound(True)
print("ret: ",ret)
time.sleep(2)
ret = sport_client.FreeBound(False)
print("ret: ",ret)
elif test_option.id == 14:
ret = sport_client.FreeBound(True)
print("ret: ",ret)
time.sleep(2)
ret = sport_client.FreeBound(False)
print("ret: ",ret)
elif test_option.id == 15:
ret = sport_client.FreeAvoid(True)
print("ret: ",ret)
time.sleep(2)
ret = sport_client.FreeAvoid(False)
print("ret: ",ret)
elif test_option.id == 16:
ret = sport_client.WalkStair(True)
print("ret: ",ret)
time.sleep(10)
ret = sport_client.WalkStair(False)
print("ret: ",ret)
elif test_option.id == 17:
ret = sport_client.WalkUpright(True)
print("ret: ",ret)
time.sleep(4)
ret = sport_client.WalkUpright(False)
print("ret: ",ret)
elif test_option.id == 18:
ret = sport_client.CrossStep(True)
print("ret: ",ret)
time.sleep(4)
ret = sport_client.CrossStep(False)
print("ret: ",ret)
elif test_option.id == 19:
ret = sport_client.FreeJump(True)
print("ret: ",ret)
time.sleep(4)
ret = sport_client.FreeJump(False)
print("ret: ",ret)
time.sleep(1)

View File

@ -49,7 +49,20 @@ SPORT_API_ID_WIGGLEHIPS = 1033
SPORT_API_ID_GETSTATE = 1034
SPORT_API_ID_ECONOMICGAIT = 1035
SPORT_API_ID_HEART = 1036
ROBOT_SPORT_API_ID_DANCE3 = 1037
ROBOT_SPORT_API_ID_DANCE4 = 1038
ROBOT_SPORT_API_ID_HOPSPINLEFT = 1039
ROBOT_SPORT_API_ID_HOPSPINRIGHT = 1040
ROBOT_SPORT_API_ID_LEFTFLIP = 1042
ROBOT_SPORT_API_ID_BACKFLIP = 1044
ROBOT_SPORT_API_ID_FREEWALK = 1045
ROBOT_SPORT_API_ID_FREEBOUND = 1046
ROBOT_SPORT_API_ID_FREEJUMP = 1047
ROBOT_SPORT_API_ID_FREEAVOID = 1048
ROBOT_SPORT_API_ID_WALKSTAIR = 1049
ROBOT_SPORT_API_ID_WALKUPRIGHT = 1050
ROBOT_SPORT_API_ID_CROSSSTEP = 1051
"""
" error code

View File

@ -73,6 +73,16 @@ class SportClient(Client):
self._RegistApi(SPORT_API_ID_ECONOMICGAIT, 0)
self._RegistApi(SPORT_API_ID_HEART, 0)
self._RegistApi(ROBOT_SPORT_API_ID_LEFTFLIP, 0)
self._RegistApi(ROBOT_SPORT_API_ID_BACKFLIP, 0)
self._RegistApi(ROBOT_SPORT_API_ID_FREEWALK, 0)
self._RegistApi(ROBOT_SPORT_API_ID_FREEBOUND, 0)
self._RegistApi(ROBOT_SPORT_API_ID_FREEJUMP, 0)
self._RegistApi(ROBOT_SPORT_API_ID_FREEAVOID, 0)
self._RegistApi(ROBOT_SPORT_API_ID_WALKSTAIR, 0)
self._RegistApi(ROBOT_SPORT_API_ID_WALKUPRIGHT, 0)
self._RegistApi(ROBOT_SPORT_API_ID_CROSSSTEP, 0)
# 1001
def Damp(self):
p = {}
@ -362,3 +372,75 @@ class SportClient(Client):
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_HEART, parameter)
return code
# 1042
def LeftFlip(self):
p = {}
p["data"] = True
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_LEFTFLIP, parameter)
return code
# 1044
def BackFlip(self):
p = {}
p["data"] = True
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_BACKFLIP, parameter)
return code
# 1045
def FreeWalk(self, flag: bool):
p = {}
p["data"] = True
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_FREEWALK, parameter)
return code
# 1046
def FreeBound(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_FREEBOUND, parameter)
return code
# 1047
def FreeJump(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_FREEJUMP, parameter)
return code
# 1048
def FreeAvoid(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_FREEAVOID, parameter)
return code
# 1049
def WalkStair(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_WALKSTAIR, parameter)
return code
# 1050
def WalkUpright(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_WALKUPRIGHT, parameter)
return code
# 1051
def CrossStep(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(ROBOT_SPORT_API_ID_CROSSSTEP, parameter)
return code