add move api of obstacles_avoid

This commit is contained in:
yangning wu 2024-09-04 20:04:11 +08:00
parent 2609e6fd2f
commit f5bfa089b0
4 changed files with 52 additions and 2 deletions

View File

@ -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)

View File

@ -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

View File

@ -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
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