Skip to content

Commit f5bfa08

Browse files
author
yangning wu
committed
add move api of obstacles_avoid
1 parent 2609e6f commit f5bfa08

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import time
2+
import sys
3+
4+
from unitree_sdk2py.core.channel import ChannelFactoryInitialize
5+
from unitree_sdk2py.go2.obstacles_avoid.obstacles_avoid_client import ObstaclesAvoidClient
6+
7+
if __name__ == "__main__":
8+
if len(sys.argv)>1:
9+
ChannelFactoryInitialize(0, sys.argv[1])
10+
else:
11+
ChannelFactoryInitialize(0)
12+
13+
client = ObstaclesAvoidClient()
14+
client.SetTimeout(3.0)
15+
client.Init()
16+
17+
client.SwitchSet(False)
18+
time.sleep(2)
19+
20+
client.SwitchSet(True)
21+
time.sleep(2)
22+
23+
client.UseRemoteCommandFromApi(True)
24+
time.sleep(2)
25+
while True:
26+
client.Move(0.5, 0.0, 0.0)
27+
time.sleep(0.02)
28+
File renamed without changes.

unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
"""
88
" service api version
99
"""
10-
OBSTACLES_AVOID_API_VERSION = "1.0.0.1"
10+
OBSTACLES_AVOID_API_VERSION = "1.0.0.2"
1111

1212

1313
"""
1414
" api id
1515
"""
1616
OBSTACLES_AVOID_API_ID_SWITCH_SET = 1001
1717
OBSTACLES_AVOID_API_ID_SWITCH_GET = 1002
18+
OBSTACLES_AVOID_API_ID_MOVE = 1003
19+
OBSTACLES_AVOID_API_ID_USE_REMOTE_COMMAND_FROM_API = 1004

unitree_sdk2py/go2/obstacles_avoid/obstacles_avoid_client.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def Init(self):
1717
# regist api
1818
self._RegistApi(OBSTACLES_AVOID_API_ID_SWITCH_SET, 0)
1919
self._RegistApi(OBSTACLES_AVOID_API_ID_SWITCH_GET, 0)
20+
self._RegistApi(OBSTACLES_AVOID_API_ID_MOVE, 0)
21+
self._RegistApi(OBSTACLES_AVOID_API_ID_USE_REMOTE_COMMAND_FROM_API, 0)
2022

2123
# 1001
2224
def SwitchSet(self, on: bool):
@@ -37,4 +39,22 @@ def SwitchGet(self):
3739
d = json.loads(data)
3840
return code, d["enable"]
3941
else:
40-
return code, None
42+
return code, None
43+
44+
# 1003
45+
def Move(self, vx: float, vy: float, vyaw: float):
46+
p = {}
47+
p["x"] = vx
48+
p["y"] = vy
49+
p["yaw"] = vyaw
50+
p["mode"] = 0
51+
parameter = json.dumps(p)
52+
code = self._CallNoReply(OBSTACLES_AVOID_API_ID_MOVE, parameter)
53+
return code
54+
55+
def UseRemoteCommandFromApi(self, isRemoteCommandsFromApi: bool):
56+
p = {}
57+
p["is_remote_commands_from_api"] = isRemoteCommandsFromApi
58+
parameter = json.dumps(p)
59+
code, data = self._Call(OBSTACLES_AVOID_API_ID_USE_REMOTE_COMMAND_FROM_API, parameter)
60+
return code

0 commit comments

Comments
 (0)