Skip to content

Commit fe77775

Browse files
committed
more decoupling
1 parent 1762b1a commit fe77775

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

go2_simulation/simulation_node.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ def __init__(self):
8181
# LowCmd
8282
self.lowcmd = LowCmd()
8383

84-
def forward(self, lowstate: LowState, im: typing.Optional[Image] = None):
84+
for i in range(12):
85+
self.lowcmd.motor_cmd[i].dq = 0.0
86+
self.lowcmd.motor_cmd[i].tau = 0.0
87+
self.lowcmd.motor_cmd[i].kp = 40.0
88+
self.lowcmd.motor_cmd[i].kd = 1.0
89+
90+
def forward(self, lowstate: LowState, im: typing.Optional[Image] = None) -> LowCmd():
8591
if im:
8692
im = np.array(im.data).reshape(im.height,im.width)
8793
self.vobs[:] = (im / 255.) - 0.5
@@ -146,7 +152,12 @@ def forward(self, lowstate: LowState, im: typing.Optional[Image] = None):
146152
self.obs_history[:] = obs_history
147153
# self.rnn_hidden_in[:] = hidden_states_out
148154

149-
return self.q0 + (np.clip(self.actions.squeeze(), -4.8, 4.8) * .25)
155+
qdes = self.q0 + (np.clip(self.actions.squeeze(), -4.8, 4.8) * .25)
156+
157+
for i in range(12):
158+
self.lowcmd.motor_cmd[i].q = qdes[i]
159+
160+
return self.lowcmd
150161

151162

152163
class Go2Simulation(Node):
@@ -209,27 +220,20 @@ def __init__(self):
209220

210221

211222
def update(self):
212-
## Control robot
213-
if False:
214-
q_des = np.array([self.last_cmd_msg.motor_cmd[i].q for i in range(12)])
215-
v_des = np.array([self.last_cmd_msg.motor_cmd[i].dq for i in range(12)])
216-
tau_des = np.array([self.last_cmd_msg.motor_cmd[i].tau for i in range(12)])
217-
kp_des = np.array([self.last_cmd_msg.motor_cmd[i].kp for i in range(12)])
218-
kd_des = np.array([self.last_cmd_msg.motor_cmd[i].kd for i in range(12)])
223+
# Camera update
224+
if self.i == 0:
225+
self.last_cmd_msg = LowCmd()
226+
elif self.i % self.camera_decimation == 0:
227+
im = self.camera_update()
228+
self.last_cmd_msg = self.actor.forward(self.low_msg, im=im)
219229
else:
220-
# Camera update
221-
if self.i == 0:
222-
q_des = np.zeros(12)
223-
elif self.i % self.camera_decimation == 0:
224-
im = self.camera_update()
225-
q_des = self.actor.forward(self.low_msg, im=im)
226-
else:
227-
q_des = self.actor.forward(self.low_msg, im=None)
228-
229-
v_des = np.zeros(12)
230-
tau_des = np.zeros(12)
231-
kp_des = 40 * np.ones(12)
232-
kd_des = 1 * np.ones(12)
230+
self.last_cmd_msg = self.actor.forward(self.low_msg, im=None)
231+
232+
q_des = np.array([self.last_cmd_msg.motor_cmd[i].q for i in range(12)])
233+
v_des = np.array([self.last_cmd_msg.motor_cmd[i].dq for i in range(12)])
234+
tau_des = np.array([self.last_cmd_msg.motor_cmd[i].tau for i in range(12)])
235+
kp_des = np.array([self.last_cmd_msg.motor_cmd[i].kp for i in range(12)])
236+
kd_des = np.array([self.last_cmd_msg.motor_cmd[i].kd for i in range(12)])
233237

234238
for _ in range(self.low_level_sub_step):
235239
# Iterate to simulate motor internal controller

0 commit comments

Comments
 (0)