agx-openplx 0.15.10__cp312-cp312-manylinux_2_39_x86_64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. agx_openplx-0.15.10.dist-info/METADATA +67 -0
  2. agx_openplx-0.15.10.dist-info/RECORD +41 -0
  3. agx_openplx-0.15.10.dist-info/WHEEL +4 -0
  4. agx_openplx-0.15.10.dist-info/entry_points.txt +8 -0
  5. openplx/Core.py +7781 -0
  6. openplx/DriveTrain.py +8972 -0
  7. openplx/Math.py +5372 -0
  8. openplx/Physics.py +39861 -0
  9. openplx/Physics1D.py +5534 -0
  10. openplx/Physics3D.py +39782 -0
  11. openplx/Robotics.py +14922 -0
  12. openplx/Simulation.py +1056 -0
  13. openplx/Terrain.py +3891 -0
  14. openplx/Urdf.py +654 -0
  15. openplx/Vehicles.py +8793 -0
  16. openplx/Visuals.py +3901 -0
  17. openplx/_AgxOpenPlxPyApi.cpython-312-x86_64-linux-gnu.so +0 -0
  18. openplx/_CorePythonSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  19. openplx/_DriveTrainSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  20. openplx/_MathSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  21. openplx/_Physics1DSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  22. openplx/_Physics3DSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  23. openplx/_PhysicsSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  24. openplx/_RoboticsSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  25. openplx/_SimulationSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  26. openplx/_TerrainSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  27. openplx/_UrdfSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  28. openplx/_VehiclesSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  29. openplx/_VisualsSwig.cpython-312-x86_64-linux-gnu.so +0 -0
  30. openplx/__init__.py +55 -0
  31. openplx/agxtoopenplx.py +55 -0
  32. openplx/anytoopenplx.py +44 -0
  33. openplx/api.py +1353 -0
  34. openplx/migrate.py +190 -0
  35. openplx/migration_hint.py +14 -0
  36. openplx/migrations.py +703 -0
  37. openplx/openplx_application.py +138 -0
  38. openplx/openplx_serialize.py +35 -0
  39. openplx/openplx_validate.py +57 -0
  40. openplx/openplx_view.py +14 -0
  41. openplx/versionaction.py +11 -0
@@ -0,0 +1,138 @@
1
+ """
2
+ Base class for OpenPLX applications
3
+ """
4
+ import os
5
+ import sys
6
+ import signal
7
+
8
+ from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, Action, SUPPRESS
9
+ import agxOSG
10
+ from openplxbundles import bundle_path
11
+
12
+ # Import useful utilities to access the current simulation, graphics root and application
13
+ from agxPythonModules.utils.environment import init_app, simulation, application, root
14
+
15
+ from openplx import InputSignalQueue, OutputSignalQueue, InputSignalListener, OutputSignalListener, OsgClickAdapter
16
+ from openplx import load_from_file, OptParams, addVisuals, addDeformableVisualUpdaters, __version__, set_log_level, add_file_changed_listener
17
+ from openplx.versionaction import VersionAction
18
+
19
+ def dummy_build_scene():
20
+ pass
21
+
22
+ class AgxHelpAction(Action):
23
+ def __call__(self, parser, namespace, values, option_string=None):
24
+ sys.argv.append("--usage")
25
+ OpenPlxApplication(dummy_build_scene).start_agx()
26
+ sys.exit(0)
27
+
28
+ class AllowCtrlBreakListener(agxOSG.ExampleApplicationListener): # pylint: disable=too-few-public-methods
29
+ pass
30
+
31
+ class OpenPlxApplication:
32
+
33
+ def __init__(self, build_scene, build_scene_file=None):
34
+ """
35
+ AGX needs to know the build scene function and which file
36
+ If build_scene_file is None then it is inferred from the build_scene function.
37
+ """
38
+ self.build_scene = build_scene
39
+ self.build_scene_file = sys.modules[self.build_scene.__module__].__file__ if build_scene_file is None else build_scene_file
40
+
41
+ @staticmethod
42
+ def setup_args_parser(openplxfile = None):
43
+ parser = ArgumentParser(description="View OpenPLX models", formatter_class=ArgumentDefaultsHelpFormatter)
44
+ if openplxfile is None:
45
+ parser.add_argument("openplxfile", help="the .openplx file to load")
46
+ parser.add_argument("[AGX flags ...]", help="any additional AGX flags", default="", nargs="?")
47
+ parser.add_argument(
48
+ "--bundle-path",
49
+ help="list of path to bundle dependencies if any. Overrides environment variable OPENPLX_BUNDLE_PATH.",
50
+ metavar="<bundle_path>",
51
+ default=bundle_path(),
52
+ )
53
+ parser.add_argument("--click-addr", type=str, help="Address for Click to listen on, e.g. ipc:///tmp/click.ipc", default="tcp://*:5555")
54
+ parser.add_argument("--debug-render-frames", action="store_true", help="enable rendering of frames for mate connectors and rigid bodies.")
55
+ parser.add_argument("--enable-click", help="Enable sending and receiving signals as Click Messages", action="store_true", default=SUPPRESS)
56
+ parser.add_argument("--loglevel",
57
+ choices=["trace", "debug", "info", "warn", "error", "critical", "off"],
58
+ help="Set log level",
59
+ default="info")
60
+ parser.add_argument("--modelname", help="The model to load (defaults to last model in file)", metavar="<name>", default=None)
61
+ parser.add_argument("--reload-on-update", help="Reload scene automatically when source is updated", action="store_true", default=SUPPRESS)
62
+ parser.add_argument("--agxhelp", help="Show AGX specific help", action=AgxHelpAction, nargs=0, default=SUPPRESS)
63
+ parser.add_argument("--version", help="Show version", action=VersionAction, nargs=0, default=SUPPRESS)
64
+ return parser
65
+
66
+ @staticmethod
67
+ def prepare_scene(openplxfile = None):
68
+ args, extra_args = OpenPlxApplication.setup_args_parser(openplxfile).parse_known_args()
69
+ set_log_level(args.loglevel)
70
+ if extra_args:
71
+ print(f"Passing these args to AGX: {(' ').join(extra_args)}")
72
+
73
+ opt_params = OptParams()
74
+ if args.modelname is not None:
75
+ opt_params = opt_params.with_model_name(args.modelname)
76
+
77
+ result = load_from_file(simulation(), args.openplxfile if openplxfile is None else openplxfile, args.bundle_path, opt_params)
78
+
79
+ assembly = result.assembly()
80
+ openplx_scene = result.scene()
81
+
82
+ # Add signal listeners so that signals are picked up from inputs
83
+ input_queue = InputSignalQueue.create()
84
+ output_queue = OutputSignalQueue.create()
85
+ input_signal_listener = InputSignalListener(assembly, input_queue)
86
+ output_signal_listener = OutputSignalListener(assembly, openplx_scene, output_queue)
87
+
88
+ simulation().add(input_signal_listener, InputSignalListener.RECOMMENDED_PRIO)
89
+ simulation().add(output_signal_listener, OutputSignalListener.RECOMMENDED_PRIO)
90
+
91
+ # Add click listeners unless this is scene-reload, in that case we want to keep our listeners
92
+ # Note that we use globals() since this whole file is reloaded on scene-reload by AGX, so no local globals are kept
93
+ if "click_adapter" not in globals():
94
+ globals()["click_adapter"] = OsgClickAdapter()
95
+ application().addListener(AllowCtrlBreakListener())
96
+
97
+ if "reload_on_update" in args:
98
+ print(f"Will reload scene when {args.openplxfile} is updated")
99
+ add_file_changed_listener(application(), args.openplxfile)
100
+
101
+ if "enable_click" in args:
102
+ click_adapter = globals()["click_adapter"]
103
+ click_adapter.add_listeners(application(), simulation(), args.click_addr, openplx_scene,
104
+ input_queue, output_queue, output_signal_listener)
105
+
106
+ if not addVisuals(result, root(), args.debug_render_frames):
107
+ application().setEnableDebugRenderer(True)
108
+ simulation().add(assembly.get())
109
+ addDeformableVisualUpdaters(result, root())
110
+ return openplx_scene, input_queue, output_queue
111
+
112
+ @staticmethod
113
+ def ctrl_break_handler(_signum, _frame):
114
+ # Unfortunately os._exit(0) doesn't cut it on Windows, so we're doing the kill to make sure we exit on Windows as well.
115
+ if os.name == "nt":
116
+ os.kill(os.getpid(), 9)
117
+ else:
118
+ application().stop()
119
+
120
+ @staticmethod
121
+ def on_shutdown(_):
122
+ if os.name == "nt":
123
+ os.kill(os.getpid(), 9)
124
+ else:
125
+ os._exit(0)
126
+
127
+ def start_agx(self):
128
+ # Tell AGX where build_scene is located
129
+ sys.argv[0] = self.build_scene_file
130
+ # Use __main__ otherwise AGX will just skip the init
131
+ # pylint: disable=unused-variable
132
+ init = init_app(name="__main__", scenes=[(self.build_scene, "1")], autoStepping=True, onShutdown=self.on_shutdown)
133
+ # pylint: enable=unused-variable
134
+
135
+ def run(self):
136
+ signal.signal(signal.SIGINT, self.ctrl_break_handler)
137
+ self.setup_args_parser("").parse_known_args()
138
+ self.start_agx()
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Command line utility that helps serialize OpenPLX models to json
4
+ """
5
+ from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, SUPPRESS
6
+ import agx
7
+ from openplxbundles import bundle_path
8
+ from openplx import serialize_file, __version__, set_log_level
9
+ from openplx.versionaction import VersionAction
10
+
11
+
12
+ def parse_args():
13
+ parser = ArgumentParser(description="Serialize OpenPLX models", formatter_class=ArgumentDefaultsHelpFormatter)
14
+ parser.add_argument("openplxfile", help="the .openplx file to serialize")
15
+ parser.add_argument("--bundle-path", help="list of path to bundle dependencies if any. Overrides environment variable OPENPLX_BUNDLE_PATH.",
16
+ metavar="<bundle_path>", default=bundle_path())
17
+ parser.add_argument("--loglevel", choices=["trace", "debug", "info", "warn", "error", "critical", "off"], help="Set log level", default="warn")
18
+ parser.add_argument("--modelname", help="The model to serialize (defaults to last model in file)", metavar="<name>", default="")
19
+ parser.add_argument("--version", help="Show version", action=VersionAction, nargs=0, default=SUPPRESS)
20
+ return parser.parse_args()
21
+
22
+
23
+ def run():
24
+ args = parse_args()
25
+ set_log_level(args.loglevel)
26
+
27
+ # Must initialize agx for plugin to work
28
+ _ = agx.init()
29
+
30
+ result = serialize_file(args.openplxfile, args.bundle_path, args.modelname)
31
+ print(result)
32
+
33
+
34
+ if __name__ == '__main__':
35
+ run()
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Command line utility that validates OpenPLX files and prints the result to stdout.
4
+ """
5
+ import os
6
+ import signal
7
+ import sys
8
+ from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, SUPPRESS
9
+ import agxOSG
10
+ import agxSDK
11
+ import agx
12
+ from openplxbundles import bundle_path
13
+ from openplx import load_from_file, OptParams, __version__, set_log_level
14
+ from openplx.versionaction import VersionAction
15
+
16
+ def parse_args():
17
+ parser = ArgumentParser(description="View OpenPLX models", formatter_class=ArgumentDefaultsHelpFormatter)
18
+ parser.add_argument("openplxfile", help="the .openplx file to load")
19
+ parser.add_argument("--bundle-path", help="list of path to bundle dependencies if any. Overrides environment variable OPENPLX_BUNDLE_PATH.",
20
+ metavar="<bundle_path>", default=bundle_path())
21
+ parser.add_argument("--debug-render-frames", action='store_true', help="enable rendering of frames for mate connectors and rigid bodies.")
22
+ parser.add_argument("--loglevel", choices=["trace", "debug", "info", "warn", "error", "critical", "off"], help="Set log level", default="warn")
23
+ parser.add_argument("--modelname", help="The model to load (defaults to last model in file)", metavar="<name>", default=None)
24
+ parser.add_argument("--version", help="Show version", action=VersionAction, nargs=0, default=SUPPRESS)
25
+ return parser.parse_args()
26
+
27
+ class AllowCtrlBreakListener(agxOSG.ExampleApplicationListener): # pylint: disable=too-few-public-methods
28
+ pass
29
+
30
+ def validate():
31
+
32
+ args = parse_args()
33
+ set_log_level(args.loglevel)
34
+
35
+ _ = agx.init()
36
+ simulation = agxSDK.Simulation()
37
+
38
+ opt_params = OptParams()
39
+ if args.modelname is not None:
40
+ opt_params = opt_params.with_model_name(args.modelname)
41
+
42
+ result = load_from_file(simulation, args.openplxfile, args.bundle_path, opt_params)
43
+
44
+ if len(result.errors()) == 0:
45
+ sys.exit(0)
46
+ else:
47
+ sys.exit(255)
48
+
49
+ def handler(_signum, _frame):
50
+ os._exit(0)
51
+
52
+ def run():
53
+ signal.signal(signal.SIGINT, handler)
54
+ validate()
55
+
56
+ if __name__ == '__main__':
57
+ run()
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Command line utility that loads OpenPLX files and loads them into an AGX Simulation
4
+ """
5
+ from openplx.openplx_application import OpenPlxApplication
6
+
7
+ def openplx_view_build_scene():
8
+ OpenPlxApplication.prepare_scene()
9
+
10
+ def run():
11
+ OpenPlxApplication(openplx_view_build_scene).run()
12
+
13
+ if __name__ == "__main__":
14
+ run()
@@ -0,0 +1,11 @@
1
+ """
2
+ A module for helping out with argparse version printing
3
+ """
4
+ from argparse import Action
5
+ import sys
6
+ from openplx import __version__
7
+
8
+ class VersionAction(Action):
9
+ def __call__(self, parser, namespace, values, option_string=None):
10
+ print(__version__)
11
+ sys.exit(0)