Skip to content

Commit 1cca937

Browse files
committed
Include joint friction in ODE state-space representation
1 parent 6465f81 commit 1cca937

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Diff for: src/jaxsim/simulation/ode.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,29 @@ def dx_dt(
105105
terrain=terrain,
106106
)
107107

108+
# ==============
109+
# Joint friction
110+
# ==============
111+
112+
# Static and viscous joint friction parameters
113+
kc = physics_model._joint_friction_static.values()
114+
kv = physics_model._joint_friction_viscous.values()
115+
116+
# Compute the joint friction torque
117+
tau_friction = -(
118+
jnp.diag(kc) @ jnp.sign(ode_state.physics_model.joint_positions)
119+
+ jnp.diag(kv) @ ode_state.physics_model.joint_velocities
120+
)
121+
108122
# ========================
109123
# Compute forward dynamics
110124
# ========================
111125

112126
# Compute the total forces applied to the bodies
113127
total_forces = ode_input.physics_model.f_ext + contact_forces_links
114128

115-
# Compute the mechanical joint torques (real torque sent to the joint) by
116-
# subtracting the optional joint friction
117-
# TODO: add support of coulomb/viscous parameters in parsers and PhysicsModel
118-
kp_friction = jnp.array([0.0] * physics_model.dofs())
119-
kd_friction = jnp.array([0.0] * physics_model.dofs())
120-
tau = ode_input.physics_model.tau - (
121-
jnp.diag(kp_friction) @ jnp.sign(ode_state.physics_model.joint_positions)
122-
+ jnp.diag(kd_friction) @ ode_state.physics_model.joint_velocities
123-
)
129+
# Compute the joint torques to actuate
130+
tau = ode_input.physics_model.tau + tau_friction
124131

125132
W_a_WB, qdd = algos.aba.aba(
126133
model=physics_model,

0 commit comments

Comments
 (0)