Skip to content

Commit

Permalink
Extend test of link bias acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Jun 19, 2024
1 parent 3359e9a commit 414a8b6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/test_api_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,69 @@ def test_link_bias_acceleration(
Jν_js = js.link.bias_acceleration(model=model, data=data, link_index=index)
assert pytest.approx(Jν_idt) == Jν_js

# Test that the conversion of the link bias acceleration works as expected.
# We exclude the mixed representation because converting the acceleration is
# more complex than using the plain 6D transform matrix.
if data.velocity_representation is not VelRepr.Mixed:

W_H_L = js.model.forward_kinematics(model=model, data=data)

# Inertial-fixed to body-fixed conversion.
if data.velocity_representation is VelRepr.Inertial:

W_a_bias_WL = jax.vmap(
lambda index: js.link.bias_acceleration(
model=model, data=data, link_index=index
)
)(jnp.arange(model.number_of_links()))

with data.switch_velocity_representation(VelRepr.Body):

W_X_L = jax.vmap(
lambda W_H_L: jaxsim.math.Adjoint.from_transform(transform=W_H_L)
)(W_H_L)

L_a_bias_WL = jax.vmap(
lambda index: js.link.bias_acceleration(
model=model, data=data, link_index=index
)
)(jnp.arange(model.number_of_links()))

W_a_bias_WL_converted = jax.vmap(
lambda W_X_L, L_a_bias_WL: W_X_L @ L_a_bias_WL
)(W_X_L, L_a_bias_WL)

assert W_a_bias_WL == pytest.approx(W_a_bias_WL_converted)

# Body-fixed to inertial-fixed conversion.
if data.velocity_representation is VelRepr.Body:

L_a_bias_WL = jax.vmap(
lambda index: js.link.bias_acceleration(
model=model, data=data, link_index=index
)
)(jnp.arange(model.number_of_links()))

with data.switch_velocity_representation(VelRepr.Inertial):

L_X_W = jax.vmap(
lambda W_H_L: jaxsim.math.Adjoint.from_transform(
transform=W_H_L, inverse=True
)
)(W_H_L)

W_a_bias_WL = jax.vmap(
lambda index: js.link.bias_acceleration(
model=model, data=data, link_index=index
)
)(jnp.arange(model.number_of_links()))

L_a_bias_WL_converted = jax.vmap(
lambda L_X_W, W_a_bias_WL: L_X_W @ W_a_bias_WL
)(L_X_W, W_a_bias_WL)

assert L_a_bias_WL == pytest.approx(L_a_bias_WL_converted)


def test_link_jacobian_derivative(
jaxsim_models_types: js.model.JaxSimModel,
Expand Down

0 comments on commit 414a8b6

Please sign in to comment.