Skip to content

Commit 2daa3b1

Browse files
committed
Add option to use simplified actuation matrix for pneumatic actuatino
1 parent 96d4053 commit 2daa3b1

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

examples/demo_planar_hsa_motor2ee_jacobian.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
jax.config.update("jax_enable_x64", True) # double precision
44
from jax import Array, jacfwd, jacrev, jit, random, vmap
55
from jax import numpy as jnp
6-
from jaxopt import GaussNewton, LevenbergMarquardt
76
from functools import partial
87
import numpy as onp
98
from pathlib import Path

examples/simulate_pneumatic_planar_pcs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
strain_selector = jnp.array([True, False, True])[None, :].repeat(num_segments, axis=0).flatten()
4949

5050
B_xi, forward_kinematics_fn, dynamical_matrices_fn, auxiliary_fns = (
51-
pneumatic_planar_pcs.factory(num_segments, sym_exp_filepath, strain_selector)
51+
pneumatic_planar_pcs.factory(
52+
num_segments, sym_exp_filepath, strain_selector, # simplified_actuation_mapping=True
53+
)
5254
)
5355
# jit the functions
5456
dynamical_matrices_fn = jax.jit(dynamical_matrices_fn)
@@ -57,6 +59,7 @@
5759
forward_kinematics_fn,
5860
auxiliary_fns["jacobian_fn"],
5961
)
62+
print("A=", actuation_mapping_fn(params, B_xi, jnp.zeros((2 * num_segments,))))
6063

6164

6265
def sweep_actuation_mapping():

src/jsrm/systems/planar_pcs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def stiffness_fn(
216216
B_xi: Strain basis matrix
217217
formulate_in_strain_space: whether to formulate the elastic matrix in the strain space
218218
Returns:
219-
K: elastic matrix of shape (n_q, n_q) if formulate_in_strain_space is False or (n_xi, n_xi) otherwise
219+
S: elastic matrix of shape (n_q, n_q) if formulate_in_strain_space is False or (n_xi, n_xi) otherwise
220220
"""
221221
# length of the segments
222222
l = params["l"]
@@ -227,14 +227,14 @@ def stiffness_fn(
227227
# elastic and shear modulus
228228
E, G = params["E"], params["G"]
229229
# stiffness matrix of shape (num_segments, 3, 3)
230-
S = compute_stiffness_matrix_for_all_segments_fn(l, A, Ib, E, G)
230+
S_sms = compute_stiffness_matrix_for_all_segments_fn(l, A, Ib, E, G)
231231
# we define the elastic matrix of shape (n_xi, n_xi) as K(xi) = K @ xi where K is equal to
232-
K = blk_diag(S)
232+
S = blk_diag(S_sms)
233233

234234
if not formulate_in_strain_space:
235-
K = B_xi.T @ K @ B_xi
235+
S = B_xi.T @ S @ B_xi
236236

237-
return K
237+
return S
238238

239239
if actuation_mapping_fn is None:
240240
def actuation_mapping_fn(

src/jsrm/systems/pneumatic_planar_pcs.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def factory(
1111
num_segments: int,
1212
*args,
1313
segment_actuation_selector: Optional[Array] = None,
14+
simplified_actuation_mapping: bool = False,
1415
**kwargs
1516
):
1617
"""
@@ -19,6 +20,7 @@ def factory(
1920
num_segments: number of segments
2021
segment_actuation_selector: actuation selector for the segments as boolean array of shape (num_segments,)
2122
True entries signify that the segment is actuated, False entries signify that the segment is passive
23+
simplified_actuation_mapping: flag to use a simplified actuation mapping (i.e., a constant actuation matrix)
2224
Returns:
2325
"""
2426
if segment_actuation_selector is None:
@@ -102,22 +104,29 @@ def compute_actuation_matrix_for_segment(
102104
2 / 3 * jnp.sinc(0.5 * varphi_cham) * (r_cham_out ** 3 - r_cham_in ** 3) / (r_cham_out ** 2 - r_cham_in ** 2)
103105
)
104106

105-
# compute the actuation matrix that collects the contributions of the pneumatic chambers in the given segment
106-
# first we consider the contribution of the distal end
107-
A_sm_de = J_de.T @ jnp.array([
108-
[-2 * A_cham * jnp.sin(th_de), -2 * A_cham * jnp.sin(th_de)],
109-
[2 * A_cham * jnp.cos(th_de), 2 * A_cham * jnp.cos(th_de)],
110-
[A_cham * r_cop, -A_cham * r_cop]
111-
])
112-
# then, we consider the contribution of the proximal end
113-
A_sm_pe = J_pe.T @ jnp.array([
114-
[2 * A_cham * jnp.sin(th_pe), 2 * A_cham * jnp.sin(th_pe)],
115-
[-2 * A_cham * jnp.cos(th_pe), -2 * A_cham * jnp.cos(th_pe)],
116-
[-A_cham * r_cop, A_cham * r_cop]
117-
])
118-
119-
# sum the contributions of the distal and proximal ends
120-
A_sm = A_sm_de + A_sm_pe
107+
if simplified_actuation_mapping:
108+
A_sm = B_xi.T @ jnp.array([
109+
[A_cham * r_cop, -A_cham * r_cop],
110+
[0.0, 0.0],
111+
[2 * A_cham, 2 * A_cham],
112+
])
113+
else:
114+
# compute the actuation matrix that collects the contributions of the pneumatic chambers in the given segment
115+
# first we consider the contribution of the distal end
116+
A_sm_de = J_de.T @ jnp.array([
117+
[-2 * A_cham * jnp.sin(th_de), -2 * A_cham * jnp.sin(th_de)],
118+
[2 * A_cham * jnp.cos(th_de), 2 * A_cham * jnp.cos(th_de)],
119+
[A_cham * r_cop, -A_cham * r_cop]
120+
])
121+
# then, we consider the contribution of the proximal end
122+
A_sm_pe = J_pe.T @ jnp.array([
123+
[2 * A_cham * jnp.sin(th_pe), 2 * A_cham * jnp.sin(th_pe)],
124+
[-2 * A_cham * jnp.cos(th_pe), -2 * A_cham * jnp.cos(th_pe)],
125+
[-A_cham * r_cop, A_cham * r_cop]
126+
])
127+
128+
# sum the contributions of the distal and proximal ends
129+
A_sm = A_sm_de + A_sm_pe
121130

122131
return A_sm
123132

@@ -173,18 +182,18 @@ def stiffness_fn(
173182
B_xi: Strain basis matrix
174183
formulate_in_strain_space: whether to formulate the elastic matrix in the strain space
175184
Returns:
176-
K: elastic matrix of shape (n_q, n_q) if formulate_in_strain_space is False or (n_xi, n_xi) otherwise
185+
S: elastic matrix of shape (n_q, n_q) if formulate_in_strain_space is False or (n_xi, n_xi) otherwise
177186
"""
178187
# stiffness matrix of shape (num_segments, 3, 3)
179-
S = vmap(
188+
S_sms = vmap(
180189
_compute_stiffness_matrix_for_segment
181190
)(
182191
params["l"], params["r"], params["r_cham_in"], params["r_cham_out"], params["varphi_cham"], params["E"]
183192
)
184-
# we define the elastic matrix of shape (n_xi, n_xi) as K(xi) = K @ xi where K is equal to
185-
K = blk_diag(S)
193+
# we define the elastic matrix of shape (n_xi, n_xi) as K(xi) = S @ xi where K is equal to
194+
S = blk_diag(S_sms)
186195

187196
if not formulate_in_strain_space:
188-
K = B_xi.T @ K @ B_xi
197+
S = B_xi.T @ S @ B_xi
189198

190-
return K
199+
return S

0 commit comments

Comments
 (0)