Skip to content

Commit 4489a10

Browse files
edantecearlaud
authored andcommitted
Remove qp from python examples
1 parent 030b339 commit 4489a10

File tree

4 files changed

+18
-146
lines changed

4 files changed

+18
-146
lines changed

examples/go2_fulldynamics.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
RobotDataHandler,
66
FullDynamicsOCP,
77
MPC,
8-
IDSolver,
98
Interpolator,
109
FrictionCompensation
1110
)
@@ -48,12 +47,12 @@
4847
u0 = np.zeros(model_handler.getModel().nv - 6)
4948

5049
w_basepos = [0, 0, 0, 0, 0, 0]
51-
w_legpos = [10, 10, 10]
50+
w_legpos = [1, 1, 1]
5251

5352
w_basevel = [10, 10, 10, 10, 10, 10]
5453
w_legvel = [0.1, 0.1, 0.1]
5554
w_x = np.array(w_basepos + w_legpos * 4 + w_basevel + w_legvel * 4)
56-
w_cent_lin = np.array([0.0, 0.0, 0])
55+
w_cent_lin = np.array([0.04, 0.04, 0])
5756
w_cent_ang = np.array([0, 0, 0])
5857
w_forces_lin = np.array([0.0001, 0.0001, 0.0001])
5958
w_frame = np.diag(np.array([1000, 1000, 1000]))
@@ -140,24 +139,6 @@
140139

141140
mpc.generateCycleHorizon(contact_phases)
142141

143-
""" Initialize whole-body inverse dynamics QP"""
144-
contact_ids = model_handler.getFeetIds()
145-
id_conf = dict(
146-
contact_ids=contact_ids,
147-
x0=model_handler.getReferenceState(),
148-
mu=0.8,
149-
Lfoot=0.01,
150-
Wfoot=0.01,
151-
force_size=3,
152-
kd=0,
153-
w_force=0,
154-
w_acc=0,
155-
w_tau=1,
156-
verbose=False,
157-
)
158-
159-
qp = IDSolver(id_conf, model_handler.getModel())
160-
161142
""" Friction """
162143
fcompensation = FrictionCompensation(model_handler.getModel(), True)
163144
""" Interpolation """
@@ -288,19 +269,8 @@
288269
x_measured, x_interp
289270
)
290271

291-
qp.solveQP(
292-
mpc.getDataHandler().getData(),
293-
contact_states,
294-
x_measured[nq:],
295-
acc_interp,
296-
current_torque,
297-
force_interp,
298-
mpc.getDataHandler().getData().M,
299-
)
300-
301-
qp_torque = qp.solved_torque.copy()
302-
friction_torque = fcompensation.computeFriction(x_interp[nq + 6:], qp_torque)
303-
device.execute(friction_torque)
272+
friction_torque = fcompensation.computeFriction(x_interp[nq + 6:], current_torque)
273+
device.execute(current_torque)
304274

305275
u_multibody.append(copy.deepcopy(friction_torque))
306276
x_multibody.append(x_measured)

examples/go2_kinodynamics.py

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
from bullet_robot import BulletRobot
3-
from simple_mpc import RobotModelHandler, RobotDataHandler, KinodynamicsOCP, MPC, IDSolver, Interpolator
3+
from simple_mpc import RobotModelHandler, RobotDataHandler, KinodynamicsOCP, MPC, Interpolator
44
import example_robot_data as erd
55
import pinocchio as pin
66
import time
@@ -134,24 +134,6 @@
134134
contact_phases += [contact_phase_lift_FR] * T_ss
135135
mpc.generateCycleHorizon(contact_phases)
136136

137-
""" Initialize whole-body inverse dynamics QP"""
138-
contact_ids = model_handler.getFeetIds()
139-
id_conf = dict(
140-
contact_ids=contact_ids,
141-
x0=model_handler.getReferenceState(),
142-
mu=0.8,
143-
Lfoot=0.01,
144-
Wfoot=0.01,
145-
force_size=3,
146-
kd=0,
147-
w_force=100,
148-
w_acc=1,
149-
w_tau=0,
150-
verbose=False,
151-
)
152-
153-
qp = IDSolver(id_conf, model_handler.getModel())
154-
155137
""" Interpolation """
156138
interpolator = Interpolator(model_handler.getModel())
157139

@@ -266,19 +248,11 @@
266248

267249
mpc.getDataHandler().updateInternalData(x_measured, True)
268250

269-
qp.solveQP(
270-
mpc.getDataHandler().getData(),
271-
contact_states,
272-
x_measured[nq:],
273-
acc_interp,
274-
np.zeros(12),
275-
force_interp,
276-
mpc.getDataHandler().getData().M,
277-
)
251+
# TODO: use TSID to compute inverse dynamics and get tau_cmd
278252

279-
device.execute(qp.solved_torque)
280-
u_multibody.append(copy.deepcopy(qp.solved_torque))
281-
x_multibody.append(x_measured)
253+
#device.execute(tau_cmd)
254+
#u_multibody.append(copy.deepcopy(tau_cmd))
255+
#x_multibody.append(x_measured)
282256

283257

284258
force_FL = np.array(force_FL)
@@ -297,6 +271,6 @@
297271
com_measured = np.array(com_measured)
298272
L_measured = np.array(L_measured)
299273

300-
save_trajectory(x_multibody, u_multibody, com_measured, force_FL, force_FR, force_RL, force_RR, solve_time,
274+
""" save_trajectory(x_multibody, u_multibody, com_measured, force_FL, force_FR, force_RL, force_RR, solve_time,
301275
FL_measured, FR_measured, RL_measured, RR_measured,
302-
FL_references, FR_references, RL_references, RR_references, L_measured, "kinodynamics")
276+
FL_references, FR_references, RL_references, RR_references, L_measured, "kinodynamics") """

examples/talos_centroidal.py

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pinocchio as pin
33
import example_robot_data as erd
44
from bullet_robot import BulletRobot
5-
from simple_mpc import RobotModelHandler, RobotDataHandler, CentroidalOCP, MPC, IKIDSolver
5+
from simple_mpc import RobotModelHandler, RobotDataHandler, CentroidalOCP, MPC
66
from utils import loadTalos
77
import time
88

@@ -101,42 +101,6 @@
101101

102102
mpc.generateCycleHorizon(contact_phases)
103103

104-
""" Initialize inverse dynamics QP """
105-
g_basepos = [0, 0, 0, 10, 10, 10]
106-
g_legpos = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
107-
g_torsopos = [1, 1]
108-
g_armpos = [10, 10, 100, 10]
109-
110-
g_q = np.array(g_basepos + g_legpos * 2 + g_torsopos + g_armpos * 2) * 10
111-
112-
g_p = np.array([2000, 2000, 2000, 2000, 2000, 2000])
113-
g_b = np.array([10, 10, 10])
114-
115-
Kp_gains = [g_q, g_p, g_b]
116-
Kd_gains = [2 * np.sqrt(g_q), 2 * np.sqrt(g_p), 2 * np.sqrt(g_b)]
117-
contact_ids = model_handler.getFeetIds()
118-
fixed_frame_ids = [model_handler.getBaseFrameId(), model_handler.getModel().getFrameId("torso_2_link")]
119-
ikid_conf = dict(
120-
Kp_gains=Kp_gains,
121-
Kd_gains=Kd_gains,
122-
contact_ids=contact_ids,
123-
fixed_frame_ids=fixed_frame_ids,
124-
x0=model_handler.getReferenceState(),
125-
dt=0.01,
126-
mu=0.8,
127-
Lfoot=0.1,
128-
Wfoot=0.075,
129-
force_size=6,
130-
w_qref=500,
131-
w_footpose=50000,
132-
w_centroidal=10,
133-
w_baserot=1000,
134-
w_force=100,
135-
verbose=False,
136-
)
137-
138-
qp = IKIDSolver(ikid_conf, model_handler.getModel())
139-
140104
""" Initialize simulation"""
141105
device = BulletRobot(
142106
model_handler.getModel().names,
@@ -196,9 +160,6 @@
196160
foot_ref = [mpc.getReferencePose(0, name) for name in model_handler.getFeetNames()]
197161
foot_ref_next = [mpc.getReferencePose(1, name) for name in model_handler.getFeetNames()]
198162
dH = mpc.getStateDerivative(0)[3:9]
199-
qp.computeDifferences(
200-
mpc.getDataHandler().getData(), x_measured, foot_ref, foot_ref_next
201-
)
202163

203164
for j in range(10):
204165
time.sleep(0.001)
@@ -215,14 +176,7 @@
215176
)
216177

217178

218-
qp.solve_qp(
219-
mpc.getDataHandler().getData(),
220-
contact_states,
221-
x_measured[nq:],
222-
forces,
223-
dH,
224-
mpc.getDataHandler().getData().M,
225-
)
179+
# TODO: use TSID to compute inverse dynamics and get tau_cmd
226180

227181

228-
device.execute(qp.solved_torque)
182+
#device.execute(tau_cmd)

examples/talos_kinodynamics.py

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from bullet_robot import BulletRobot
55
import time
66
from utils import loadTalos
7-
from simple_mpc import RobotModelHandler, RobotDataHandler, KinodynamicsOCP, MPC, IDSolver
7+
from simple_mpc import RobotModelHandler, RobotDataHandler, KinodynamicsOCP, MPC
88

99
# RobotWrapper
1010
URDF_SUBPATH = "/talos_data/robots/talos_reduced.urdf"
@@ -136,24 +136,6 @@
136136

137137
mpc.generateCycleHorizon(contact_phases)
138138

139-
""" Initialize whole-body inverse dynamics QP"""
140-
contact_ids = model_handler.getFeetIds()
141-
id_conf = dict(
142-
contact_ids=contact_ids,
143-
x0=model_handler.getReferenceState(),
144-
mu=0.8,
145-
Lfoot=0.1,
146-
Wfoot=0.075,
147-
force_size=6,
148-
kd=0,
149-
w_force=100,
150-
w_acc=1,
151-
w_tau=0,
152-
verbose=False,
153-
)
154-
155-
qp = IDSolver(id_conf, model_handler.getModel())
156-
157139
""" Initialize simulation"""
158140
device = BulletRobot(
159141
model_handler.getModel().names,
@@ -225,14 +207,6 @@
225207
a_interp = (10 - j) / 10 * a0 + j / 10 * a1
226208
f_interp = (10 - j) / 10 * forces0 + j / 10 * forces1
227209

228-
qp.solveQP(
229-
mpc.getDataHandler().getData(),
230-
contact_states,
231-
x_measured[nq:],
232-
a_interp,
233-
np.zeros(nu),
234-
f_interp,
235-
mpc.getDataHandler().getData().M,
236-
)
237-
238-
device.execute(qp.solved_torque)
210+
# TODO: use TSID to compute inverse dynamics and get tau_cmd
211+
212+
#device.execute(tau_cmd)

0 commit comments

Comments
 (0)