nepyope commited on
Commit
3b4d882
·
verified ·
1 Parent(s): d33e33c

Update sim/unitree_sdk2py_bridge.py

Browse files
Files changed (1) hide show
  1. sim/unitree_sdk2py_bridge.py +4 -34
sim/unitree_sdk2py_bridge.py CHANGED
@@ -16,21 +16,14 @@ from unitree_sdk2py.idl.default import (
16
  unitree_hg_msg_dds__HandState_ as HandState_default,
17
  )
18
  from unitree_sdk2py.idl.unitree_go.msg.dds_ import WirelessController_
19
- try:
20
- from unitree_sdk2py.idl.unitree_hg.msg.dds_ import HandCmd_, HandState_, OdoState_
21
- HAS_ODOSTATE = True
22
- except ImportError:
23
- from unitree_sdk2py.idl.unitree_hg.msg.dds_ import HandCmd_, HandState_
24
- OdoState_ = None
25
- HAS_ODOSTATE = False
26
- print("Warning: OdoState_ not available in unitree_sdk2py")
27
 
28
 
29
  class UnitreeSdk2Bridge:
30
  """
31
- This class is responsible for bridging the Unitree SDK2 with the Gr00t environment.
32
- It is responsible for sending and receiving messages to and from the Unitree SDK2.
33
- Both the body and hand are supported.
34
  """
35
 
36
  def __init__(self, config):
@@ -44,10 +37,6 @@ class UnitreeSdk2Bridge:
44
  unitree_hg_msg_dds__LowCmd_,
45
  unitree_hg_msg_dds__LowState_ as LowState_default,
46
  )
47
- try:
48
- from unitree_sdk2py.idl.default import unitree_hg_msg_dds__OdoState_ as OdoState_default
49
- except ImportError:
50
- OdoState_default = None
51
  from unitree_sdk2py.idl.unitree_hg.msg.dds_ import IMUState_, LowCmd_, LowState_
52
 
53
  self.low_cmd = unitree_hg_msg_dds__LowCmd_()
@@ -85,14 +74,6 @@ class UnitreeSdk2Bridge:
85
  self.low_state_puber = ChannelPublisher("rt/lowstate", LowState_)
86
  self.low_state_puber.Init()
87
 
88
- # Only create odo_state for supported robot types (if available)
89
- if ("g1" in robot_type or "h1-2" in robot_type) and HAS_ODOSTATE and OdoState_default:
90
- self.odo_state = OdoState_default()
91
- self.odo_state_puber = ChannelPublisher("rt/odostate", OdoState_)
92
- self.odo_state_puber.Init()
93
- else:
94
- self.odo_state = None
95
- self.odo_state_puber = None
96
  self.torso_imu_state = IMUState_default()
97
  self.torso_imu_puber = ChannelPublisher("rt/secondary_imu", IMUState_)
98
  self.torso_imu_puber.Init()
@@ -224,12 +205,6 @@ class UnitreeSdk2Bridge:
224
  raise NotImplementedError("Frame sensor data is not implemented yet.")
225
  else:
226
  # Get data from ground truth
227
- # Publish odo state only if available
228
- if self.odo_state is not None:
229
- self.odo_state.position[:] = obs["floating_base_pose"][:3]
230
- self.odo_state.linear_velocity[:] = obs["floating_base_vel"][:3]
231
- self.odo_state.orientation[:] = obs["floating_base_pose"][3:7]
232
- self.odo_state.angular_velocity[:] = obs["floating_base_vel"][3:6]
233
  # quaternion: w, x, y, z
234
  self.low_state.imu_state.quaternion[:] = obs["floating_base_pose"][3:7]
235
  # angular velocity
@@ -246,11 +221,6 @@ class UnitreeSdk2Bridge:
246
  self.low_state.tick = int(obs["time"] * 1e3)
247
  self.low_state_puber.Write(self.low_state)
248
 
249
- # Publish odo state only if available
250
- if self.odo_state is not None and self.odo_state_puber is not None:
251
- self.odo_state.tick = int(obs["time"] * 1e3)
252
- self.odo_state_puber.Write(self.odo_state)
253
-
254
  self.torso_imu_puber.Write(self.torso_imu_state)
255
 
256
  # publish hand state
 
16
  unitree_hg_msg_dds__HandState_ as HandState_default,
17
  )
18
  from unitree_sdk2py.idl.unitree_go.msg.dds_ import WirelessController_
19
+
20
+ from unitree_sdk2py.idl.unitree_hg.msg.dds_ import HandCmd_, HandState_
 
 
 
 
 
 
21
 
22
 
23
  class UnitreeSdk2Bridge:
24
  """
25
+ Bridge between Unitree SDK2 and the MuJoCo simulation.
26
+ Handles sending and receiving DDS messages for body and hand control.
 
27
  """
28
 
29
  def __init__(self, config):
 
37
  unitree_hg_msg_dds__LowCmd_,
38
  unitree_hg_msg_dds__LowState_ as LowState_default,
39
  )
 
 
 
 
40
  from unitree_sdk2py.idl.unitree_hg.msg.dds_ import IMUState_, LowCmd_, LowState_
41
 
42
  self.low_cmd = unitree_hg_msg_dds__LowCmd_()
 
74
  self.low_state_puber = ChannelPublisher("rt/lowstate", LowState_)
75
  self.low_state_puber.Init()
76
 
 
 
 
 
 
 
 
 
77
  self.torso_imu_state = IMUState_default()
78
  self.torso_imu_puber = ChannelPublisher("rt/secondary_imu", IMUState_)
79
  self.torso_imu_puber.Init()
 
205
  raise NotImplementedError("Frame sensor data is not implemented yet.")
206
  else:
207
  # Get data from ground truth
 
 
 
 
 
 
208
  # quaternion: w, x, y, z
209
  self.low_state.imu_state.quaternion[:] = obs["floating_base_pose"][3:7]
210
  # angular velocity
 
221
  self.low_state.tick = int(obs["time"] * 1e3)
222
  self.low_state_puber.Write(self.low_state)
223
 
 
 
 
 
 
224
  self.torso_imu_puber.Write(self.torso_imu_state)
225
 
226
  # publish hand state