This commit is contained in:
LuoBin 2024-09-02 14:34:41 +08:00
parent bd24b5be05
commit fa4cbef093
9 changed files with 556 additions and 1 deletions

View File

@ -1,4 +1,4 @@
from . import idl, utils, core, rpc, go2
from . import idl, utils, core, rpc, go2, b2
__all__ = [
"idl"
@ -6,4 +6,5 @@ __all__ = [
"core",
"rpc",
"go2",
"b2",
]

View File

@ -0,0 +1,25 @@
"""
" service name
"""
ROBOT_STATE_SERVICE_NAME = "robot_state"
"""
" service api version
"""
ROBOT_STATE_API_VERSION = "1.0.0.1"
"""
" api id
"""
ROBOT_STATE_API_ID_SERVICE_SWITCH = 1001
ROBOT_STATE_API_ID_REPORT_FREQ = 1002
ROBOT_STATE_API_ID_SERVICE_LIST = 1003
"""
" error code
"""
ROBOT_STATE_ERR_SERVICE_SWITCH = 5201
ROBOT_STATE_ERR_SERVICE_PROTECTED = 5202

View File

@ -0,0 +1,84 @@
import json
from ...rpc.client import Client
from ...rpc.client_internal import *
from .robot_state_api import *
"""
" class ServiceState
"""
class ServiceState:
def __init__(self, name: str = None, status: int = None, protect: bool = None):
self.name = name
self.status = status
self.protect = protect
"""
" class RobotStateClient
"""
class RobotStateClient(Client):
def __init__(self):
super().__init__(ROBOT_STATE_SERVICE_NAME, False)
def Init(self):
# set api version
self._SetApiVerson(ROBOT_STATE_API_VERSION)
# regist api
self._RegistApi(ROBOT_STATE_API_ID_SERVICE_SWITCH, 0)
self._RegistApi(ROBOT_STATE_API_ID_REPORT_FREQ, 0)
self._RegistApi(ROBOT_STATE_API_ID_SERVICE_LIST, 0)
def ServiceList(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(ROBOT_STATE_API_ID_SERVICE_LIST, parameter)
if code != 0:
return code, None
lst = []
d = json.loads(data)
for t in d:
s = ServiceState()
s.name = t["name"]
s.status = t["status"]
s.protect = t["protect"]
lst.append(s)
return code, lst
def ServiceSwitch(self, name: str, switch: bool):
p = {}
p["name"] = name
p["switch"] = int(switch)
parameter = json.dumps(p)
code, data = self._Call(ROBOT_STATE_API_ID_SERVICE_SWITCH, parameter)
if code != 0:
return code
d = json.loads(data)
status = d["status"]
if status == 5:
return ROBOT_STATE_ERR_SERVICE_PROTECTED
if status != 0 and status != 1:
return ROBOT_STATE_ERR_SERVICE_SWITCH
return code
def SetReportFreq(self, interval: int, duration: int):
p = {}
p["interval"] = interval
p["duration"] = duration
parameter = json.dumps(p)
code, data = self._Call(ROBOT_STATE_API_ID_REPORT_FREQ, p)
return code

View File

@ -0,0 +1,58 @@
"""
" service name
"""
SPORT_SERVICE_NAME = "sport"
"""
" service api version
"""
SPORT_API_VERSION = "1.0.0.1"
"""
" api id
"""
SPORT_API_ID_DAMP = 1001;
SPORT_API_ID_BALANCESTAND = 1002;
SPORT_API_ID_STOPMOVE = 1003;
SPORT_API_ID_STANDUP = 1004;
SPORT_API_ID_STANDDOWN = 1005;
SPORT_API_ID_RECOVERYSTAND = 1006;
SPORT_API_ID_EULER = 1007;
SPORT_API_ID_MOVE = 1008;
SPORT_API_ID_SIT = 1009;
SPORT_API_ID_RISESIT = 1010;
SPORT_API_ID_SWITCHGAIT = 1011;
SPORT_API_ID_TRIGGER = 1012;
SPORT_API_ID_BODYHEIGHT = 1013;
SPORT_API_ID_FOOTRAISEHEIGHT = 1014;
SPORT_API_ID_SPEEDLEVEL = 1015;
SPORT_API_ID_HELLO = 1016;
SPORT_API_ID_STRETCH = 1017;
SPORT_API_ID_TRAJECTORYFOLLOW = 1018;
SPORT_API_ID_CONTINUOUSGAIT = 1019;
SPORT_API_ID_CONTENT = 1020;
SPORT_API_ID_WALLOW = 1021;
SPORT_API_ID_DANCE1 = 1022;
SPORT_API_ID_DANCE2 = 1023;
SPORT_API_ID_GETBODYHEIGHT = 1024;
SPORT_API_ID_GETFOOTRAISEHEIGHT = 1025;
SPORT_API_ID_GETSPEEDLEVEL = 1026;
SPORT_API_ID_SWITCHJOYSTICK = 1027;
SPORT_API_ID_POSE = 1028;
SPORT_API_ID_FRONTJUMP = 1031;
SPORT_API_ID_ECONOMICGAIT = 1035;
SPORT_API_ID_MOVETOPOS = 1036;
SPORT_API_ID_SWITCHEULERMODE = 1037;
SPORT_API_ID_SWITCHMOVEMODE = 1038;
"""
" error code
"""
# client side
SPORT_ERR_CLIENT_POINT_PATH = 4101
# server side
SPORT_ERR_SERVER_OVERTIME = 4201
SPORT_ERR_SERVER_NOT_INIT = 4202

View File

@ -0,0 +1,241 @@
import json
from ...rpc.client import Client
from .sport_api import *
"""
" SPORT_PATH_POINT_SIZE
"""
SPORT_PATH_POINT_SIZE = 30
"""
" class PathPoint
"""
class PathPoint:
def __init__(self, timeFromStart: float, x: float, y: float, yaw: float, vx: float, vy: float, vyaw: float):
self.timeFromStart = timeFromStart
self.x = x
self.y = y
self.yaw = yaw
self.vx = vx
self.vy = vy
self.vyaw = vyaw
"""
" class SportClient
"""
class SportClient(Client):
def __init__(self, enableLease: bool = False):
super().__init__(SPORT_SERVICE_NAME, enableLease)
def Init(self):
# set api version
self._SetApiVerson(SPORT_API_VERSION)
# regist api
self._RegistApi(SPORT_API_ID_DAMP, 0)
self._RegistApi(SPORT_API_ID_BALANCESTAND, 0)
self._RegistApi(SPORT_API_ID_STOPMOVE, 0)
self._RegistApi(SPORT_API_ID_STANDUP, 0)
self._RegistApi(SPORT_API_ID_STANDDOWN, 0)
self._RegistApi(SPORT_API_ID_RECOVERYSTAND, 0)
self._RegistApi(SPORT_API_ID_EULER, 0)
self._RegistApi(SPORT_API_ID_MOVE, 0)
self._RegistApi(SPORT_API_ID_SIT, 0)
self._RegistApi(SPORT_API_ID_SWITCHGAIT, 0)
self._RegistApi(SPORT_API_ID_BODYHEIGHT, 0)
self._RegistApi(SPORT_API_ID_FOOTRAISEHEIGHT, 0)
self._RegistApi(SPORT_API_ID_SPEEDLEVEL, 0)
self._RegistApi(SPORT_API_ID_TRAJECTORYFOLLOW, 0)
self._RegistApi(SPORT_API_ID_CONTINUOUSGAIT, 0)
self._RegistApi(SPORT_API_ID_MOVETOPOS, 0)
self._RegistApi(SPORT_API_ID_FRONTJUMP, 0)
self._RegistApi(SPORT_API_ID_ECONOMICGAIT, 0)
self._RegistApi(SPORT_API_ID_POSE, 0)
self._RegistApi(SPORT_API_ID_SWITCHEULERMODE, 0)
self._RegistApi(SPORT_API_ID_SWITCHMOVEMODE, 0)
# 1001
def Damp(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_DAMP, parameter)
return code
# 1002
def BalanceStand(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_BALANCESTAND, parameter)
return code
# 1003
def StopMove(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_STOPMOVE, parameter)
return code
# 1004
def StandUp(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_STANDUP, parameter)
return code
# 1005
def StandDown(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_STANDDOWN, parameter)
return code
# 1006
def RecoveryStand(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_RECOVERYSTAND, parameter)
return code
# 1007
def Euler(self, roll: float, pitch: float, yaw: float):
p = {}
p["x"] = roll
p["y"] = pitch
p["z"] = yaw
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_EULER, parameter)
return code
# 1008
def Move(self, vx: float, vy: float, vyaw: float):
p = {}
p["x"] = vx
p["y"] = vy
p["z"] = vyaw
parameter = json.dumps(p)
code = self._CallNoReply(SPORT_API_ID_MOVE, parameter)
return code
# 1009
def Sit(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_SIT, parameter)
return code
# 1011
def SwitchGait(self, t: int):
p = {}
p["data"] = t
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_SWITCHGAIT, parameter)
return code
# 1013
def BodyHeight(self, height: float):
p = {}
p["data"] = height
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_BODYHEIGHT, parameter)
return code
# 1014
def FootRaiseHeight(self, height: float):
p = {}
p["data"] = height
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_FOOTRAISEHEIGHT, parameter)
return code
# 1015
def SpeedLevel(self, level: int):
p = {}
p["data"] = level
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_SPEEDLEVEL, parameter)
return code
# 1018
def TrajectoryFollow(self, path: list):
l = len(path)
if l != SPORT_PATH_POINT_SIZE:
return SPORT_ERR_CLIENT_POINT_PATH
path_p = []
for i in range(l):
point = path[i]
p = {}
p["t_from_start"] = point.timeFromStart
p["x"] = point.x
p["y"] = point.y
p["yaw"] = point.yaw
p["vx"] = point.vx
p["vy"] = point.vy
p["vyaw"] = point.vyaw
path_p.append(p)
parameter = json.dumps(path_p)
code = self._CallNoReply(SPORT_API_ID_TRAJECTORYFOLLOW, parameter)
return code
# 1019
def ContinuousGait(self, flag: int):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_CONTINUOUSGAIT, parameter)
return code
# 1036
def MoveToPos(self, x: float, y: float, yaw: float):
p = {}
p["x"] = x
p["y"] = y
p["yaw"] = yaw
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_MOVETOPOS, parameter)
return code
# 1031
def FrontJump(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_FRONTJUMP, parameter)
return code
# 1035
def EconomicGait(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_ECONOMICGAIT, parameter)
return code
# 1028
def Pose(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_POSE, parameter)
return code
# 1037
def SwitchEulerMode(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_SWITCHEULERMODE, parameter)
return code
# 1038
def SwitchMoveMode(self, flag: bool):
p = {}
p["data"] = flag
parameter = json.dumps(p)
code, data = self._Call(SPORT_API_ID_SWITCHMOVEMODE, parameter)
return code

View File

@ -0,0 +1,16 @@
"""
" service name
"""
VIDEO_SERVICE_NAME = "videohub"
"""
" service api version
"""
VIDEO_API_VERSION = "1.0.0.1"
"""
" api id
"""
VIDEO_API_ID_GETIMAGESAMPLE = 1001

View File

@ -0,0 +1,23 @@
import json
from ...rpc.client import Client
from .video_api import *
"""
" class VideoClient
"""
class VideoClient(Client):
def __init__(self):
super().__init__(VIDEO_SERVICE_NAME, False)
def Init(self):
# set api version
self._SetApiVerson(VIDEO_API_VERSION)
# regist api
self._RegistApi(VIDEO_API_ID_GETIMAGESAMPLE, 0)
# 1001
def GetImageSample(self):
return self._CallBinary(VIDEO_API_ID_GETIMAGESAMPLE, [])

View File

@ -0,0 +1,21 @@
"""
" service name
"""
VUI_SERVICE_NAME = "vui"
"""
" service api version
"""
VUI_API_VERSION = "1.0.0.1"
"""
" api id
"""
VUI_API_ID_SETSWITCH = 1001
VUI_API_ID_GETSWITCH = 1002
VUI_API_ID_SETVOLUME = 1003
VUI_API_ID_GETVOLUME = 1004
VUI_API_ID_SETBRIGHTNESS = 1005
VUI_API_ID_GETBRIGHTNESS = 1006

View File

@ -0,0 +1,86 @@
import json
from ...rpc.client import Client
from .vui_api import *
"""
" class VideoClient
"""
class VuiClient(Client):
def __init__(self):
super().__init__(VUI_SERVICE_NAME, False)
def Init(self):
# set api version
self._SetApiVerson(VUI_API_VERSION)
# regist api
self._RegistApi(VUI_API_ID_SETSWITCH, 0)
self._RegistApi(VUI_API_ID_GETSWITCH, 0)
self._RegistApi(VUI_API_ID_SETVOLUME, 0)
self._RegistApi(VUI_API_ID_GETVOLUME, 0)
self._RegistApi(VUI_API_ID_SETBRIGHTNESS, 0)
self._RegistApi(VUI_API_ID_GETBRIGHTNESS, 0)
# 1001
def SetSwitch(self, enable: int):
p = {}
p["enable"] = enable
parameter = json.dumps(p)
code, data = self._Call(VUI_API_ID_SETSWITCH, parameter)
return code
# 1002
def GetSwitch(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(VUI_API_ID_GETSWITCH, parameter)
if code == 0:
d = json.loads(data)
return code, d["enable"]
else:
return code, None
# 1003
def SetVolume(self, level: int):
p = {}
p["volume"] = level
parameter = json.dumps(p)
code, data = self._Call(VUI_API_ID_SETVOLUME, parameter)
return code
# 1006
def GetVolume(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(VUI_API_ID_GETVOLUME, parameter)
if code == 0:
d = json.loads(data)
return code, d["volume"]
else:
return code, None
# 1005
def SetBrightness(self, level: int):
p = {}
p["brightness"] = level
parameter = json.dumps(p)
code, data = self._Call(VUI_API_ID_SETBRIGHTNESS, parameter)
return code
# 1006
def GetBrightness(self):
p = {}
parameter = json.dumps(p)
code, data = self._Call(VUI_API_ID_GETBRIGHTNESS, parameter)
if code == 0:
d = json.loads(data)
return code, d["brightness"]
else:
return code, None