-
Couldn't load subscription status.
- Fork 2.5k
[FEATURE] Add Sensor.draw_debug method. #1770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
duburcqa
merged 4 commits into
Genesis-Embodied-AI:main
from
Milotrince:sensor_draw_debug
Sep 30, 2025
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import argparse | ||
|
|
||
| from tqdm import tqdm | ||
|
|
||
| import genesis as gs | ||
| from genesis.recorders.plotters import IS_MATPLOTLIB_AVAILABLE, IS_PYQTGRAPH_AVAILABLE | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("-dt", "--timestep", type=float, default=1e-2, help="Simulation time step") | ||
| parser.add_argument("-v", "--vis", action="store_true", default=True, help="Show visualization GUI") | ||
| parser.add_argument("-nv", "--no-vis", action="store_false", dest="vis", help="Disable visualization GUI") | ||
| parser.add_argument("-c", "--cpu", action="store_true", help="Use CPU instead of GPU") | ||
| parser.add_argument("-t", "--seconds", type=float, default=2, help="Number of seconds to simulate") | ||
| parser.add_argument("-f", "--force", action="store_true", default=True, help="Use ContactForceSensor (xyz float)") | ||
| parser.add_argument("-nf", "--no-force", action="store_false", dest="force", help="Use ContactSensor (boolean)") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| ########################## init ########################## | ||
| gs.init(backend=gs.cpu if args.cpu else gs.gpu, logging_level=None) | ||
|
|
||
| ########################## scene setup ########################## | ||
| scene = gs.Scene( | ||
| sim_options=gs.options.SimOptions(dt=args.timestep), | ||
| rigid_options=gs.options.RigidOptions( | ||
| use_gjk_collision=True, | ||
| constraint_timeconst=max(0.01, 2 * args.timestep), | ||
| ), | ||
| vis_options=gs.options.VisOptions(show_world_frame=True), | ||
| profiling_options=gs.options.ProfilingOptions(show_FPS=False), | ||
| show_viewer=args.vis, | ||
| ) | ||
|
|
||
| scene.add_entity(gs.morphs.Plane()) | ||
|
|
||
| foot_link_names = ["FR_foot", "FL_foot", "RR_foot", "RL_foot"] | ||
| go2 = scene.add_entity( | ||
| gs.morphs.URDF( | ||
| file="urdf/go2/urdf/go2.urdf", | ||
| pos=(0.0, 0.0, 0.2), | ||
| links_to_keep=foot_link_names, | ||
| ) | ||
| ) | ||
|
|
||
| for link_name in foot_link_names: | ||
| if args.force: | ||
| sensor_options = gs.sensors.ContactForce( | ||
| entity_idx=go2.idx, | ||
| link_idx_local=go2.get_link(link_name).idx_local, | ||
| draw_debug=True, | ||
| ) | ||
| plot_kwargs = dict( | ||
| title=f"{link_name} Force Sensor Data", | ||
| labels=["force_x", "force_y", "force_z"], | ||
| ) | ||
| else: | ||
| sensor_options = gs.sensors.Contact( | ||
| entity_idx=go2.idx, | ||
| link_idx_local=go2.get_link(link_name).idx_local, | ||
| draw_debug=True, | ||
| ) | ||
| plot_kwargs = dict( | ||
| title=f"{link_name} Contact Sensor Data", | ||
| labels=["in_contact"], | ||
| ) | ||
|
|
||
| sensor = scene.add_sensor(sensor_options) | ||
|
|
||
| if IS_PYQTGRAPH_AVAILABLE: | ||
| sensor.start_recording(gs.recorders.PyQtLinePlot(**plot_kwargs)) | ||
| elif IS_MATPLOTLIB_AVAILABLE: | ||
| print("pyqtgraph not found, falling back to matplotlib.") | ||
| sensor.start_recording(gs.recorders.MPLLinePlot(**plot_kwargs)) | ||
| else: | ||
| print("matplotlib or pyqtgraph not found, skipping real-time plotting.") | ||
|
|
||
| scene.build() | ||
|
|
||
| try: | ||
| steps = int(args.seconds / args.timestep) | ||
| for _ in tqdm(range(steps)): | ||
| scene.step() | ||
| except KeyboardInterrupt: | ||
| gs.logger.info("Simulation interrupted, exiting.") | ||
| finally: | ||
| gs.logger.info("Simulation finished.") | ||
|
|
||
| scene.stop_recording() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.