jaxsim 0.3.1.dev40__py3-none-any.whl → 0.3.1.dev46__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.
jaxsim/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.3.1.dev40'
16
- __version_tuple__ = version_tuple = (0, 3, 1, 'dev40')
15
+ __version__ = version = '0.3.1.dev46'
16
+ __version_tuple__ = version_tuple = (0, 3, 1, 'dev46')
jaxsim/api/frame.py CHANGED
@@ -4,11 +4,11 @@ from typing import Sequence
4
4
  import jax
5
5
  import jax.numpy as jnp
6
6
  import jaxlie
7
- import numpy as np
8
7
 
9
8
  import jaxsim.api as js
10
9
  import jaxsim.math
11
10
  import jaxsim.typing as jtp
11
+ from jaxsim import exceptions
12
12
 
13
13
  from .common import VelRepr
14
14
 
@@ -17,22 +17,32 @@ from .common import VelRepr
17
17
  # =======================
18
18
 
19
19
 
20
+ @jax.jit
20
21
  def idx_of_parent_link(
21
- model: js.model.JaxSimModel, *, frame_idx: jtp.IntLike
22
+ model: js.model.JaxSimModel, *, frame_index: jtp.IntLike
22
23
  ) -> jtp.Int:
23
24
  """
24
25
  Get the index of the link to which the frame is rigidly attached.
25
26
 
26
27
  Args:
27
28
  model: The model to consider.
28
- frame_idx: The index of the frame.
29
+ frame_index: The index of the frame.
29
30
 
30
31
  Returns:
31
32
  The index of the frame's parent link.
32
33
  """
33
34
 
35
+ n_l = model.number_of_links()
36
+ n_f = len(model.frame_names())
37
+
38
+ exceptions.raise_value_error_if(
39
+ condition=jnp.array([frame_index < n_l, frame_index >= n_l + n_f]).any(),
40
+ msg="Invalid frame index '{idx}'",
41
+ idx=frame_index,
42
+ )
43
+
34
44
  return model.kin_dyn_parameters.frame_parameters.body[
35
- frame_idx - model.number_of_links()
45
+ frame_index - model.number_of_links()
36
46
  ]
37
47
 
38
48
 
@@ -49,19 +59,17 @@ def name_to_idx(model: js.model.JaxSimModel, *, frame_name: str) -> jtp.Int:
49
59
  The index of the frame.
50
60
  """
51
61
 
52
- if frame_name in model.kin_dyn_parameters.frame_parameters.name:
53
- return (
54
- jnp.array(
55
- np.argwhere(
56
- np.array(model.kin_dyn_parameters.frame_parameters.name)
57
- == frame_name
58
- )
59
- )
60
- .squeeze()
61
- .astype(int)
62
- ) + model.number_of_links()
62
+ if frame_name not in model.kin_dyn_parameters.frame_parameters.name:
63
+ raise ValueError(f"Frame '{frame_name}' not found in the model.")
63
64
 
64
- return jnp.array(-1).astype(int)
65
+ return (
66
+ jnp.array(
67
+ model.number_of_links()
68
+ + model.kin_dyn_parameters.frame_parameters.name.index(frame_name)
69
+ )
70
+ .astype(int)
71
+ .squeeze()
72
+ )
65
73
 
66
74
 
67
75
  def idx_to_name(model: js.model.JaxSimModel, *, frame_index: jtp.IntLike) -> str:
@@ -76,6 +84,15 @@ def idx_to_name(model: js.model.JaxSimModel, *, frame_index: jtp.IntLike) -> str
76
84
  The name of the frame.
77
85
  """
78
86
 
87
+ n_l = model.number_of_links()
88
+ n_f = len(model.frame_names())
89
+
90
+ exceptions.raise_value_error_if(
91
+ condition=jnp.array([frame_index < n_l, frame_index >= n_l + n_f]).any(),
92
+ msg="Invalid frame index '{idx}'",
93
+ idx=frame_index,
94
+ )
95
+
79
96
  return model.kin_dyn_parameters.frame_parameters.name[
80
97
  frame_index - model.number_of_links()
81
98
  ]
@@ -142,8 +159,17 @@ def transform(
142
159
  The 4x4 matrix representing the transform.
143
160
  """
144
161
 
162
+ n_l = model.number_of_links()
163
+ n_f = len(model.frame_names())
164
+
165
+ exceptions.raise_value_error_if(
166
+ condition=jnp.array([frame_index < n_l, frame_index >= n_l + n_f]).any(),
167
+ msg="Invalid frame index '{idx}'",
168
+ idx=frame_index,
169
+ )
170
+
145
171
  # Compute the necessary transforms.
146
- L = idx_of_parent_link(model=model, frame_idx=frame_index)
172
+ L = idx_of_parent_link(model=model, frame_index=frame_index)
147
173
  W_H_L = js.link.transform(model=model, data=data, link_index=L)
148
174
 
149
175
  # Get the static frame pose wrt the parent link.
@@ -181,12 +207,21 @@ def jacobian(
181
207
  velocity representation.
182
208
  """
183
209
 
210
+ n_l = model.number_of_links()
211
+ n_f = len(model.frame_names())
212
+
213
+ exceptions.raise_value_error_if(
214
+ condition=jnp.array([frame_index < n_l, frame_index >= n_l + n_f]).any(),
215
+ msg="Invalid frame index '{idx}'",
216
+ idx=frame_index,
217
+ )
218
+
184
219
  output_vel_repr = (
185
220
  output_vel_repr if output_vel_repr is not None else data.velocity_representation
186
221
  )
187
222
 
188
223
  # Get the index of the parent link.
189
- L = idx_of_parent_link(model=model, frame_idx=frame_index)
224
+ L = idx_of_parent_link(model=model, frame_index=frame_index)
190
225
 
191
226
  # Compute the Jacobian of the parent link using body-fixed output representation.
192
227
  L_J_WL = js.link.jacobian(
jaxsim/api/joint.py CHANGED
@@ -6,6 +6,7 @@ import jax.numpy as jnp
6
6
 
7
7
  import jaxsim.api as js
8
8
  import jaxsim.typing as jtp
9
+ from jaxsim import exceptions
9
10
 
10
11
  # =======================
11
12
  # Index-related functions
@@ -25,14 +26,18 @@ def name_to_idx(model: js.model.JaxSimModel, *, joint_name: str) -> jtp.Int:
25
26
  The index of the joint.
26
27
  """
27
28
 
28
- if joint_name in model.kin_dyn_parameters.joint_model.joint_names:
29
- # Note: the index of the joint for RBDAs starts from 1, but
30
- # the index for accessing the right element starts from 0.
31
- # Therefore, there is a -1.
32
- return jnp.array(
29
+ if joint_name not in model.joint_names():
30
+ raise ValueError(f"Joint '{joint_name}' not found in the model.")
31
+
32
+ # Note: the index of the joint for RBDAs starts from 1, but the index for
33
+ # accessing the right element starts from 0. Therefore, there is a -1.
34
+ return (
35
+ jnp.array(
33
36
  model.kin_dyn_parameters.joint_model.joint_names.index(joint_name) - 1
34
- ).squeeze()
35
- return jnp.array(-1).astype(int)
37
+ )
38
+ .astype(int)
39
+ .squeeze()
40
+ )
36
41
 
37
42
 
38
43
  def idx_to_name(model: js.model.JaxSimModel, *, joint_index: jtp.IntLike) -> str:
@@ -47,6 +52,14 @@ def idx_to_name(model: js.model.JaxSimModel, *, joint_index: jtp.IntLike) -> str
47
52
  The name of the joint.
48
53
  """
49
54
 
55
+ exceptions.raise_value_error_if(
56
+ condition=jnp.array(
57
+ [joint_index < 0, joint_index >= model.number_of_joints()]
58
+ ).any(),
59
+ msg="Invalid joint index '{idx}'",
60
+ idx=joint_index,
61
+ )
62
+
50
63
  return model.kin_dyn_parameters.joint_model.joint_names[joint_index + 1]
51
64
 
52
65
 
@@ -112,6 +125,14 @@ def position_limit(
112
125
  if model.number_of_joints() <= 1:
113
126
  return jnp.empty(0).astype(float), jnp.empty(0).astype(float)
114
127
 
128
+ exceptions.raise_value_error_if(
129
+ condition=jnp.array(
130
+ [joint_index < 0, joint_index >= model.number_of_joints()]
131
+ ).any(),
132
+ msg="Invalid joint index '{idx}'",
133
+ idx=joint_index,
134
+ )
135
+
115
136
  s_min = model.kin_dyn_parameters.joint_parameters.position_limits_min[joint_index]
116
137
  s_max = model.kin_dyn_parameters.joint_parameters.position_limits_max[joint_index]
117
138
 
jaxsim/api/link.py CHANGED
@@ -5,11 +5,11 @@ import jax
5
5
  import jax.numpy as jnp
6
6
  import jax.scipy.linalg
7
7
  import jaxlie
8
- import numpy as np
9
8
 
10
9
  import jaxsim.api as js
11
10
  import jaxsim.rbda
12
11
  import jaxsim.typing as jtp
12
+ from jaxsim import exceptions
13
13
 
14
14
  from .common import VelRepr
15
15
 
@@ -31,15 +31,14 @@ def name_to_idx(model: js.model.JaxSimModel, *, link_name: str) -> jtp.Int:
31
31
  The index of the link.
32
32
  """
33
33
 
34
- if link_name in model.kin_dyn_parameters.link_names:
35
- return (
36
- jnp.array(
37
- np.argwhere(np.array(model.kin_dyn_parameters.link_names) == link_name)
38
- )
39
- .squeeze()
40
- .astype(int)
41
- )
42
- return jnp.array(-1).astype(int)
34
+ if link_name not in model.link_names():
35
+ raise ValueError(f"Link '{link_name}' not found in the model.")
36
+
37
+ return (
38
+ jnp.array(model.kin_dyn_parameters.link_names.index(link_name))
39
+ .astype(int)
40
+ .squeeze()
41
+ )
43
42
 
44
43
 
45
44
  def idx_to_name(model: js.model.JaxSimModel, *, link_index: jtp.IntLike) -> str:
@@ -54,6 +53,14 @@ def idx_to_name(model: js.model.JaxSimModel, *, link_index: jtp.IntLike) -> str:
54
53
  The name of the link.
55
54
  """
56
55
 
56
+ exceptions.raise_value_error_if(
57
+ condition=jnp.array(
58
+ [link_index < 0, link_index >= model.number_of_links()]
59
+ ).any(),
60
+ msg="Invalid link index '{idx}'",
61
+ idx=link_index,
62
+ )
63
+
57
64
  return model.kin_dyn_parameters.link_names[link_index]
58
65
 
59
66
 
@@ -112,6 +119,14 @@ def mass(model: js.model.JaxSimModel, *, link_index: jtp.IntLike) -> jtp.Float:
112
119
  The mass of the link.
113
120
  """
114
121
 
122
+ exceptions.raise_value_error_if(
123
+ condition=jnp.array(
124
+ [link_index < 0, link_index >= model.number_of_links()]
125
+ ).any(),
126
+ msg="Invalid link index '{idx}'",
127
+ idx=link_index,
128
+ )
129
+
115
130
  return model.kin_dyn_parameters.link_parameters.mass[link_index].astype(float)
116
131
 
117
132
 
@@ -131,6 +146,14 @@ def spatial_inertia(
131
146
  the link frame (body-fixed representation).
132
147
  """
133
148
 
149
+ exceptions.raise_value_error_if(
150
+ condition=jnp.array(
151
+ [link_index < 0, link_index >= model.number_of_links()]
152
+ ).any(),
153
+ msg="Invalid link index '{idx}'",
154
+ idx=link_index,
155
+ )
156
+
134
157
  link_parameters = jax.tree_util.tree_map(
135
158
  lambda l: l[link_index], model.kin_dyn_parameters.link_parameters
136
159
  )
@@ -157,6 +180,14 @@ def transform(
157
180
  The 4x4 matrix representing the transform.
158
181
  """
159
182
 
183
+ exceptions.raise_value_error_if(
184
+ condition=jnp.array(
185
+ [link_index < 0, link_index >= model.number_of_links()]
186
+ ).any(),
187
+ msg="Invalid link index '{idx}'",
188
+ idx=link_index,
189
+ )
190
+
160
191
  return js.model.forward_kinematics(model=model, data=data)[link_index]
161
192
 
162
193
 
@@ -230,6 +261,14 @@ def jacobian(
230
261
  velocity representation.
231
262
  """
232
263
 
264
+ exceptions.raise_value_error_if(
265
+ condition=jnp.array(
266
+ [link_index < 0, link_index >= model.number_of_links()]
267
+ ).any(),
268
+ msg="Invalid link index '{idx}'",
269
+ idx=link_index,
270
+ )
271
+
233
272
  output_vel_repr = (
234
273
  output_vel_repr if output_vel_repr is not None else data.velocity_representation
235
274
  )
@@ -318,6 +357,14 @@ def velocity(
318
357
  The 6D velocity of the link in the specified velocity representation.
319
358
  """
320
359
 
360
+ exceptions.raise_value_error_if(
361
+ condition=jnp.array(
362
+ [link_index < 0, link_index >= model.number_of_links()]
363
+ ).any(),
364
+ msg="Invalid link index '{idx}'",
365
+ idx=link_index,
366
+ )
367
+
321
368
  output_vel_repr = (
322
369
  output_vel_repr if output_vel_repr is not None else data.velocity_representation
323
370
  )
@@ -364,6 +411,14 @@ def jacobian_derivative(
364
411
  velocity representation.
365
412
  """
366
413
 
414
+ exceptions.raise_value_error_if(
415
+ condition=jnp.array(
416
+ [link_index < 0, link_index >= model.number_of_links()]
417
+ ).any(),
418
+ msg="Invalid link index '{idx}'",
419
+ idx=link_index,
420
+ )
421
+
367
422
  output_vel_repr = (
368
423
  output_vel_repr if output_vel_repr is not None else data.velocity_representation
369
424
  )
@@ -538,6 +593,14 @@ def bias_acceleration(
538
593
  The 6D bias acceleration of the link.
539
594
  """
540
595
 
596
+ exceptions.raise_value_error_if(
597
+ condition=jnp.array(
598
+ [link_index < 0, link_index >= model.number_of_links()]
599
+ ).any(),
600
+ msg="Invalid link index '{idx}'",
601
+ idx=link_index,
602
+ )
603
+
541
604
  # Compute the bias acceleration of all links in the active representation.
542
605
  O_v̇_WL = js.model.link_bias_accelerations(model=model, data=data)[link_index]
543
606
  return O_v̇_WL
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jaxsim
3
- Version: 0.3.1.dev40
3
+ Version: 0.3.1.dev46
4
4
  Home-page: https://github.com/ami-iit/jaxsim
5
5
  Author: Diego Ferigo
6
6
  Author-email: diego.ferigo@iit.it
@@ -1,5 +1,5 @@
1
1
  jaxsim/__init__.py,sha256=xzuTuZrgKdWLqqDzbvqzm2cJrEtAbepOeUqDu7ByVek,2621
2
- jaxsim/_version.py,sha256=JHeHgaRnZLSH9QDd807jRnlOgX9sn4w_CGqGSxA8lL0,426
2
+ jaxsim/_version.py,sha256=9MZZuPQZKCPbVj6_p_Ju-do62zKeUP7ohaQeRYNKN3w,426
3
3
  jaxsim/exceptions.py,sha256=8_h8iqL8DgNR754dR8SZiQ7361GR5V1sUk3ZuZCHw1Q,2069
4
4
  jaxsim/logging.py,sha256=c4zhwBKf9eAYAHVp62kTEllqdsZgh0K-kPKVy8L3elU,1584
5
5
  jaxsim/typing.py,sha256=cl7HHQCeP3mHmtF6EuQZcCjGvDmc_AryMWntP_lRBGg,722
@@ -8,10 +8,10 @@ jaxsim/api/com.py,sha256=Yof6otFi-mLWAs1rqjmeNJTOWIH9gn7BdU5EIjiL6Ts,13481
8
8
  jaxsim/api/common.py,sha256=bqQ__pIQZbh-j8rkoHUkYHAgGiJnDzjHG-q4Ny0OOYQ,6646
9
9
  jaxsim/api/contact.py,sha256=soB28vqmzUwE6CN36TU4keASWZoSWE2_zhJLXA8yw2E,13132
10
10
  jaxsim/api/data.py,sha256=oAJ2suPeQLQZGpHZi98g6UZp1VcoDtuqT_aZBpynA30,27582
11
- jaxsim/api/frame.py,sha256=vSbFHL4WtKPySxunNoZLlM_aDuJXZtf8CSBKku63BAs,6178
12
- jaxsim/api/joint.py,sha256=-5DogPg4g4mmLckyVIVNjwv-Rxz0IWS7_md9nDlhPWA,4581
11
+ jaxsim/api/frame.py,sha256=m_waB9_0kgJq5miiZDXdRzIZii-BwQaN9bRt22JkJ1I,7212
12
+ jaxsim/api/joint.py,sha256=Pvg_It2iYA-jAQ2nOlFZxwmITiozO_f46G13BdQtHQ0,5106
13
13
  jaxsim/api/kin_dyn_parameters.py,sha256=AEpDg9kihbKUN9PA8pNrAruSuWFUC-k_GGxtlcdcDiQ,29215
14
- jaxsim/api/link.py,sha256=MdMWaMpM5Dj5JHK8uwHZ4zR4Fjq3R4asi2sGTxk1OAs,16647
14
+ jaxsim/api/link.py,sha256=edXaNO0TcqyFyMOlIlCnReQK_VP8p38crLEp0of7mWo,18404
15
15
  jaxsim/api/model.py,sha256=HAnrlgPDl5CCZQzQ84AfjC_DZjmrCzBKEDodE6hyLf8,60518
16
16
  jaxsim/api/ode.py,sha256=xQL53ppnKweMQWRNm5gGR8FTjqRVzds8WKg9js9k5TA,10780
17
17
  jaxsim/api/ode_data.py,sha256=Sa2i1zZhqyQqIGv1jarTmmU-W9HhTw-DErs12kFA1GA,19737
@@ -61,8 +61,8 @@ jaxsim/utils/__init__.py,sha256=Y5zyoRevl3EMVQadhZ4EtSwTEkDt2vcnFoRhPJjKTZ0,215
61
61
  jaxsim/utils/jaxsim_dataclass.py,sha256=h26timZ_XrBL_Q_oymv-DkQd-EcUiHn8QexAaZXBY9c,11396
62
62
  jaxsim/utils/tracing.py,sha256=KDMoyVPlu2NJvFkhtZwq5AkqMMgajt3munvJom-vEjQ,650
63
63
  jaxsim/utils/wrappers.py,sha256=QIJitSoljrKR_U4T3ewCJPT3DTh-tPZsRsg0t_MH93E,3896
64
- jaxsim-0.3.1.dev40.dist-info/LICENSE,sha256=eaYdFmdeMbiIoIiPzEK0MjP1S9wtFXjXNR5er49uLR0,1546
65
- jaxsim-0.3.1.dev40.dist-info/METADATA,sha256=ds7zFF0BWvBs8TLnHcQ54-diuMpka_Y5NKlF-vDK2nA,9739
66
- jaxsim-0.3.1.dev40.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
67
- jaxsim-0.3.1.dev40.dist-info/top_level.txt,sha256=LxGMA8FLtXjQ6oI7N5gd_R_oSUHxpXxUEOfT1xS_ni0,7
68
- jaxsim-0.3.1.dev40.dist-info/RECORD,,
64
+ jaxsim-0.3.1.dev46.dist-info/LICENSE,sha256=eaYdFmdeMbiIoIiPzEK0MjP1S9wtFXjXNR5er49uLR0,1546
65
+ jaxsim-0.3.1.dev46.dist-info/METADATA,sha256=KS14B2THB9Wao1MpRKEp345CTkC7PMLMfUOSbOkYbBA,9739
66
+ jaxsim-0.3.1.dev46.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
67
+ jaxsim-0.3.1.dev46.dist-info/top_level.txt,sha256=LxGMA8FLtXjQ6oI7N5gd_R_oSUHxpXxUEOfT1xS_ni0,7
68
+ jaxsim-0.3.1.dev46.dist-info/RECORD,,