Skip to content

Commit 4d42ffd

Browse files
committed
Continue implementing actuation_mapping_fn
1 parent ae1b67d commit 4d42ffd

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/jsrm/systems/planar_pcs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ def stiffness_fn(
238238

239239
if actuation_mapping_fn is None:
240240
def actuation_mapping_fn(
241+
forward_kinematics_fn: Callable,
242+
jacobian_fn: Callable,
241243
params: Dict[str, Array],
242244
B_xi: Array,
243245
q: Array,
@@ -246,6 +248,8 @@ def actuation_mapping_fn(
246248
Returns the actuation matrix that maps the actuation space to the configuration space.
247249
Assumes the fully actuated and identity actuation matrix.
248250
Args:
251+
forward_kinematics_fn: function to compute the forward kinematics
252+
jacobian_fn: function to compute the Jacobian
249253
params: dictionary with robot parameters
250254
B_xi: strain basis matrix
251255
q: configuration of the robot
@@ -355,7 +359,7 @@ def dynamical_matrices_fn(
355359
# compute the stiffness matrix
356360
K = stiffness_fn(params, B_xi, formulate_in_strain_space=True)
357361
# compute the actuation matrix
358-
A = actuation_mapping_fn(params, B_xi, q)
362+
A = actuation_mapping_fn(forward_kinematics_fn, actuation_mapping_fn, params, B_xi, q)
359363

360364
# dissipative matrix from the parameters
361365
D = params.get("D", jnp.zeros((n_xi, n_xi)))

src/jsrm/systems/pneumatic_planar_pcs.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import jax.numpy as jnp
44
from jsrm.math_utils import blk_diag
55
import numpy as onp
6-
from typing import Dict, Optional, Tuple, Union
6+
from typing import Callable, Dict, Optional, Tuple, Union
77

88
from .planar_pcs import factory as planar_pcs_factory
99

@@ -37,13 +37,17 @@ def factory(
3737
actuation_basis = actuation_basis.at[2 * i + 1, j + 1].set(1.0)
3838

3939
def actuation_mapping_fn(
40+
forward_kinematics_fn: Callable,
41+
jacobian_fn: Callable,
4042
params: Dict[str, Array],
4143
B_xi: Array,
4244
q: Array,
4345
) -> Array:
4446
"""
4547
Returns the actuation matrix that maps the actuation space to the configuration space.
4648
Args:
49+
forward_kinematics_fn: function to compute the forward kinematics
50+
jacobian_fn: function to compute the Jacobian
4751
params: dictionary with robot parameters
4852
B_xi: strain basis matrix
4953
q: configuration of the robot
@@ -57,8 +61,32 @@ def actuation_mapping_fn(
5761
# number of strains
5862
n_xi = xi.shape[0]
5963

60-
for i in range(num_segments):
61-
pass
64+
# all segment bases and tips
65+
sms = jnp.concat([jnp.zeros((1,)), jnp.cumsum(params["l"])], axis=0)
66+
print("sms =\n", sms)
67+
68+
# compute the poses of all segment tips
69+
chi_sms = vmap(forward_kinematics_fn, in_axes=(None, None, 0))(params, q, sms)
70+
71+
# compute the Jacobian for all segment tips
72+
J_sms = vmap(jacobian_fn, in_axes=(None, None, 0))(params, q, sms)
73+
74+
def compute_actuation_matrix_for_segment(
75+
chi_sm: Array, J_sm: Array, xi: Array
76+
) -> Array:
77+
"""
78+
Compute the actuation matrix for a single segment.
79+
Args:
80+
chi_sm: tip position of the segment
81+
J_sm: Jacobian of the segment
82+
xi: strains of the segment
83+
Returns:
84+
A_sm: actuation matrix of shape (n_xi, 2)
85+
"""
86+
# compute the actuation matrix for a single segment
87+
A_sm = jnp.zeros((n_xi, 2))
88+
return A_sm
89+
6290

6391
A = jnp.zeros((n_xi, 2 * num_segments))
6492

0 commit comments

Comments
 (0)