Skip to content

Commit ed44e6e

Browse files
committed
Run formatting
1 parent ec45c08 commit ed44e6e

File tree

5 files changed

+46
-25
lines changed

5 files changed

+46
-25
lines changed

examples/simulate_planar_hsa.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
inverse_kinematics_end_effector_fn,
6060
dynamical_matrices_fn,
6161
sys_helpers,
62-
) = planar_hsa.factory(sym_exp_filepath, strain_selector, consider_hysteresis=consider_hysteresis)
62+
) = planar_hsa.factory(
63+
sym_exp_filepath, strain_selector, consider_hysteresis=consider_hysteresis
64+
)
6365

6466
# import matplotlib.pyplot as plt
6567
# plt.plot(chi_ps[0, :], chi_ps[1, :])
@@ -91,7 +93,9 @@
9193
x0 = jnp.zeros((2 * q0.shape[0],)) # initial condition
9294
x0 = x0.at[: q0.shape[0]].set(q0) # set initial configuration
9395

94-
ode_fn = planar_hsa.ode_factory(dynamical_matrices_fn, params, consider_hysteresis=consider_hysteresis)
96+
ode_fn = planar_hsa.ode_factory(
97+
dynamical_matrices_fn, params, consider_hysteresis=consider_hysteresis
98+
)
9599
ode_term = ODETerm(ode_fn)
96100

97101
sol = diffeqsolve(
@@ -118,7 +122,7 @@
118122
video_path,
119123
video_ts=video_ts,
120124
q_ts=sol.ys[:, :3],
121-
video_width=video_width,
122-
video_height=video_height
125+
video_width=video_width,
126+
video_height=video_height,
123127
)
124128
print(f"Video saved at {video_path}")

src/jsrm/parameters/hsa_params.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,34 @@ def generate_common_base_params(
8080
# mapping hysteresis displacements to the strains
8181
# per default, we only model the hysteresis on the axial strain
8282
B_z = jax.scipy.linalg.block_diag(
83-
*[jnp.array([[0.0], [0.0], [1.0]]) for _ in range(num_segments)] # assumes 3 strains per segment
84-
83+
*[
84+
jnp.array([[0.0], [0.0], [1.0]]) for _ in range(num_segments)
85+
] # assumes 3 strains per segment
8586
)
8687
params["hysteresis"]["basis"] = B_z
8788
# number of hysteresis states
8889
n_z = params["hysteresis"]["basis"].shape[1]
8990
# ratio of post-yield and pre-yield stiffness
9091
hys_alpha_val = 0.6
91-
hys_alpha = jnp.array([(hys_alpha_val if B_z[xi_idx, :].sum() > 0 else 1.0) for xi_idx in range(3 * num_segments)])
92+
hys_alpha = jnp.array(
93+
[
94+
(hys_alpha_val if B_z[xi_idx, :].sum() > 0 else 1.0)
95+
for xi_idx in range(3 * num_segments)
96+
]
97+
)
9298
params["hysteresis"]["alpha"] = hys_alpha
9399
# params["hysteresis"]["alpha"] = 0.6 * jnp.ones((n_q, )) # ratio of post-yield and pre-yield stiffness
94-
params["hysteresis"]["beta"] = 30.0 * jnp.ones((n_z, )) # dimensionless parameter in the Bouc-Wen model
95-
params["hysteresis"]["gamma"] = 1.0 * jnp.ones((n_z, )) # dimensionless parameter in the Bouc-Wen model
96-
params["hysteresis"]["n"] = 1.0 * jnp.ones((n_z, )) # dimensionless parameter in the Bouc-Wen model
100+
params["hysteresis"]["beta"] = 30.0 * jnp.ones(
101+
(n_z,)
102+
) # dimensionless parameter in the Bouc-Wen model
103+
params["hysteresis"]["gamma"] = 1.0 * jnp.ones(
104+
(n_z,)
105+
) # dimensionless parameter in the Bouc-Wen model
106+
params["hysteresis"]["n"] = 1.0 * jnp.ones(
107+
(n_z,)
108+
) # dimensionless parameter in the Bouc-Wen model
97109
# to remove redundancy from Bouc-Wen model, choose A = 1
98-
params["hysteresis"]["A"] = jnp.ones((n_z, ))
110+
params["hysteresis"]["A"] = jnp.ones((n_z,))
99111

100112
return params
101113

src/jsrm/symbolic_derivation/planar_hsa.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ def symbolically_derive_planar_hsa_model(
341341
J_betar = sp.Matrix([[1, 0, 0], [0, 1, 0], [roff[i, j], 0, 1]])
342342

343343
# nominal stiffness matrix of the virtual backbone
344-
Shat[3 * i : 3 * (i + 1), 3 * i : 3 * (i + 1)] += J_betar.T @ Shatr @ J_betar
345-
344+
Shat[3 * i : 3 * (i + 1), 3 * i : 3 * (i + 1)] += (
345+
J_betar.T @ Shatr @ J_betar
346+
)
347+
346348
# contribution of elastic forces of current rod to the virtual backbone
347349
vKr = J_betar.T @ Shatr @ (pxir - pxi_eqr)
348350
# add contribution of elasticity vector

src/jsrm/systems/planar_hsa.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ def select_params_for_lambdify_fn(params: Dict[str, Array]) -> List[Array]:
150150
G_lambda = sp.lambdify(
151151
params_syms_cat + sym_exps["state_syms"]["xi"], sym_exps["exps"]["G"], "jax"
152152
)
153-
Shat_lambda = sp.lambdify(
154-
params_syms_cat, sym_exps["exps"]["Shat"], "jax"
155-
)
153+
Shat_lambda = sp.lambdify(params_syms_cat, sym_exps["exps"]["Shat"], "jax")
156154
K_lambda = sp.lambdify(
157155
params_syms_cat + sym_exps["state_syms"]["xi"], sym_exps["exps"]["K"], "jax"
158156
)
@@ -602,8 +600,8 @@ def dynamical_matrices_fn(
602600
B_z = params["hysteresis"]["basis"]
603601
hyst_alpha = params["hysteresis"]["alpha"]
604602
# add the post-yield potential forces
605-
K = hyst_alpha*K + (1-hyst_alpha) * Shat @ (B_z @ z)
606-
603+
K = hyst_alpha * K + (1 - hyst_alpha) * Shat @ (B_z @ z)
604+
607605
# TODO: add post-yield potential forces (i.e., hysteresis effects) to the actuation vector
608606

609607
# apply the strain basis
@@ -752,11 +750,16 @@ def ode_fn(t: float, x: Array, u: Array) -> Array:
752750

753751
n_z = B_z.shape[1]
754752
n_q = (x.shape[0] - n_z) // 2
755-
q, q_d, z = x[:n_q], x[n_q:2*n_q], x[2*n_q:]
753+
q, q_d, z = x[:n_q], x[n_q : 2 * n_q], x[2 * n_q :]
756754

757755
z_d = (B_z.T @ q_d) * (
758-
hys_params["A"] - jnp.abs(z)**hys_params["n"] * (hys_params["gamma"] + hys_params["beta"] * jnp.sign((B_z.T @ q_d) * z))
756+
hys_params["A"]
757+
- jnp.abs(z) ** hys_params["n"]
758+
* (
759+
hys_params["gamma"]
760+
+ hys_params["beta"] * jnp.sign((B_z.T @ q_d) * z)
759761
)
762+
)
760763
else:
761764
n_q = x.shape[0] // 2
762765
q, q_d = x[:n_q], x[n_q:]

src/jsrm/systems/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def substitute_params_into_all_symbolic_expressions(
3131
for exp_key, exp_val in exps.items():
3232
if issubclass(type(exp_val), list):
3333
for exp_item_idx, exp_item_val in enumerate(exp_val):
34-
exps[exp_key][
35-
exp_item_idx
36-
] = substitute_params_into_single_symbolic_expression(
37-
exp_item_val, params_syms, params
34+
exps[exp_key][exp_item_idx] = (
35+
substitute_params_into_single_symbolic_expression(
36+
exp_item_val, params_syms, params
37+
)
3838
)
3939
else:
4040
exps[exp_key] = substitute_params_into_single_symbolic_expression(
@@ -74,7 +74,7 @@ def substitute_params_into_single_symbolic_expression(
7474

7575

7676
def concatenate_params_syms(
77-
params_syms: Dict[str, Union[sp.Symbol, List[sp.Symbol]]]
77+
params_syms: Dict[str, Union[sp.Symbol, List[sp.Symbol]]],
7878
) -> List[sp.Symbol]:
7979
# concatenate the robot params symbols
8080
params_syms_cat = []

0 commit comments

Comments
 (0)