Skip to content

Commit 996b5ec

Browse files
committed
Allow setting custom actuation_mapping_fn for planar pcs systems
1 parent 49882f3 commit 996b5ec

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/jsrm/systems/planar_pcs.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def factory(
1919
strain_selector: Array = None,
2020
xi_eq: Optional[Array] = None,
2121
stiffness_fn: Optional[Callable] = None,
22+
actuation_mapping_fn: Optional[Callable] = None,
2223
global_eps: float = 1e-6,
2324
) -> Tuple[
2425
Array,
@@ -38,6 +39,8 @@ def factory(
3839
xi_eq: array of shape (3 * num_segments) with the rest strains of the rod
3940
stiffness_fn: function to compute the stiffness matrix of the system. Should have the signature
4041
stiffness_fn(params: Dict[str, Array], B_xi, formulate_in_strain_space: bool) -> Array
42+
actuation_mapping_fn: function to compute the actuation matrix that maps the actuation space to the
43+
configuration space.
4144
global_eps: small number to avoid singularities (e.g., division by zero)
4245
Returns:
4346
B_xi: strain basis matrix of shape (3 * num_segments, n_q)
@@ -233,6 +236,26 @@ def stiffness_fn(
233236

234237
return K
235238

239+
if actuation_mapping_fn is None:
240+
def actuation_mapping_fn(
241+
params: Dict[str, Array],
242+
B_xi: Array,
243+
q: Array,
244+
) -> Array:
245+
"""
246+
Returns the actuation matrix that maps the actuation space to the configuration space.
247+
Assumes the fully actuated and identity actuation matrix.
248+
Args:
249+
params: dictionary with robot parameters
250+
B_xi: strain basis matrix
251+
q: configuration of the robot
252+
Returns:
253+
A: actuation matrix of shape (n_xi, n_xi) where n_xi is the number of strains.
254+
"""
255+
A = jnp.identity(n_xi) @ B_xi
256+
257+
return A
258+
236259
@jit
237260
def forward_kinematics_fn(
238261
params: Dict[str, Array], q: Array, s: Array, eps: float = global_eps
@@ -331,6 +354,8 @@ def dynamical_matrices_fn(
331354

332355
# compute the stiffness matrix
333356
K = stiffness_fn(params, B_xi, formulate_in_strain_space=True)
357+
# compute the actuation matrix
358+
A = actuation_mapping_fn(params, B_xi, q)
334359

335360
# dissipative matrix from the parameters
336361
D = params.get("D", jnp.zeros((n_xi, n_xi)))
@@ -347,7 +372,7 @@ def dynamical_matrices_fn(
347372
D = B_xi.T @ D @ B_xi
348373

349374
# apply the strain basis to the actuation matrix
350-
alpha = B_xi.T @ jnp.identity(n_xi) @ B_xi
375+
alpha = B_xi.T @ A
351376

352377
return B, C, G, K, D, alpha
353378

@@ -500,6 +525,7 @@ def operational_space_dynamical_matrices_fn(
500525
"apply_eps_to_bend_strains": apply_eps_to_bend_strains,
501526
"classify_segment": classify_segment,
502527
"stiffness_fn": stiffness_fn,
528+
"actuation_mapping_fn": actuation_mapping_fn,
503529
"jacobian_fn": jacobian_fn,
504530
"kinetic_energy_fn": kinetic_energy_fn,
505531
"potential_energy_fn": potential_energy_fn,

0 commit comments

Comments
 (0)