11import argparse
2+ import os
23
34import numpy as np
45from tqdm import tqdm
@@ -21,14 +22,20 @@ def main():
2122
2223 ########################## create a scene ##########################
2324 scene = gs .Scene (
24- sim_options = gs .options .SimOptions (dt = args .timestep ),
25- vis_options = gs .options .VisOptions (show_world_frame = False ),
25+ sim_options = gs .options .SimOptions (
26+ dt = args .timestep ,
27+ ),
28+ vis_options = gs .options .VisOptions (
29+ show_world_frame = False ,
30+ ),
2631 viewer_options = gs .options .ViewerOptions (
2732 camera_pos = (3.5 , 0.0 , 2.5 ),
2833 camera_lookat = (0.0 , 0.0 , 0.5 ),
2934 camera_fov = 40 ,
3035 ),
31- profiling_options = gs .options .ProfilingOptions (show_FPS = False ),
36+ profiling_options = gs .options .ProfilingOptions (
37+ show_FPS = False ,
38+ ),
3239 show_viewer = args .vis ,
3340 )
3441
@@ -40,6 +47,7 @@ def main():
4047 end_effector = franka .get_link ("hand" )
4148 motors_dof = (0 , 1 , 2 , 3 , 4 , 5 , 6 )
4249
50+ ########################## record sensor data ##########################
4351 imu = scene .add_sensor (
4452 gs .sensors .IMU (
4553 entity_idx = franka .idx ,
@@ -59,25 +67,38 @@ def main():
5967 draw_debug = True ,
6068 )
6169 )
62- labels = {"lin_acc" : ("acc_x" , "acc_y" , "acc_z" ), "ang_vel" : ("gyro_x" , "gyro_y" , "gyro_z" )}
6370 if args .vis :
71+ xyz = ("x" , "y" , "z" )
72+ labels = {"lin_acc" : xyz , "true_lin_acc" : xyz , "ang_vel" : xyz , "true_ang_vel" : xyz }
73+
74+ def data_func ():
75+ data = imu .read ()
76+ true_data = imu .read_ground_truth ()
77+ return {
78+ "lin_acc" : data .lin_acc ,
79+ "true_lin_acc" : true_data .lin_acc ,
80+ "ang_vel" : data .ang_vel ,
81+ "true_ang_vel" : true_data .ang_vel ,
82+ }
83+
6484 if IS_PYQTGRAPH_AVAILABLE :
65- imu .start_recording (gs .recorders .PyQtLinePlot (title = "IMU Measured Data" , labels = labels ))
6685 scene .start_recording (
67- imu . read_ground_truth ,
86+ data_func ,
6887 gs .recorders .PyQtLinePlot (title = "IMU Ground Truth Data" , labels = labels ),
6988 )
7089 elif IS_MATPLOTLIB_AVAILABLE :
7190 gs .logger .info ("pyqtgraph not found, falling back to matplotlib." )
72- imu .start_recording (gs .recorders .MPLLinePlot (title = "IMU Measured Data" , labels = labels ))
7391 scene .start_recording (
74- imu . read_ground_truth ,
92+ data_func ,
7593 gs .recorders .MPLLinePlot (title = "IMU Ground Truth Data" , labels = labels ),
7694 )
7795 else :
7896 print ("matplotlib or pyqtgraph not found, skipping real-time plotting." )
7997
80- imu .start_recording (gs .recorders .NPZFile (filename = "imu_data.npz" ))
98+ scene .start_recording (
99+ data_func = lambda : imu .read ()._asdict (),
100+ rec_options = gs .recorders .NPZFile (filename = "imu_data.npz" ),
101+ )
81102
82103 ########################## build ##########################
83104 scene .build ()
@@ -98,7 +119,7 @@ def main():
98119 rate = np .deg2rad (2.0 )
99120
100121 try :
101- steps = int (args .seconds / args .timestep )
122+ steps = int (args .seconds / args .timestep ) if "PYTEST_VERSION" not in os . environ else 5
102123 for i in tqdm (range (steps )):
103124 scene .step ()
104125
0 commit comments