Skip to content

Commit fdc3158

Browse files
committed
DroneCAN: automatically handle Gazebo version
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
1 parent 71ad16d commit fdc3158

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

scripts/dronecan_sensor.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import dronecan
77
import math
8+
import os
89
import threading
910
import time
1011

@@ -15,24 +16,28 @@
1516
GZ_VERSION_HARMONIC = "harmonic"
1617
GZ_VERSION_IONIC = "ionic"
1718

18-
GZ_VERSION = GZ_VERSION_HARMONIC
1919

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:
2126
from gz.msgs9.model_pb2 import Model
22-
elif GZ_VERSION == GZ_VERSION_HARMONIC:
27+
elif gz_version() == GZ_VERSION_HARMONIC:
2328
from gz.msgs10.model_pb2 import Model
24-
elif GZ_VERSION == GZ_VERSION_IONIC:
29+
elif gz_version() == GZ_VERSION_IONIC:
2530
from gz.msgs11.model_pb2 import Model
2631

2732

2833
# Importing gz.transport into the module global scope causes an odd
2934
# multiprocessing conflict with dronecan. This is a workaround.
3035
def gz_node():
31-
if GZ_VERSION == GZ_VERSION_GARDEN:
36+
if gz_version() == GZ_VERSION_GARDEN:
3237
from gz.transport12 import Node
33-
elif GZ_VERSION == GZ_VERSION_HARMONIC:
38+
elif gz_version() == GZ_VERSION_HARMONIC:
3439
from gz.transport13 import Node
35-
elif GZ_VERSION == GZ_VERSION_IONIC:
40+
elif gz_version() == GZ_VERSION_IONIC:
3641
from gz.transport14 import Node
3742

3843
return Node()

0 commit comments

Comments
 (0)