26
26
)
27
27
28
28
29
- def factory_fn (params : Dict [str , Array ]) -> Tuple [Callable , Callable ]:
29
+ def factory_fn (params : Dict [str , Array ], verbose : bool = False ) -> Tuple [Callable , Callable ]:
30
30
"""
31
31
Factory function for the planar HSA.
32
32
Args:
33
33
params: dictionary with robot parameters
34
+ verbose: flag to print additional information
34
35
Returns:
35
36
phi2chi_static_model_fn: function that maps motor angles to the end-effector pose
36
37
jac_phi2chi_static_model_fn: function that computes the Jacobian between the actuation space and the task-space
@@ -45,6 +46,7 @@ def factory_fn(params: Dict[str, Array]) -> Tuple[Callable, Callable]:
45
46
) = planar_hsa .factory (sym_exp_filepath , strain_selector )
46
47
dynamical_matrices_fn = partial (dynamical_matrices_fn , params )
47
48
forward_kinematics_end_effector_fn = jit (partial (forward_kinematics_end_effector_fn , params ))
49
+ jacobian_end_effector_fn = jit (partial (jacobian_end_effector_fn , params ))
48
50
49
51
def residual_fn (q : Array , phi : Array ) -> Array :
50
52
q_d = jnp .zeros_like (q )
@@ -77,9 +79,10 @@ def phi2q_static_model_fn(phi: Array, q0: Array = jnp.zeros((3, ))) -> Tuple[Arr
77
79
fun = lambda q : residual_fn (q , phi ).item (),
78
80
x0 = q0 ,
79
81
jac = lambda q : jac_residual_fn (q , phi ),
80
- # options={"disp": True},
82
+ options = {"disp" : True } if verbose else None ,
81
83
)
82
- print ("Optimization converged after" , sol .nit , "iterations with residual" , sol .fun )
84
+ if verbose :
85
+ print ("Optimization converged after" , sol .nit , "iterations with residual" , sol .fun )
83
86
84
87
# configuration that minimizes the residual
85
88
q = jnp .array (sol .x )
@@ -117,13 +120,13 @@ def jac_phi2chi_static_model_fn(phi: Array, q0: Array = jnp.zeros((3, ))) -> Tup
117
120
q , aux = phi2q_static_model_fn (phi , q0 = q0 )
118
121
# approximate the Jacobian between the actuation and the task-space using finite differences
119
122
J_phi2q = approx_derivative (
120
- fun = lambda _phi : phi2q_static_model_fn (phi , q0 = q0 )[0 ],
123
+ fun = lambda _phi : phi2q_static_model_fn (_phi , q0 = q0 )[0 ],
121
124
x0 = phi ,
122
125
f0 = q ,
123
126
)
124
127
125
128
# evaluate the closed-form, analytical jacobian of the forward kinematics
126
- J_q2chi = jacobian_end_effector_fn (params , q )
129
+ J_q2chi = jacobian_end_effector_fn (q )
127
130
128
131
# evaluate the Jacobian between the actuation and the task-space
129
132
J_phi2chi = J_q2chi @ J_phi2q
0 commit comments