25
25
26
26
import argparse
27
27
import copy
28
+ import json
28
29
import logging
29
- import os
30
30
31
31
from pathlib import Path
32
32
33
33
import numpy as np
34
34
import open3d as o3d
35
35
36
36
from pydrake .all import (
37
- AddMultibodyPlantSceneGraph ,
38
- DiagramBuilder ,
39
- Ellipsoid ,
40
37
FixedOffsetFrame ,
41
- MeshcatVisualizer ,
42
38
MultibodyPlant ,
43
- Rgba ,
44
39
RigidTransform ,
45
- Simulator ,
46
40
SpatialInertia ,
47
- StartMeshcat ,
48
41
UnitInertia ,
49
42
)
50
43
@@ -327,7 +320,6 @@ def main():
327
320
)
328
321
parser .add_argument (
329
322
"--output_param_path" ,
330
- required = True ,
331
323
type = Path ,
332
324
help = "Path to the output parameter `.npy` file. If not provided, the parameters "
333
325
+ "are not saved to disk." ,
@@ -631,7 +623,7 @@ def main():
631
623
frame_F = payload_frame ,
632
624
body_indexes = [last_link .index ()],
633
625
)
634
- # Express inerita about CoM to match SDFormat convention
626
+ # Express inerita about CoM to match SDFormat convention.
635
627
M_PPayloadcom_Payload = M_PPayload_Payload .Shift (M_PPayload_Payload .get_com ())
636
628
logging .info (
637
629
"Difference in the last link's parameters (payload parameters). "
@@ -646,6 +638,17 @@ def main():
646
638
)
647
639
logging .info ("Payload inertia (about CoM):\n " + f"{ I_PPayloadcom_Payload } \n " )
648
640
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
+
649
652
if visualize :
650
653
visualize_object_inertia (
651
654
object_mesh_path = object_mesh_path ,
0 commit comments