@@ -46,46 +46,42 @@ def main():
4646
4747 for link_name in foot_link_names :
4848 if args .force :
49- force_sensor = scene .add_sensor (
50- gs .sensors .ContactForce (
51- entity_idx = go2 .idx ,
52- link_idx_local = go2 .get_link (link_name ).idx_local ,
53- draw_debug = True ,
54- )
49+ sensor_options = gs .sensors .ContactForce (
50+ entity_idx = go2 .idx ,
51+ link_idx_local = go2 .get_link (link_name ).idx_local ,
52+ draw_debug = True ,
53+ )
54+ plot_kwargs = dict (
55+ title = f"{ link_name } Force Sensor Data" ,
56+ labels = ["force_x" , "force_y" , "force_z" ],
5557 )
56- if IS_PYQTGRAPH_AVAILABLE :
57- force_sensor .start_recording (
58- gs .recorders .PyQtLinePlot (
59- title = "Force Sensor Data" ,
60- labels = ["force_x" , "force_y" , "force_z" ],
61- )
62- )
63- elif IS_MATPLOTLIB_AVAILABLE :
64- print ("pyqtgraph not found, falling back to matplotlib." )
65- force_sensor .start_recording (
66- gs .recorders .MPLLinePlot (
67- title = "Force Sensor Data" ,
68- labels = ["force_x" , "force_y" , "force_z" ],
69- )
70- )
71- else :
72- print ("matplotlib or pyqtgraph not found, skipping real-time plotting." )
7358 else :
74- contact_sensor = scene .add_sensor (
75- gs .sensors .Contact (
76- entity_idx = go2 .idx ,
77- link_idx_local = go2 .get_link (link_name ).idx_local ,
78- draw_debug = True ,
79- )
59+ sensor_options = gs .sensors .Contact (
60+ entity_idx = go2 .idx ,
61+ link_idx_local = go2 .get_link (link_name ).idx_local ,
62+ draw_debug = True ,
63+ )
64+ plot_kwargs = dict (
65+ title = f"{ link_name } Contact Sensor Data" ,
66+ labels = ["in_contact" ],
8067 )
8168
69+ sensor = scene .add_sensor (sensor_options )
70+
71+ if IS_PYQTGRAPH_AVAILABLE :
72+ sensor .start_recording (gs .recorders .PyQtLinePlot (** plot_kwargs ))
73+ elif IS_MATPLOTLIB_AVAILABLE :
74+ print ("pyqtgraph not found, falling back to matplotlib." )
75+ sensor .start_recording (gs .recorders .MPLLinePlot (** plot_kwargs ))
76+ else :
77+ print ("matplotlib or pyqtgraph not found, skipping real-time plotting." )
78+
8279 scene .build ()
8380
8481 try :
8582 steps = int (args .seconds / args .timestep )
8683 for _ in tqdm (range (steps )):
8784 scene .step ()
88-
8985 except KeyboardInterrupt :
9086 gs .logger .info ("Simulation interrupted, exiting." )
9187 finally :
0 commit comments