|
5 | 5 |
|
6 | 6 | import dronecan |
7 | 7 | import math |
| 8 | +import os |
8 | 9 | import threading |
9 | 10 | import time |
10 | 11 |
|
|
15 | 16 | GZ_VERSION_HARMONIC = "harmonic" |
16 | 17 | GZ_VERSION_IONIC = "ionic" |
17 | 18 |
|
18 | | -GZ_VERSION = GZ_VERSION_HARMONIC |
19 | 19 |
|
20 | | -if GZ_VERSION == GZ_VERSION_GARDEN: |
| 20 | +def gz_version(): |
| 21 | + """Return the environment variable GZ_VERSION if set, else default to 'harmonic'""" |
| 22 | + return os.environ.get("GZ_VERSION", GZ_VERSION_HARMONIC) |
| 23 | + |
| 24 | + |
| 25 | +if gz_version() == GZ_VERSION_GARDEN: |
21 | 26 | from gz.msgs9.model_pb2 import Model |
22 | | -elif GZ_VERSION == GZ_VERSION_HARMONIC: |
| 27 | +elif gz_version() == GZ_VERSION_HARMONIC: |
23 | 28 | from gz.msgs10.model_pb2 import Model |
24 | | -elif GZ_VERSION == GZ_VERSION_IONIC: |
| 29 | +elif gz_version() == GZ_VERSION_IONIC: |
25 | 30 | from gz.msgs11.model_pb2 import Model |
26 | 31 |
|
27 | 32 |
|
28 | 33 | # Importing gz.transport into the module global scope causes an odd |
29 | 34 | # multiprocessing conflict with dronecan. This is a workaround. |
30 | 35 | def gz_node(): |
31 | | - if GZ_VERSION == GZ_VERSION_GARDEN: |
| 36 | + if gz_version() == GZ_VERSION_GARDEN: |
32 | 37 | from gz.transport12 import Node |
33 | | - elif GZ_VERSION == GZ_VERSION_HARMONIC: |
| 38 | + elif gz_version() == GZ_VERSION_HARMONIC: |
34 | 39 | from gz.transport13 import Node |
35 | | - elif GZ_VERSION == GZ_VERSION_IONIC: |
| 40 | + elif gz_version() == GZ_VERSION_IONIC: |
36 | 41 | from gz.transport14 import Node |
37 | 42 |
|
38 | 43 | return Node() |
|
0 commit comments