pose_conversion
convert_pose_axis_order(pose, target_axis_order, joint_preset=JointPreset.ALL_BIOLOGICAL, ref_fly_kwargs=dict(), fitted_fly_kwargs=dict())
¶
Convert a KinematicPose to a different joint axis order.
Builds two fly models (one per axis order), fits the target-order model's joint angles to match the reference model's body poses using IK, and returns the converted pose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pose
|
KinematicPose
|
Input pose to convert. |
required |
target_axis_order
|
AxisOrder
|
Axis order for the output pose. |
required |
joint_preset
|
JointPreset
|
Joint preset to use for both models. |
ALL_BIOLOGICAL
|
ref_fly_kwargs
|
dict
|
Extra kwargs passed to the reference |
dict()
|
fitted_fly_kwargs
|
dict
|
Extra kwargs passed to the target |
dict()
|
Returns:
| Type | Description |
|---|---|
KinematicPose
|
A |
Source code in src/flygym/utils/pose_conversion.py
fit_qpos_to_xpos_xquat(mj_model, mj_data, target_xpos, target_xquat, fitting_pos_weight=1.0, fitting_rot_weight=1.0, max_iters=100)
¶
Fit joint angles (qpos) to match target body positions and orientations.
Uses L-BFGS-B optimization to minimize a weighted sum of position and rotation errors across all bodies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mj_model
|
MjModel
|
Compiled MuJoCo model. |
required |
mj_data
|
MjData
|
Associated MuJoCo data (modified in place during optimization). |
required |
target_xpos
|
ndarray
|
Target global body positions, shape |
required |
target_xquat
|
ndarray
|
Target global body quaternions, shape |
required |
fitting_pos_weight
|
float
|
Weight applied to positional error. |
1.0
|
fitting_rot_weight
|
float
|
Weight applied to rotational error. |
1.0
|
max_iters
|
int
|
Maximum number of optimizer iterations. |
100
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Optimized qpos array, shape |
Source code in src/flygym/utils/pose_conversion.py
get_body_names(mj_model)
¶
Return a list of body names in the order they appear in the model.
get_xpos0_xquat0(mj_model, mj_data)
¶
Return body positions and quaternions at keyframe 0.
Resets to keyframe 0 and runs forward kinematics.
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of |
ndarray
|
|
Source code in src/flygym/utils/pose_conversion.py
qpos_to_kinematic_pose(mj_model, qpos, axis_order)
¶
Convert a qpos array to a KinematicPose using left-side joints only.
Right-side angles are populated by mirroring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mj_model
|
MjModel
|
Compiled MuJoCo model. |
required |
qpos
|
ndarray
|
Joint position vector, shape |
required |
axis_order
|
AxisOrder
|
The axis order used for the model's joints. |
required |
Returns:
| Type | Description |
|---|---|
KinematicPose
|
A |