2 changed files with 62 additions and 9 deletions
@ -0,0 +1,47 @@ |
|||||
|
# for motion switcher |
||||
|
from unitree_sdk2py.core.channel import ChannelFactoryInitialize |
||||
|
from unitree_sdk2py.comm.motion_switcher.motion_switcher_client import MotionSwitcherClient |
||||
|
# for loco client |
||||
|
from unitree_sdk2py.g1.loco.g1_loco_client import LocoClient |
||||
|
import time |
||||
|
|
||||
|
# MotionSwitcher used to switch mode between debug mode and ai mode |
||||
|
class MotionSwitcher: |
||||
|
def __init__(self): |
||||
|
self.msc = MotionSwitcherClient() |
||||
|
self.msc.SetTimeout(5.0) |
||||
|
self.msc.Init() |
||||
|
|
||||
|
def Enter_Debug_Mode(self): |
||||
|
status, result = self.msc.CheckMode() |
||||
|
while result['name']: |
||||
|
self.msc.ReleaseMode() |
||||
|
status, result = self.msc.CheckMode() |
||||
|
time.sleep(1) |
||||
|
return status, result |
||||
|
|
||||
|
def Exit_Debug_Mode(self): |
||||
|
status, result = self.msc.SelectMode(nameOrAlias='ai') |
||||
|
return status, result |
||||
|
|
||||
|
class LocoClientWrapper: |
||||
|
def __init__(self): |
||||
|
self.client = LocoClient() |
||||
|
self.client.SetTimeout(1.0) |
||||
|
self.client.Init() |
||||
|
|
||||
|
def Enter_Damp_Mode(self): |
||||
|
self.client.Damp() |
||||
|
|
||||
|
def Move(self, vx, vy, vyaw): |
||||
|
self.client.Move(vx, vy, vyaw, continous_move=False) |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
ChannelFactoryInitialize(0) |
||||
|
ms = MotionSwitcher() |
||||
|
status, result = ms.Enter_Debug_Mode() |
||||
|
print("Enter debug mode:", status, result) |
||||
|
time.sleep(5) |
||||
|
status, result = ms.Exit_Debug_Mode() |
||||
|
print("Exit debug mode:", status, result) |
||||
|
time.sleep(2) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue