Skip to content

Commit

Permalink
Cache base_velocity, base_orientation and base_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
flferretti committed Jan 15, 2025
1 parent 00c7b84 commit dc458fa
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 261 deletions.
8 changes: 4 additions & 4 deletions examples/jaxsim_for_robot_controllers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
"\n",
" # Update the MuJoCo data.\n",
" mj_model_helper.set_joint_positions(\n",
" positions=data.joint_positions(), joint_names=model.joint_names()\n",
" positions=data.joint_positions, joint_names=model.joint_names()\n",
" )\n",
"\n",
" # Record a new video frame.\n",
Expand Down Expand Up @@ -345,8 +345,8 @@
" Mss = js.model.free_floating_mass_matrix(model=model, data=data)[6:, 6:]\n",
"\n",
" # Get the current joint positions and velocities.\n",
" s = data.joint_positions()\n",
" ṡ = data.joint_velocities()\n",
" s = data.joint_positions\n",
" ṡ = data.joint_velocities\n",
"\n",
" # Compute the actuated joint torques.\n",
" s_star = -kp * (s - s_des) - kd * (ṡ - s_dot_des)\n",
Expand Down Expand Up @@ -405,7 +405,7 @@
"\n",
" # Update the MuJoCo data.\n",
" mj_model_helper.set_joint_positions(\n",
" positions=data.joint_positions(), joint_names=model.joint_names()\n",
" positions=data.joint_positions, joint_names=model.joint_names()\n",
" )\n",
"\n",
" # Record a new video frame.\n",
Expand Down
8 changes: 4 additions & 4 deletions src/jaxsim/api/com.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def com_position(
m = js.model.total_mass(model=model)

W_H_L = data.kyn_dyn.forward_kinematics
W_H_B = data.base_transform()
W_H_B = data.kyn_dyn.base_transform
B_H_W = jaxsim.math.Transform.inverse(transform=W_H_B)

def B_p̃_LCoM(i) -> jtp.Vector:
Expand Down Expand Up @@ -134,7 +134,7 @@ def centroidal_momentum_jacobian(
model=model, data=data, output_vel_repr=VelRepr.Body
)

W_H_B = data.base_transform()
W_H_B = data.kyn_dyn.base_transform
B_H_W = jaxsim.math.Transform.inverse(W_H_B)

W_p_CoM = com_position(model=model, data=data)
Expand Down Expand Up @@ -172,7 +172,7 @@ def locked_centroidal_spatial_inertia(
with data.switch_velocity_representation(VelRepr.Body):
B_Mbb_B = js.model.locked_spatial_inertia(model=model, data=data)

W_H_B = data.base_transform()
W_H_B = data.kyn_dyn.base_transform
W_p_CoM = com_position(model=model, data=data)

match data.velocity_representation:
Expand Down Expand Up @@ -411,7 +411,7 @@ def bias_momentum_derivative_term(
case VelRepr.Body:

GB_Xf_W = jaxsim.math.Adjoint.from_transform(
transform=data.base_transform().at[0:3].set(W_p_CoM)
transform=data.kyn_dyn.base_transform.at[0:3].set(W_p_CoM)
).T

GB_ḣ_bias = GB_Xf_W @ W_ḣ_bias
Expand Down
8 changes: 4 additions & 4 deletions src/jaxsim/api/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,20 +636,20 @@ def compute_Ṫ(model: js.model.JaxSimModel, Ẋ: jtp.Matrix) -> jtp.Matrix:
= compute_Ṫ(model=model, =W_Ẋ_W)

case VelRepr.Body:
W_H_B = data.base_transform()
W_H_B = data.kyn_dyn.base_transform
W_X_B = Adjoint.from_transform(transform=W_H_B)
B_v_WB = data.base_velocity()
B_v_WB = data.kyn_dyn.base_velocity
B_vx_WB = Cross.vx(B_v_WB)
W_Ẋ_B = W_X_B @ B_vx_WB

T = compute_T(model=model, X=W_X_B)
= compute_Ṫ(model=model, =W_Ẋ_B)

case VelRepr.Mixed:
W_H_B = data.base_transform()
W_H_B = data.kyn_dyn.base_transform
W_H_BW = W_H_B.at[0:3, 0:3].set(jnp.eye(3))
W_X_BW = Adjoint.from_transform(transform=W_H_BW)
BW_v_WB = data.base_velocity()
BW_v_WB = data.kyn_dyn.base_velocity
BW_v_W_BW = BW_v_WB.at[3:6].set(jnp.zeros(3))
BW_vx_W_BW = Cross.vx(BW_v_W_BW)
W_Ẋ_BW = W_X_BW @ BW_vx_W_BW
Expand Down
Loading

0 comments on commit dc458fa

Please sign in to comment.