Skip to content

Commit

Permalink
Run formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoelzle committed Oct 26, 2023
1 parent c084130 commit d340015
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 44 deletions.
4 changes: 3 additions & 1 deletion examples/simulate_planar_hsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def draw_robot(
params, q, s_ps
) # poses of virtual backbone
chiL_ps = batched_forward_kinematics_rod_fn(params, q, s_ps, 0) # poses of left rod
chiR_ps = batched_forward_kinematics_rod_fn(params, q, s_ps, 1) # poses of right rod
chiR_ps = batched_forward_kinematics_rod_fn(
params, q, s_ps, 1
) # poses of right rod
# poses of the platforms
chip_ps = batched_forward_kinematics_platform_fn(
params, q, jnp.arange(0, num_segments)
Expand Down
69 changes: 45 additions & 24 deletions src/jsrm/parameters/hsa_params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
__all__ = [
"generate_base_params_for_fpu", "generate_base_params_for_epu",
"PARAMS_FPU_CONTROL", "PARAMS_FPU_SYSTEM_ID",
"PARAMS_EPU_CONTROL", "PARAMS_EPU_SYSTEM_ID",
"generate_base_params_for_fpu",
"generate_base_params_for_epu",
"PARAMS_FPU_CONTROL",
"PARAMS_FPU_SYSTEM_ID",
"PARAMS_EPU_CONTROL",
"PARAMS_EPU_SYSTEM_ID",
]

from jax import Array
Expand All @@ -10,9 +13,9 @@


def generate_common_base_params(
num_segments: int = 1,
num_rods_per_segment: int = 4,
end_effector_attached: int = False
num_segments: int = 1,
num_rods_per_segment: int = 4,
end_effector_attached: int = False,
) -> Dict[str, Array]:
assert num_rods_per_segment % 2 == 0, "num_rods_per_segment must be even"

Expand Down Expand Up @@ -52,7 +55,9 @@ def generate_common_base_params(
if end_effector_attached:
# the end-effector is moved by 25mm in the y-dir relative to the top surface of the HSA platform
params["chiee_off"] = jnp.array([0.0, 0.025, 0.0])
params["mpl"] = jnp.array(0.018) # the end-effector attachment has a mass of 18g
params["mpl"] = jnp.array(
0.018
) # the end-effector attachment has a mass of 18g
# the end-effector attachment has a center of gravity of 3.63mm in y-dir from its base.
# as it has a thickness of 25mm, this is -21.37mm from the top surface (i.e., end-effector position)
params["CoGpl"] = jnp.array([0.0, -0.02137])
Expand All @@ -61,12 +66,14 @@ def generate_common_base_params(


def generate_base_params_for_fpu(
num_segments: int = 1,
num_rods_per_segment: int = 4,
rod_multiplier: int = 1,
**kwargs
num_segments: int = 1,
num_rods_per_segment: int = 4,
rod_multiplier: int = 1,
**kwargs,
) -> Dict[str, Array]:
common_params = generate_common_base_params(num_segments, num_rods_per_segment, **kwargs)
common_params = generate_common_base_params(
num_segments, num_rods_per_segment, **kwargs
)

ones_rod = jnp.ones((num_segments, num_rods_per_segment))
# old params (1st ISER submission)
Expand Down Expand Up @@ -144,7 +151,9 @@ def generate_base_params_for_fpu(
"rin": (25.4e-3 / 2 - 2.43e-3) * ones_rod, # this is for FPU rods
# mass of FPU rod: 14 g
# For FPU, this corresponds to a measure volume of 0000175355 m^3 --> rho = 798.38 kg/m^3
"rhor": 798.38 * rod_multiplier * ones_rod, # Volumetric density of rods [kg/m^3],
"rhor": 798.38
* rod_multiplier
* ones_rod, # Volumetric density of rods [kg/m^3],
# Volumetric density of platform [kg/m^3],
# weight of platform + marker holder + cylinder top piece: 0.107 kg
# subtracting 4 x 9g for distal cap: 0.071 kg
Expand Down Expand Up @@ -185,12 +194,14 @@ def generate_base_params_for_fpu(


def generate_base_params_for_epu(
num_segments: int = 1,
num_rods_per_segment: int = 4,
rod_multiplier: int = 1,
**kwargs
num_segments: int = 1,
num_rods_per_segment: int = 4,
rod_multiplier: int = 1,
**kwargs,
) -> Dict[str, Array]:
common_params = generate_common_base_params(num_segments, num_rods_per_segment, **kwargs)
common_params = generate_common_base_params(
num_segments, num_rods_per_segment, **kwargs
)

ones_rod = jnp.ones((num_segments, num_rods_per_segment))
params = common_params | {
Expand All @@ -200,7 +211,9 @@ def generate_base_params_for_epu(
"rin": (25.4e-3 / 2 - 4.76e-3) * ones_rod, # this is for EPU rods
# mass of EPU rod: 26 g
# For EPU, this corresponds to a measure volume of 0000314034 m^3 --> rho = 827.94 kg/m^3
"rhor": 827.94 * rod_multiplier * ones_rod, # Volumetric density of rods [kg/m^3],
"rhor": 827.94
* rod_multiplier
* ones_rod, # Volumetric density of rods [kg/m^3],
# Volumetric density of platform [kg/m^3],
# weight of platform + marker holder + cylinder top piece: 0.107 kg
# subtracting 4 x 9g for distal cap: 0.071 kg
Expand All @@ -218,7 +231,7 @@ def generate_base_params_for_epu(
# Nominal shear stiffness of each rod [N]
"S_sh_hat": 4.28135773e-02 * rod_multiplier * ones_rod,
# Nominal axial stiffness of each rod [N]
"S_a_hat": 0. * rod_multiplier * ones_rod,
"S_a_hat": 0.0 * rod_multiplier * ones_rod,
# Elastic coupling between bending and shear [Nm/rad]
"S_b_sh": 5.04204068e-04 * rod_multiplier * ones_rod,
# Scaling of bending stiffness with twist strain [Nm^3/rad]
Expand All @@ -240,21 +253,29 @@ def generate_base_params_for_epu(
return params


PARAMS_FPU_SYSTEM_ID = generate_base_params_for_fpu(num_segments=1, num_rods_per_segment=4)
PARAMS_FPU_SYSTEM_ID = generate_base_params_for_fpu(
num_segments=1, num_rods_per_segment=4
)
PARAMS_FPU_SYSTEM_ID.update(
{
"h": jnp.array([[1.0, -1.0, 1.0, -1.0]]),
"roff": 24e-3 * jnp.array([[1.0, 1.0, -1.0, -1.0]]),
}
)
PARAMS_FPU_CONTROL = generate_base_params_for_fpu(num_segments=1, num_rods_per_segment=2, rod_multiplier=2)
PARAMS_FPU_CONTROL = generate_base_params_for_fpu(
num_segments=1, num_rods_per_segment=2, rod_multiplier=2
)

PARAMS_EPU_SYSTEM_ID = generate_base_params_for_epu(num_segments=1, num_rods_per_segment=4)
PARAMS_EPU_SYSTEM_ID = generate_base_params_for_epu(
num_segments=1, num_rods_per_segment=4
)
PARAMS_EPU_SYSTEM_ID.update(
{
"h": jnp.array([[1.0, -1.0, 1.0, -1.0]]),
"roff": 24e-3 * jnp.array([[1.0, 1.0, -1.0, -1.0]]),
}
)

PARAMS_EPU_CONTROL = generate_base_params_for_epu(num_segments=1, num_rods_per_segment=2, rod_multiplier=2)
PARAMS_EPU_CONTROL = generate_base_params_for_epu(
num_segments=1, num_rods_per_segment=2, rod_multiplier=2
)
12 changes: 9 additions & 3 deletions src/jsrm/symbolic_derivation/planar_hsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def symbolically_derive_planar_hsa_model(
# bending rest strain of each rod
kappa_b_eq = sp.Matrix(kappa_b_eq_syms).reshape(num_segments, num_rods_per_segment)
# shear rest strain of each rod
sigma_sh_eq = sp.Matrix(sigma_sh_eq_syms).reshape(num_segments, num_rods_per_segment)
sigma_sh_eq = sp.Matrix(sigma_sh_eq_syms).reshape(
num_segments, num_rods_per_segment
)
# axial rest strain of each rod
sigma_a_eq = sp.Matrix(sigma_a_eq_syms).reshape(num_segments, num_rods_per_segment)
C_varepsilon = sp.Matrix(C_varepsilon_syms).reshape(
Expand Down Expand Up @@ -303,7 +305,9 @@ def symbolically_derive_planar_hsa_model(

# strains in physical HSA rod
pxir = _sym_beta_fn(vxi, roff[i, j])
pxi_eqr = sp.Matrix([[kappa_b_eq[i, j]], [sigma_sh_eq[i, j]], [sigma_a_eq[i, j]]])
pxi_eqr = sp.Matrix(
[[kappa_b_eq[i, j]], [sigma_sh_eq[i, j]], [sigma_a_eq[i, j]]]
)
# twist angle of the current rod
phir = phi[i * num_rods_per_segment + j]

Expand Down Expand Up @@ -468,7 +472,9 @@ def symbolically_derive_planar_hsa_model(
pee = p_prev # end-effector position
thee = th_prev # end-effector orientation
# rotation matrix of the last platform
R_last_last_platform = sp.Matrix([[sp.cos(thee), -sp.sin(thee)], [sp.sin(thee), sp.cos(thee)]])
R_last_last_platform = sp.Matrix(
[[sp.cos(thee), -sp.sin(thee)], [sp.sin(thee), sp.cos(thee)]]
)
# add the rigid offset of the end-effector from the distal end of the last platform
pee += R_last_last_platform @ sp.Matrix([chiee_off_syms[0], chiee_off_syms[1]])
thee += chiee_off_syms[2]
Expand Down
38 changes: 22 additions & 16 deletions src/jsrm/systems/planar_hsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,28 +462,34 @@ def inverse_kinematics_end_effector_fn(
)

# transformation from the base to the end-effector
T_b_to_ee = jnp.array([
[jnp.cos(chiee[2]), -jnp.sin(chiee[2]), chiee[0]],
[jnp.sin(chiee[2]), jnp.cos(chiee[2]), chiee[1]],
[0.0, 0.0, 1.0]
])
T_b_to_ee = jnp.array(
[
[jnp.cos(chiee[2]), -jnp.sin(chiee[2]), chiee[0]],
[jnp.sin(chiee[2]), jnp.cos(chiee[2]), chiee[1]],
[0.0, 0.0, 1.0],
]
)

# transformation from the distal end of the virtual backbone to the end-effector
T_de_to_ee = jnp.array([
[jnp.cos(chiee_off[2]), -jnp.sin(chiee_off[2]), chiee_off[0]],
[jnp.sin(chiee_off[2]), jnp.cos(chiee_off[2]), ldc + hp + chiee_off[1]],
[0.0, 0.0, 1.0]
])
T_de_to_ee = jnp.array(
[
[jnp.cos(chiee_off[2]), -jnp.sin(chiee_off[2]), chiee_off[0]],
[jnp.sin(chiee_off[2]), jnp.cos(chiee_off[2]), ldc + hp + chiee_off[1]],
[0.0, 0.0, 1.0],
]
)

# compute the transformation from the proximal to the distal end of the virtual backbone
T_pe_to_de = jnp.linalg.inv(T_b_to_pe) @ T_b_to_ee @ jnp.linalg.inv(T_de_to_ee)
T_pe_to_de = jnp.linalg.inv(T_b_to_pe) @ T_b_to_ee @ jnp.linalg.inv(T_de_to_ee)

# compute the SE(2) pose from the transformation matrix
vchi_pe_to_de = jnp.array([
T_pe_to_de[0, 2],
T_pe_to_de[1, 2],
jnp.arctan2(T_pe_to_de[1, 0], T_pe_to_de[0, 0])
])
vchi_pe_to_de = jnp.array(
[
T_pe_to_de[0, 2],
T_pe_to_de[1, 2],
jnp.arctan2(T_pe_to_de[1, 0], T_pe_to_de[0, 0]),
]
)

# extract the x and y position and the orientation
px, py, th = vchi_pe_to_de[0], vchi_pe_to_de[1], vchi_pe_to_de[2]
Expand Down

0 comments on commit d340015

Please sign in to comment.