Skip to content

Commit ab76aea

Browse files
committed
Add B_xi to stiffness_fn interface
1 parent e192e5d commit ab76aea

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

examples/simulate_planar_pcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def draw_robot(
162162
)
163163
plt.plot(
164164
video_ts, q_ts[:, 3 * segment_idx + 2],
165-
label=r"$\sigma_\mathrm{el," + str(segment_idx + 1) + "}$ [-]"
165+
label=r"$\sigma_\mathrm{ax," + str(segment_idx + 1) + "}$ [-]"
166166
)
167167
plt.xlabel("Time [s]")
168168
plt.ylabel("Configuration")

src/jsrm/systems/planar_pcs.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def factory(
3737
strain are active / non-zero
3838
xi_eq: array of shape (3 * num_segments) with the rest strains of the rod
3939
stiffness_fn: function to compute the stiffness matrix of the system. Should have the signature
40-
stiffness_fn(params: Dict[str, Array], formulate_in_strain_space: bool) -> Array
40+
stiffness_fn(params: Dict[str, Array], B_xi, formulate_in_strain_space: bool) -> Array
4141
global_eps: small number to avoid singularities (e.g., division by zero)
4242
Returns:
4343
B_xi: strain basis matrix of shape (3 * num_segments, n_q)
@@ -204,12 +204,13 @@ def classify_segment(params: Dict[str, Array], s: Array) -> Tuple[Array, Array]:
204204

205205
if stiffness_fn is None:
206206
def stiffness_fn(
207-
params: Dict[str, Array], formulate_in_strain_space: bool = False
207+
params: Dict[str, Array], B_xi: Array, formulate_in_strain_space: bool = False
208208
) -> Array:
209209
"""
210210
Compute the stiffness matrix of the system.
211211
Args:
212212
params: Dictionary of robot parameters
213+
B_xi: Strain basis matrix
213214
formulate_in_strain_space: whether to formulate the elastic matrix in the strain space
214215
Returns:
215216
K: elastic matrix of shape (n_q, n_q) if formulate_in_strain_space is False or (n_xi, n_xi) otherwise
@@ -329,7 +330,7 @@ def dynamical_matrices_fn(
329330
xi_epsed = apply_eps_to_bend_strains(xi, eps)
330331

331332
# compute the stiffness matrix
332-
K = stiffness_fn(params, formulate_in_strain_space=True)
333+
K = stiffness_fn(params, B_xi, formulate_in_strain_space=True)
333334

334335
# dissipative matrix from the parameters
335336
D = params.get("D", jnp.zeros((n_xi, n_xi)))
@@ -385,7 +386,7 @@ def potential_energy_fn(
385386
xi_epsed = apply_eps_to_bend_strains(xi, eps)
386387

387388
# compute the stiffness matrix
388-
K = stiffness_fn(params, formulate_in_strain_space=True)
389+
K = stiffness_fn(params, B_xi, formulate_in_strain_space=True)
389390
# elastic energy
390391
U_K = (xi - xi_eq).T @ K @ (xi - xi_eq) # evaluate K(xi) = K @ xi
391392

src/jsrm/systems/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ def compute_planar_stiffness_matrix(l: Array, A: Array, Ib: Array, E: Array, G:
121121
Returns:
122122
S: stiffness matrix of shape (3, 3)
123123
"""
124-
S = l* jnp.diag(jnp.stack([Ib * E, 4 / 3 * A * G, A * E], axis=0))
124+
S = l * jnp.diag(jnp.stack([Ib * E, 4 / 3 * A * G, A * E], axis=0))
125125

126126
return S

0 commit comments

Comments
 (0)