-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxdeploy.py
More file actions
executable file
·84 lines (62 loc) · 2.23 KB
/
xdeploy.py
File metadata and controls
executable file
·84 lines (62 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import time
import sys
import mujoco
import mujoco.viewer
from threading import Thread
import threading
from unitree_sdk2py.core.channel import ChannelFactoryInitialize
from unitree_sdk2py_bridge import UnitreeSdk2Bridge, ElasticBand
import scripts.config_PBHC as config_PBHC
from ipdb import set_trace as xxxx
locker = threading.Lock()
mj_model = mujoco.MjModel.from_xml_path(config_PBHC.ROBOT_SCENE)
mj_data = mujoco.MjData(mj_model)
if config_PBHC.ENABLE_ELASTIC_BAND:
elastic_band = ElasticBand()
if config_PBHC.ROBOT == "h1" or config_PBHC.ROBOT == "g1":
band_attached_link = mj_model.body("torso_link").id
else:
band_attached_link = mj_model.body("base_link").id
viewer = mujoco.viewer.launch_passive(
mj_model, mj_data, key_callback=elastic_band.MujuocoKeyCallback
)
else:
viewer = mujoco.viewer.launch_passive(mj_model, mj_data)
mj_model.opt.timestep = config_PBHC.SIMULATE_DT
num_motor_ = mj_model.nu
dim_motor_sensor_ = 3 * num_motor_
time.sleep(0.2)
def SimulationThread():
global mj_data, mj_model
if len(sys.argv)>1:
ChannelFactoryInitialize(0, sys.argv[1])
else:
ChannelFactoryInitialize(0)
unitree = UnitreeSdk2Bridge(mj_model, mj_data, config_PBHC.RUN_MODE)
if config_PBHC.USE_JOYSTICK:
unitree.SetupJoystick(device_id=0, js_type=config_PBHC.JOYSTICK_TYPE)
if config_PBHC.PRINT_SCENE_INFORMATION:
unitree.PrintSceneInformation()
while viewer.is_running():
step_start = time.perf_counter()
locker.acquire()
## main loop
# TODO
## main loop
locker.release()
time_until_next_step = mj_model.opt.timestep - (
time.perf_counter() - step_start
)
if time_until_next_step > 0:
time.sleep(time_until_next_step)
def PhysicsViewerThread():
while viewer.is_running():
locker.acquire()
viewer.sync()
locker.release()
time.sleep(config_PBHC.VIEWER_DT)
if __name__ == "__main__":
viewer_thread = Thread(target=PhysicsViewerThread)
sim_thread = Thread(target=SimulationThread)
viewer_thread.start()
sim_thread.start()