jaxsim 0.6.2.dev182__py3-none-any.whl → 0.6.2.dev225__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,101 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import jax
4
- import jax.numpy as jnp
5
-
6
- import jaxsim.api as js
7
- import jaxsim.typing as jtp
8
-
9
-
10
- @jax.jit
11
- @js.common.named_scope
12
- def link_contact_forces(
13
- model: js.model.JaxSimModel,
14
- data: js.data.JaxSimModelData,
15
- *,
16
- link_forces: jtp.MatrixLike | None = None,
17
- joint_torques: jtp.VectorLike | None = None,
18
- ) -> jtp.Matrix:
19
- """
20
- Compute the 6D contact forces of all links of the model in inertial representation.
21
-
22
- Args:
23
- model: The model to consider.
24
- data: The data of the considered model.
25
- link_forces:
26
- The 6D external forces to apply to the links expressed in inertial representation
27
- joint_torques:
28
- The joint torques acting on the joints.
29
-
30
- Returns:
31
- A `(nL, 6)` array containing the stacked 6D contact forces of the links,
32
- expressed in inertial representation.
33
- """
34
-
35
- # Compute the contact forces for each collidable point with the active contact model.
36
- W_f_C, _ = model.contact_model.compute_contact_forces(
37
- model=model,
38
- data=data,
39
- link_forces=link_forces,
40
- joint_force_references=joint_torques,
41
- )
42
-
43
- # Compute the 6D forces applied to the links equivalent to the forces applied
44
- # to the frames associated to the collidable points.
45
- W_f_L = link_forces_from_contact_forces(
46
- model=model, data=data, contact_forces=W_f_C
47
- )
48
-
49
- return W_f_L
50
-
51
-
52
- @staticmethod
53
- def link_forces_from_contact_forces(
54
- model: js.model.JaxSimModel,
55
- data: js.data.JaxSimModelData,
56
- *,
57
- contact_forces: jtp.MatrixLike,
58
- ) -> jtp.Matrix:
59
- """
60
- Compute the link forces from the contact forces.
61
-
62
- Args:
63
- model: The robot model considered by the contact model.
64
- data: The data of the considered model.
65
- contact_forces: The contact forces computed by the contact model.
66
-
67
- Returns:
68
- The 6D contact forces applied to the links and expressed in the frame of
69
- the velocity representation of data.
70
- """
71
-
72
- # Get the object storing the contact parameters of the model.
73
- contact_parameters = model.kin_dyn_parameters.contact_parameters
74
-
75
- # Extract the indices corresponding to the enabled collidable points.
76
- indices_of_enabled_collidable_points = (
77
- contact_parameters.indices_of_enabled_collidable_points
78
- )
79
-
80
- # Convert the contact forces to a JAX array.
81
- W_f_C = jnp.atleast_2d(jnp.array(contact_forces, dtype=float).squeeze())
82
-
83
- # Construct the vector defining the parent link index of each collidable point.
84
- # We use this vector to sum the 6D forces of all collidable points rigidly
85
- # attached to the same link.
86
- parent_link_index_of_collidable_points = jnp.array(
87
- contact_parameters.body, dtype=int
88
- )[indices_of_enabled_collidable_points]
89
-
90
- # Create the mask that associate each collidable point to their parent link.
91
- # We use this mask to sum the collidable points to the right link.
92
- mask = parent_link_index_of_collidable_points[:, jnp.newaxis] == jnp.arange(
93
- model.number_of_links()
94
- )
95
-
96
- # Sum the forces of all collidable points rigidly attached to a body.
97
- # Since the contact forces W_f_C are expressed in the world frame,
98
- # we don't need any coordinate transformation.
99
- W_f_L = mask.T @ W_f_C
100
-
101
- return W_f_L