unitree_sdk2_python/example/obstacles_avoid/obstacles_avoid_move.py

35 lines
943 B
Python
Raw Normal View History

2024-09-04 20:04:11 +08:00
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)
2024-09-25 21:13:33 +08:00
try:
client = ObstaclesAvoidClient()
client.SetTimeout(3.0)
client.Init()
2024-09-04 20:04:11 +08:00
2024-09-25 21:13:33 +08:00
while not client.SwitchGet()[1]:
client.SwitchSet(True)
time.sleep(0.1)
2024-09-04 20:04:11 +08:00
2024-09-25 21:13:33 +08:00
print("obstacles avoid switch on")
2024-09-04 20:04:11 +08:00
2024-09-25 21:13:33 +08:00
client.UseRemoteCommandFromApi(True)
time.sleep(0.5)
2024-09-04 20:04:11 +08:00
client.Move(0.5, 0.0, 0.0)
2024-09-25 21:13:33 +08:00
time.sleep(1.0) # move 1s
client.Move(0.0, 0.0, 0.0)
client.UseRemoteCommandFromApi(False)
except KeyboardInterrupt:
client.Move(0.0, 0.0, 0.0)
client.UseRemoteCommandFromApi(False)
print("exit!!")
2024-09-04 20:04:11 +08:00