Skip to content

Commit a2823da

Browse files
committed
Add support for segment_actuation_selector
1 parent a66de0b commit a2823da

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

examples/simulate_tendon_actuated_planar_pcs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444

4545
# activate all strains (i.e. bending, shear, and axial)
4646
strain_selector = jnp.ones((3 * num_segments,), dtype=bool)
47+
# actuation selector for the segments
48+
segment_actuation_selector = jnp.ones((num_segments,), dtype=bool)
49+
# segment_actuation_selector = jnp.array([False, True]) # only the last segment is actuated
4750

4851
# define initial configuration
4952
q0 = jnp.repeat(jnp.array([5.0 * jnp.pi, 0.1, 0.2])[None, :], num_segments, axis=0).flatten()
@@ -99,7 +102,7 @@ def draw_robot(
99102

100103
if __name__ == "__main__":
101104
strain_basis, forward_kinematics_fn, dynamical_matrices_fn, auxiliary_fns = (
102-
planar_pcs.factory(num_segments, sym_exp_filepath, strain_selector)
105+
planar_pcs.factory(num_segments, sym_exp_filepath, strain_selector, segment_actuation_selector=segment_actuation_selector)
103106
)
104107
actuation_mapping_fn = auxiliary_fns["actuation_mapping_fn"]
105108
# jit the functions

src/jsrm/systems/tendon_actuated_planar_pcs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ def factory(
2424
if segment_actuation_selector is None:
2525
segment_actuation_selector = jnp.ones(num_segments, dtype=bool)
2626

27-
# number of system inputs
28-
actuation_dim = segment_actuation_selector.sum()
29-
actuation_dim = 2 * num_segments
30-
actuation_basis = jnp.eye(actuation_dim)
31-
3227
def actuation_mapping_fn(
3328
forward_kinematics_fn: Callable,
3429
jacobian_fn: Callable,
@@ -112,12 +107,17 @@ def compute_A_d_wrt_xi_i(i: Array, l_i: Array, xi_i: Array) -> Array:
112107

113108
return A_sm
114109

110+
# compute the actuation matrix for all segments
111+
# will have shape (num_segments, n_xi, num_segment_tendons)
115112
A = vmap(compute_actuation_matrix_for_segment, in_axes=(0, 0), out_axes=0)(
116113
segment_indices, params["d"],
117-
).transpose((1, 0, 2)).reshape(xi.shape[0], -1)
114+
)
115+
116+
# deactivate the actuation for some segments
117+
A = A[segment_actuation_selector]
118118

119-
# apply the actuation_basis
120-
A = A @ actuation_basis
119+
# reshape the actuation matrix to have shape (n_xi, n_act)
120+
A = A.transpose((1, 0, 2)).reshape(xi.shape[0], -1)
121121

122122
return A
123123

0 commit comments

Comments
 (0)