|
1 | 1 | import numpy as np |
2 | 2 | from bullet_robot import BulletRobot |
3 | | -from simple_mpc import RobotModelHandler, RobotDataHandler, FullDynamicsOCP, MPC, IDSolver |
| 3 | +from simple_mpc import RobotModelHandler, RobotDataHandler, FullDynamicsOCP, MPC, IDSolver, FrictionCompensation |
4 | 4 | import example_robot_data as erd |
5 | 5 | import pinocchio as pin |
6 | 6 | import time |
|
21 | 21 | model_handler.addFoot("RR_foot", base_joint_name, pin.XYZQUATToSE3(np.array([-0.24,-0.15, 0.0, 0,0,0,1]))) |
22 | 22 | data_handler = RobotDataHandler(model_handler) |
23 | 23 |
|
| 24 | +nq = model_handler.getModel().nq |
| 25 | +nv = model_handler.getModel().nv |
| 26 | +nu = nv - 6 |
24 | 27 | force_size = 3 |
25 | 28 | nk = len(model_handler.getFeetNames()) |
26 | 29 | gravity = np.array([0, 0, -9.81]) |
|
110 | 113 | "RL_foot": False, |
111 | 114 | "RR_foot": False, |
112 | 115 | } |
113 | | -contact_phases = [contact_phase_quadru] * int(T_ds / 2) |
| 116 | +contact_phases = [contact_phase_quadru] * T_ds |
114 | 117 | contact_phases += [contact_phase_lift_FL] * T_ss |
115 | 118 | contact_phases += [contact_phase_quadru] * T_ds |
116 | 119 | contact_phases += [contact_phase_lift_FR] * T_ss |
117 | | -contact_phases += [contact_phase_quadru] * int(T_ds / 2) |
118 | 120 |
|
119 | 121 | """ contact_phases = [contact_phase_quadru] * int(T_ds / 2) |
120 | 122 | contact_phases += [contact_phase_lift] * T_ss |
|
140 | 142 |
|
141 | 143 | qp = IDSolver(id_conf, model_handler.getModel()) |
142 | 144 |
|
| 145 | +""" Friction """ |
| 146 | +fcompensation = FrictionCompensation(model_handler.getModel(), True) |
| 147 | + |
143 | 148 | """ Initialize simulation""" |
144 | 149 | device = BulletRobot( |
145 | 150 | model_handler.getModel().names, |
|
187 | 192 | L_measured = [] |
188 | 193 |
|
189 | 194 | v = np.zeros(6) |
190 | | -v[0] = 0.2 |
| 195 | +v[0] = 0. |
191 | 196 | mpc.velocity_base = v |
192 | 197 | for t in range(500): |
193 | 198 | print("Time " + str(t)) |
|
270 | 275 | mpc.getDataHandler().getData().M, |
271 | 276 | ) |
272 | 277 |
|
273 | | - device.execute(qp.solved_torque) |
| 278 | + qp_torque = qp.solved_torque.copy() |
| 279 | + friction_torque = fcompensation.computeFriction(x_interp[nq + 6:], qp_torque) |
| 280 | + device.execute(friction_torque) |
274 | 281 |
|
275 | | - u_multibody.append(copy.deepcopy(qp.solved_torque)) |
| 282 | + u_multibody.append(copy.deepcopy(friction_torque)) |
276 | 283 | x_multibody.append(x_measured) |
277 | 284 |
|
278 | 285 | force_FL = np.array(force_FL) |
|
0 commit comments