新增日志调试模式,并精简代码
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
|
LastEditTime: 2023-12-05 17:01:44
|
||||||
FilePath: /wzx/zkmetaapi/wukong/ZKMetaUnit/ZKMeta.py
|
FilePath: /wzx/zkmetaapi/wukong/ZKMetaUnit/ZKMeta.py
|
||||||
'''
|
'''
|
||||||
import os, sys
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import logging
|
||||||
from typing import List
|
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")
|
sys.path.append("/home/unitree/alg/prejects/ZK-AI/zkdog/ZKDogApi/src")
|
||||||
import robot_interface as sdk
|
import robot_interface as sdk
|
||||||
|
|
||||||
HIGHLEVEL = 0xee
|
HIGHLEVEL = 0xee
|
||||||
LOWLEVEL = 0xff
|
LOWLEVEL = 0xff
|
||||||
|
|
||||||
# cmake -DPYTHON_LIBRARY=/home/unitree/python3.8/lib \
|
logger = logging.getLogger(__name__)
|
||||||
# -DPYTHON_INCLUDE_DIR=/home/unitree/python3.8/include/python3.8 \
|
logging.basicConfig(format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||||
# -DPYTHON_EXECUTABLE=/home/unitree/python3.8/bin/python3.8 \
|
|
||||||
# ..
|
|
||||||
|
|
||||||
class ZKDOG:
|
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.udp = sdk.UDP(HIGHLEVEL, 8080, "192.168.123.161", 8082)
|
||||||
self.MQTT = MQTT()
|
self.MQTT = MQTT()
|
||||||
self.cmd = sdk.HighCmd()
|
self.cmd = sdk.HighCmd()
|
||||||
|
@ -248,63 +249,60 @@ class ZKDOG:
|
||||||
def getcurrenrstate(self):
|
def getcurrenrstate(self):
|
||||||
return self.state.mode
|
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):
|
def turn_left(self, tag=90):
|
||||||
try:
|
return self.rolling(tag=tag)
|
||||||
res = self.rolling(tag=tag)
|
|
||||||
return {"type": res}
|
|
||||||
except Exception as e:
|
|
||||||
return {"type": False, "msg": e}
|
|
||||||
|
|
||||||
|
@handle_exception(lambda res: {"type": res})
|
||||||
def turn_right(self, tag=90):
|
def turn_right(self, tag=90):
|
||||||
try:
|
return self.rolling(tag=tag, yawSpeed=-1)
|
||||||
res = self.rolling(tag=tag, yawSpeed = -1)
|
|
||||||
return {"type": res}
|
|
||||||
except Exception as e:
|
|
||||||
return {"type": False, "msg": e}
|
|
||||||
|
|
||||||
|
@handle_exception(lambda res: {"type": res})
|
||||||
def up(self, tag=1):
|
def up(self, tag=1):
|
||||||
try:
|
return self.forward(distance=tag)
|
||||||
res = self.forward(distance=tag)
|
|
||||||
return {"type": res}
|
|
||||||
except Exception as e:
|
|
||||||
return {"type": False, "msg": e}
|
|
||||||
|
|
||||||
|
@handle_exception(lambda res: {"type": res})
|
||||||
def down(self, tag=1):
|
def down(self, tag=1):
|
||||||
try:
|
return self.forward(distance=tag, velocaity=[-1, 0])
|
||||||
res = self.forward(distance=tag, velocaity=[-1, 0])
|
|
||||||
return {"type": res}
|
|
||||||
except Exception as e:
|
|
||||||
return {"type": False, "msg": e}
|
|
||||||
|
|
||||||
|
@handle_exception(lambda res: {"type": True})
|
||||||
def bark(self, tag="bark"):
|
def bark(self, tag="bark"):
|
||||||
try:
|
if not os.system(f"ssh unitree@192.168.123.13 -t \'aplay -D plughw:2,0 /home/unitree/tmp/{tag}\'.wav"):
|
||||||
tag="bark"
|
return True
|
||||||
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}
|
|
||||||
|
|
||||||
|
@handle_exception(lambda res: {"type": res})
|
||||||
def sitdown(self, tag=1):
|
def sitdown(self, tag=1):
|
||||||
try:
|
return self.__sitdown()
|
||||||
res = self.__sitdown()
|
|
||||||
return {"type": res}
|
|
||||||
except Exception as e:
|
|
||||||
return {"type": False, "msg": e}
|
|
||||||
|
|
||||||
|
@handle_exception(lambda res: {"type": res})
|
||||||
def standup(self, tag=1):
|
def standup(self, tag=1):
|
||||||
try:
|
return self.__standup()
|
||||||
res = self.__standup()
|
|
||||||
return {"type": res}
|
|
||||||
except Exception as e:
|
|
||||||
return {"type": False, "msg": e}
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
zd = ZKDOG()
|
zd = ZKDOG(mode=False)
|
||||||
|
|
||||||
print(zd.down(tag=1))
|
# print(zd.down(tag=1))
|
||||||
print(zd.turn_right(tag=180))
|
# print(zd.turn_right(tag=180))
|
||||||
print(zd.up(tag=1))
|
print(zd.up(tag=1))
|
||||||
print(zd.down(tag=1))
|
print(zd.down(tag=1))
|
||||||
# zd.sitdown()
|
# zd.sitdown()
|
||||||
# zd.standup()
|
# zd.standup()
|
||||||
# zd.bark()
|
zd.bark()
|
Loading…
Reference in New Issue