Skip to content

Commit 955c5ae

Browse files
committed
Save identified object params as json
1 parent a2aa9ab commit 955c5ae

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

scripts/identify_grasped_object_payload.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,19 @@
2525

2626
import argparse
2727
import copy
28+
import json
2829
import logging
29-
import os
3030

3131
from pathlib import Path
3232

3333
import numpy as np
3434
import open3d as o3d
3535

3636
from pydrake.all import (
37-
AddMultibodyPlantSceneGraph,
38-
DiagramBuilder,
39-
Ellipsoid,
4037
FixedOffsetFrame,
41-
MeshcatVisualizer,
4238
MultibodyPlant,
43-
Rgba,
4439
RigidTransform,
45-
Simulator,
4640
SpatialInertia,
47-
StartMeshcat,
4841
UnitInertia,
4942
)
5043

@@ -327,7 +320,6 @@ def main():
327320
)
328321
parser.add_argument(
329322
"--output_param_path",
330-
required=True,
331323
type=Path,
332324
help="Path to the output parameter `.npy` file. If not provided, the parameters "
333325
+ "are not saved to disk.",
@@ -631,7 +623,7 @@ def main():
631623
frame_F=payload_frame,
632624
body_indexes=[last_link.index()],
633625
)
634-
# Express inerita about CoM to match SDFormat convention
626+
# Express inerita about CoM to match SDFormat convention.
635627
M_PPayloadcom_Payload = M_PPayload_Payload.Shift(M_PPayload_Payload.get_com())
636628
logging.info(
637629
"Difference in the last link's parameters (payload parameters). "
@@ -646,6 +638,17 @@ def main():
646638
)
647639
logging.info("Payload inertia (about CoM):\n" + f"{I_PPayloadcom_Payload}\n")
648640

641+
# Save inertial parameters to JSON.
642+
inertial_params = {
643+
"mass": float(payload_mass),
644+
"center_of_mass": com_PPayload_Payload.tolist(),
645+
"inertia_matrix": I_PPayloadcom_Payload.tolist(),
646+
}
647+
json_path = object_joint_data_path.parent / "inertial_params.json"
648+
with open(json_path, "w") as f:
649+
json.dump(inertial_params, f, indent=2)
650+
logging.info(f"Saved inertial parameters to {json_path}")
651+
649652
if visualize:
650653
visualize_object_inertia(
651654
object_mesh_path=object_mesh_path,

0 commit comments

Comments
 (0)