新增日志调试模式,并精简代码
This commit is contained in:
parent
ab657425c8
commit
9a24dad17f
|
@ -5,24 +5,25 @@ LastEditors: WZX 17839623189@168.com
|
|||
LastEditTime: 2023-12-05 17:01:44
|
||||
FilePath: /wzx/zkmetaapi/wukong/ZKMetaUnit/ZKMeta.py
|
||||
'''
|
||||
import os, sys
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import math
|
||||
import logging
|
||||
from typing import List
|
||||
from .utils import MQTT, parse_robot_state, calcu_vecloty, calcu_distance
|
||||
from utils import MQTT, parse_robot_state, calcu_vecloty, calcu_distance
|
||||
sys.path.append("/home/unitree/alg/prejects/ZK-AI/zkdog/ZKDogApi/src")
|
||||
import robot_interface as sdk
|
||||
|
||||
HIGHLEVEL = 0xee
|
||||
LOWLEVEL = 0xff
|
||||
|
||||
# cmake -DPYTHON_LIBRARY=/home/unitree/python3.8/lib \
|
||||
# -DPYTHON_INCLUDE_DIR=/home/unitree/python3.8/include/python3.8 \
|
||||
# -DPYTHON_EXECUTABLE=/home/unitree/python3.8/bin/python3.8 \
|
||||
# ..
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||
|
||||
class ZKDOG:
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, mode=True) -> None:
|
||||
self.mode = mode # When mode is equal to false, it is debugging mode, no action is executed, and only logs are printed.
|
||||
self.udp = sdk.UDP(HIGHLEVEL, 8080, "192.168.123.161", 8082)
|
||||
self.MQTT = MQTT()
|
||||
self.cmd = sdk.HighCmd()
|
||||
|
@ -247,64 +248,61 @@ class ZKDOG:
|
|||
|
||||
def getcurrenrstate(self):
|
||||
return self.state.mode
|
||||
|
||||
|
||||
def handle_exception(callback):
|
||||
def decorator(func):
|
||||
def wrapper(self, *args, **kwargs):
|
||||
try:
|
||||
# print(args, kwargs, func)
|
||||
if self.mode:
|
||||
res = func(self, *args, **kwargs)
|
||||
logging.info(f"mode ==> {self.mode} && action {func} ==> {kwargs}")
|
||||
return callback(res)
|
||||
else:
|
||||
time.sleep(1)
|
||||
logging.info(f"mode ==> {self.mode} && action {func} ==> {kwargs}")
|
||||
return {"type": True}
|
||||
except Exception as e:
|
||||
return callback({"type": False, "msg": str(e)})
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
@handle_exception(lambda res: {"type": res})
|
||||
def turn_left(self, tag=90):
|
||||
try:
|
||||
res = self.rolling(tag=tag)
|
||||
return {"type": res}
|
||||
except Exception as e:
|
||||
return {"type": False, "msg": e}
|
||||
return self.rolling(tag=tag)
|
||||
|
||||
@handle_exception(lambda res: {"type": res})
|
||||
def turn_right(self, tag=90):
|
||||
try:
|
||||
res = self.rolling(tag=tag, yawSpeed = -1)
|
||||
return {"type": res}
|
||||
except Exception as e:
|
||||
return {"type": False, "msg": e}
|
||||
|
||||
return self.rolling(tag=tag, yawSpeed=-1)
|
||||
|
||||
@handle_exception(lambda res: {"type": res})
|
||||
def up(self, tag=1):
|
||||
try:
|
||||
res = self.forward(distance=tag)
|
||||
return {"type": res}
|
||||
except Exception as e:
|
||||
return {"type": False, "msg": e}
|
||||
return self.forward(distance=tag)
|
||||
|
||||
@handle_exception(lambda res: {"type": res})
|
||||
def down(self, tag=1):
|
||||
try:
|
||||
res = self.forward(distance=tag, velocaity=[-1, 0])
|
||||
return {"type": res}
|
||||
except Exception as e:
|
||||
return {"type": False, "msg": e}
|
||||
return self.forward(distance=tag, velocaity=[-1, 0])
|
||||
|
||||
@handle_exception(lambda res: {"type": True})
|
||||
def bark(self, tag="bark"):
|
||||
try:
|
||||
tag="bark"
|
||||
if not os.system(f"ssh unitree@192.168.123.13 -t 'aplay -D plughw:2,0 /home/unitree/tmp/{tag}'.wav"):
|
||||
return {"type": True}
|
||||
except Exception as e:
|
||||
return {"type": False, "msg": e}
|
||||
|
||||
def sitdown(self, tag=1):
|
||||
try:
|
||||
res = self.__sitdown()
|
||||
return {"type": res}
|
||||
except Exception as e:
|
||||
return {"type": False, "msg": e}
|
||||
if not os.system(f"ssh unitree@192.168.123.13 -t \'aplay -D plughw:2,0 /home/unitree/tmp/{tag}\'.wav"):
|
||||
return True
|
||||
|
||||
@handle_exception(lambda res: {"type": res})
|
||||
def sitdown(self, tag=1):
|
||||
return self.__sitdown()
|
||||
|
||||
@handle_exception(lambda res: {"type": res})
|
||||
def standup(self, tag=1):
|
||||
try:
|
||||
res = self.__standup()
|
||||
return {"type": res}
|
||||
except Exception as e:
|
||||
return {"type": False, "msg": e}
|
||||
return self.__standup()
|
||||
|
||||
if __name__=="__main__":
|
||||
zd = ZKDOG()
|
||||
zd = ZKDOG(mode=False)
|
||||
|
||||
print(zd.down(tag=1))
|
||||
print(zd.turn_right(tag=180))
|
||||
# print(zd.down(tag=1))
|
||||
# print(zd.turn_right(tag=180))
|
||||
print(zd.up(tag=1))
|
||||
print(zd.down(tag=1))
|
||||
# zd.sitdown()
|
||||
# zd.standup()
|
||||
# zd.bark()
|
||||
zd.bark()
|
Loading…
Reference in New Issue