From f5bfa089b07026d3bb007a9530a3f21e380b1c92 Mon Sep 17 00:00:00 2001 From: yangning wu Date: Wed, 4 Sep 2024 20:04:11 +0800 Subject: [PATCH] add move api of obstacles_avoid --- .../obstacles_avoid/obstacles_avoid_move.py | 28 +++++++++++++++++++ .../obstacles_avoid_switch.py | 0 .../obstacles_avoid/obstacles_avoid_api.py | 4 ++- .../obstacles_avoid/obstacles_avoid_client.py | 22 ++++++++++++++- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 example/obstacles_avoid/obstacles_avoid_move.py rename example/{obstacles_avoid_switch => obstacles_avoid}/obstacles_avoid_switch.py (100%) diff --git a/example/obstacles_avoid/obstacles_avoid_move.py b/example/obstacles_avoid/obstacles_avoid_move.py new file mode 100644 index 0000000..32aa051 --- /dev/null +++ b/example/obstacles_avoid/obstacles_avoid_move.py @@ -0,0 +1,28 @@ +import time +import sys + +from unitree_sdk2py.core.channel import ChannelFactoryInitialize +from unitree_sdk2py.go2.obstacles_avoid.obstacles_avoid_client import ObstaclesAvoidClient + +if __name__ == "__main__": + if len(sys.argv)>1: + ChannelFactoryInitialize(0, sys.argv[1]) + else: + ChannelFactoryInitialize(0) + + client = ObstaclesAvoidClient() + client.SetTimeout(3.0) + client.Init() + + client.SwitchSet(False) + time.sleep(2) + + client.SwitchSet(True) + time.sleep(2) + + client.UseRemoteCommandFromApi(True) + time.sleep(2) + while True: + client.Move(0.5, 0.0, 0.0) + time.sleep(0.02) + \ No newline at end of file diff --git a/example/obstacles_avoid_switch/obstacles_avoid_switch.py b/example/obstacles_avoid/obstacles_avoid_switch.py similarity index 100% rename from example/obstacles_avoid_switch/obstacles_avoid_switch.py rename to example/obstacles_avoid/obstacles_avoid_switch.py diff --git a/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_api.py b/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_api.py index af0a50d..ad9dc06 100644 --- a/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_api.py +++ b/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_api.py @@ -7,7 +7,7 @@ OBSTACLES_AVOID_SERVICE_NAME = "obstacles_avoid" """ " service api version """ -OBSTACLES_AVOID_API_VERSION = "1.0.0.1" +OBSTACLES_AVOID_API_VERSION = "1.0.0.2" """ @@ -15,3 +15,5 @@ OBSTACLES_AVOID_API_VERSION = "1.0.0.1" """ OBSTACLES_AVOID_API_ID_SWITCH_SET = 1001 OBSTACLES_AVOID_API_ID_SWITCH_GET = 1002 +OBSTACLES_AVOID_API_ID_MOVE = 1003 +OBSTACLES_AVOID_API_ID_USE_REMOTE_COMMAND_FROM_API = 1004 \ No newline at end of file diff --git a/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_client.py b/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_client.py index d17dfda..4d7b62b 100644 --- a/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_client.py +++ b/unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_client.py @@ -17,6 +17,8 @@ class ObstaclesAvoidClient(Client): # regist api self._RegistApi(OBSTACLES_AVOID_API_ID_SWITCH_SET, 0) self._RegistApi(OBSTACLES_AVOID_API_ID_SWITCH_GET, 0) + self._RegistApi(OBSTACLES_AVOID_API_ID_MOVE, 0) + self._RegistApi(OBSTACLES_AVOID_API_ID_USE_REMOTE_COMMAND_FROM_API, 0) # 1001 def SwitchSet(self, on: bool): @@ -37,4 +39,22 @@ class ObstaclesAvoidClient(Client): d = json.loads(data) return code, d["enable"] else: - return code, None \ No newline at end of file + return code, None + + # 1003 + def Move(self, vx: float, vy: float, vyaw: float): + p = {} + p["x"] = vx + p["y"] = vy + p["yaw"] = vyaw + p["mode"] = 0 + parameter = json.dumps(p) + code = self._CallNoReply(OBSTACLES_AVOID_API_ID_MOVE, parameter) + return code + + def UseRemoteCommandFromApi(self, isRemoteCommandsFromApi: bool): + p = {} + p["is_remote_commands_from_api"] = isRemoteCommandsFromApi + parameter = json.dumps(p) + code, data = self._Call(OBSTACLES_AVOID_API_ID_USE_REMOTE_COMMAND_FROM_API, parameter) + return code \ No newline at end of file