@@ -199,6 +199,31 @@ def classify_segment(params: Dict[str, Array], s: Array) -> Tuple[Array, Array]
199
199
200
200
return segment_idx , s_segment
201
201
202
+ def stiffness_fn (params : Dict [str , Array ], formulate_in_strain_space : bool = False ) -> Array :
203
+ """
204
+ Compute the stiffness matrix of the system.
205
+ Args:
206
+ params: Dictionary of robot parameters
207
+
208
+ Returns:
209
+ K: elastic matrix of shape (n_q, n_q) if formulate_in_strain_space is False or (n_xi, n_xi) otherwise
210
+ """
211
+ # cross-sectional area and second moment of area
212
+ A = jnp .pi * params ["r" ] ** 2
213
+ Ib = A ** 2 / (4 * jnp .pi )
214
+
215
+ # elastic and shear modulus
216
+ E , G = params ["E" ], params ["G" ]
217
+ # stiffness matrix of shape (num_segments, 3, 3)
218
+ S = compute_stiffness_matrix_for_all_segments_fn (A , Ib , E , G )
219
+ # we define the elastic matrix of shape (n_xi, n_xi) as K(xi) = K @ xi where K is equal to
220
+ K = blk_diag (S )
221
+
222
+ if not formulate_in_strain_space :
223
+ K = B_xi .T @ K @ B_xi
224
+
225
+ return K
226
+
202
227
@jit
203
228
def forward_kinematics_fn (
204
229
params : Dict [str , Array ], q : Array , s : Array , eps : float = global_eps
@@ -295,17 +320,8 @@ def dynamical_matrices_fn(
295
320
# add a small number to the bending strain to avoid singularities
296
321
xi_epsed = apply_eps_to_bend_strains (xi , eps )
297
322
298
- # cross-sectional area and second moment of area
299
- A = jnp .pi * params ["r" ] ** 2
300
- Ib = A ** 2 / (4 * jnp .pi )
301
-
302
- # elastic and shear modulus
303
- elastic_modulus , shear_modulus = params ["E" ], params ["G" ]
304
- # stiffness matrix of shape (num_segments, 3, 3)
305
- S = compute_stiffness_matrix_for_all_segments_fn (A , Ib , elastic_modulus , shear_modulus )
306
-
307
- # we define the elastic matrix of shape (n_xi, n_xi) as K(xi) = K @ xi where K is equal to
308
- K = blk_diag (S )
323
+ # compute the stiffness matrix
324
+ K = stiffness_fn (params , formulate_in_strain_space = True )
309
325
310
326
# dissipative matrix from the parameters
311
327
D = params .get ("D" , jnp .zeros ((n_xi , n_xi )))
@@ -360,16 +376,8 @@ def potential_energy_fn(params: Dict[str, Array], q: Array, eps: float = 1e4 * g
360
376
# add a small number to the bending strain to avoid singularities
361
377
xi_epsed = apply_eps_to_bend_strains (xi , eps )
362
378
363
- # cross-sectional area and second moment of area
364
- A = jnp .pi * params ["r" ] ** 2
365
- Ib = A ** 2 / (4 * jnp .pi )
366
-
367
- # elastic and shear modulus
368
- E , G = params ["E" ], params ["G" ]
369
- # stiffness matrix of shape (num_segments, 3, 3)
370
- S = compute_stiffness_matrix_for_all_segments_fn (A , Ib , E , G )
371
- # we define the elastic matrix of shape (n_xi, n_xi) as K(xi) = K @ xi where K is equal to
372
- K = blk_diag (S )
379
+ # compute the stiffness matrix
380
+ K = stiffness_fn (params , formulate_in_strain_space = True )
373
381
# elastic energy
374
382
U_K = (xi - xi_eq ).T @ K @ (xi - xi_eq ) # evaluate K(xi) = K @ xi
375
383
@@ -476,6 +484,8 @@ def operational_space_dynamical_matrices_fn(
476
484
477
485
auxiliary_fns = {
478
486
"apply_eps_to_bend_strains" : apply_eps_to_bend_strains ,
487
+ "classify_segment" : classify_segment ,
488
+ "stiffness_fn" : stiffness_fn ,
479
489
"jacobian_fn" : jacobian_fn ,
480
490
"kinetic_energy_fn" : kinetic_energy_fn ,
481
491
"potential_energy_fn" : potential_energy_fn ,
0 commit comments