agx-openplx 0.15.0__cp38-cp38-manylinux_2_31_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- agx_openplx-0.15.0.dist-info/METADATA +232 -0
- agx_openplx-0.15.0.dist-info/RECORD +41 -0
- agx_openplx-0.15.0.dist-info/WHEEL +4 -0
- agx_openplx-0.15.0.dist-info/entry_points.txt +8 -0
- openplx/Core.py +7781 -0
- openplx/DriveTrain.py +8574 -0
- openplx/Math.py +5372 -0
- openplx/Physics.py +36195 -0
- openplx/Physics1D.py +6732 -0
- openplx/Physics3D.py +42524 -0
- openplx/Robotics.py +15762 -0
- openplx/Simulation.py +1056 -0
- openplx/Terrain.py +3891 -0
- openplx/Urdf.py +654 -0
- openplx/Vehicles.py +8793 -0
- openplx/Visuals.py +3901 -0
- openplx/_AgxOpenPlxPyApi.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_CorePythonSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_DriveTrainSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_MathSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_Physics1DSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_Physics3DSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_PhysicsSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_RoboticsSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_SimulationSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_TerrainSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_UrdfSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_VehiclesSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/_VisualsSwig.cpython-38-x86_64-linux-gnu.so +0 -0
- openplx/__init__.py +51 -0
- openplx/agxtoopenplx.py +55 -0
- openplx/anytoopenplx.py +44 -0
- openplx/api.py +1337 -0
- openplx/migrate.py +136 -0
- openplx/migration_hint.py +14 -0
- openplx/migrations.py +521 -0
- openplx/openplx_application.py +133 -0
- openplx/openplx_serialize.py +35 -0
- openplx/openplx_validate.py +57 -0
- openplx/openplx_view.py +14 -0
- openplx/versionaction.py +11 -0
@@ -0,0 +1,133 @@
|
|
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 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
|
+
OpenPlxApplication(dummy_build_scene).start_agx()
|
25
|
+
sys.exit(0)
|
26
|
+
|
27
|
+
class AllowCtrlBreakListener(agxOSG.ExampleApplicationListener): # pylint: disable=too-few-public-methods
|
28
|
+
pass
|
29
|
+
|
30
|
+
class OpenPlxApplication:
|
31
|
+
|
32
|
+
def __init__(self, build_scene, build_scene_file=None):
|
33
|
+
"""
|
34
|
+
AGX needs to know the build scene function and which file
|
35
|
+
If build_scene_file is None then it is inferred from the build_scene function.
|
36
|
+
"""
|
37
|
+
self.build_scene = build_scene
|
38
|
+
self.build_scene_file = sys.modules[self.build_scene.__module__].__file__ if build_scene_file is None else build_scene_file
|
39
|
+
|
40
|
+
@staticmethod
|
41
|
+
def parse_args(openplxfile = None):
|
42
|
+
parser = ArgumentParser(description="View OpenPLX models", formatter_class=ArgumentDefaultsHelpFormatter)
|
43
|
+
if openplxfile is None:
|
44
|
+
parser.add_argument("openplxfile", help="the .openplx file to load")
|
45
|
+
parser.add_argument("[AGX flags ...]", help="any additional AGX flags", default="", nargs="?")
|
46
|
+
parser.add_argument(
|
47
|
+
"--bundle-path",
|
48
|
+
help="list of path to bundle dependencies if any. Overrides environment variable OPENPLX_BUNDLE_PATH.",
|
49
|
+
metavar="<bundle_path>",
|
50
|
+
default=bundle_path(),
|
51
|
+
)
|
52
|
+
parser.add_argument("--click-addr", type=str, help="Address for Click to listen on, e.g. ipc:///tmp/click.ipc", default="tcp://*:5555")
|
53
|
+
parser.add_argument("--debug-render-frames", action="store_true", help="enable rendering of frames for mate connectors and rigid bodies.")
|
54
|
+
parser.add_argument("--enable-click", help="Enable sending and receiving signals as Click Messages", action="store_true", default=SUPPRESS)
|
55
|
+
parser.add_argument("--loglevel",
|
56
|
+
choices=["trace", "debug", "info", "warn", "error", "critical", "off"],
|
57
|
+
help="Set log level",
|
58
|
+
default="info")
|
59
|
+
parser.add_argument("--modelname", help="The model to load (defaults to last model in file)", metavar="<name>", default=None)
|
60
|
+
parser.add_argument("--reload-on-update", help="Reload scene automatically when source is updated", action="store_true", default=SUPPRESS)
|
61
|
+
parser.add_argument("--usage", help="Show AGX specific help", action=AgxHelpAction, nargs=0, default=SUPPRESS)
|
62
|
+
parser.add_argument("--version", help="Show version", action=VersionAction, nargs=0, default=SUPPRESS)
|
63
|
+
return parser.parse_known_args()
|
64
|
+
|
65
|
+
@staticmethod
|
66
|
+
def prepareScene(openplxfile = None): # pylint: disable=invalid-name
|
67
|
+
args, extra_args = OpenPlxApplication.parse_args(openplxfile)
|
68
|
+
set_log_level(args.loglevel)
|
69
|
+
if extra_args:
|
70
|
+
print(f"Passing these args to AGX: {(' ').join(extra_args)}")
|
71
|
+
|
72
|
+
opt_params = OptParams()
|
73
|
+
if args.modelname is not None:
|
74
|
+
opt_params.with_model_name(args.modelname)
|
75
|
+
|
76
|
+
result = load_from_file(simulation(), args.openplxfile if openplxfile is None else openplxfile, args.bundle_path, opt_params)
|
77
|
+
|
78
|
+
assembly = result.assembly()
|
79
|
+
openplx_scene = result.scene()
|
80
|
+
|
81
|
+
# Add signal listeners so that signals are picked up from inputs
|
82
|
+
input_signal_listener = InputSignalListener(assembly)
|
83
|
+
output_signal_listener = OutputSignalListener(assembly, openplx_scene)
|
84
|
+
|
85
|
+
simulation().add(input_signal_listener, InputSignalListener.RECOMMENDED_PRIO)
|
86
|
+
simulation().add(output_signal_listener, OutputSignalListener.RECOMMENDED_PRIO)
|
87
|
+
|
88
|
+
# Add click listeners unless this is scene-reload, in that case we want to keep our listeners
|
89
|
+
# Note that we use globals() since this whole file is reloaded on scene-reload by AGX, so no local globals are kept
|
90
|
+
if "click_adapter" not in globals():
|
91
|
+
globals()["click_adapter"] = OsgClickAdapter()
|
92
|
+
application().addListener(AllowCtrlBreakListener())
|
93
|
+
|
94
|
+
if "reload_on_update" in args:
|
95
|
+
print(f"Will reload scene when {args.openplxfile} is updated")
|
96
|
+
add_file_changed_listener(application(), args.openplxfile)
|
97
|
+
|
98
|
+
if "enable_click" in args:
|
99
|
+
click_adapter = globals()["click_adapter"]
|
100
|
+
click_adapter.add_listeners(application(), simulation(), args.click_addr, openplx_scene, output_signal_listener)
|
101
|
+
|
102
|
+
if not addVisuals(result, root(), args.debug_render_frames):
|
103
|
+
application().setEnableDebugRenderer(True)
|
104
|
+
simulation().add(assembly.get())
|
105
|
+
addDeformableVisualUpdaters(result, root())
|
106
|
+
return openplx_scene
|
107
|
+
|
108
|
+
@staticmethod
|
109
|
+
def ctrl_break_handler(_signum, _frame):
|
110
|
+
# 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.
|
111
|
+
if os.name == "nt":
|
112
|
+
os.kill(os.getpid(), 9)
|
113
|
+
else:
|
114
|
+
application().stop()
|
115
|
+
|
116
|
+
@staticmethod
|
117
|
+
def on_shutdown(_):
|
118
|
+
if os.name == "nt":
|
119
|
+
os.kill(os.getpid(), 9)
|
120
|
+
else:
|
121
|
+
os._exit(0)
|
122
|
+
|
123
|
+
def start_agx(self):
|
124
|
+
# Tell AGX where build_scene is located
|
125
|
+
sys.argv[0] = self.build_scene_file
|
126
|
+
# pylint: disable=W0612 # Unused variable 'init'
|
127
|
+
# Use __main__ otherwise AGX will just skip the init
|
128
|
+
init = init_app(name="__main__", scenes=[(self.build_scene, "1")], autoStepping=True, onShutdown=self.on_shutdown) # Default: False
|
129
|
+
|
130
|
+
def run(self):
|
131
|
+
signal.signal(signal.SIGINT, self.ctrl_break_handler)
|
132
|
+
self.parse_args("")
|
133
|
+
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="")
|
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):
|
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.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()
|
openplx/openplx_view.py
ADDED
@@ -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.prepareScene()
|
9
|
+
|
10
|
+
def run():
|
11
|
+
OpenPlxApplication(openplx_view_build_scene).run()
|
12
|
+
|
13
|
+
if __name__ == "__main__":
|
14
|
+
run()
|
openplx/versionaction.py
ADDED
@@ -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)
|