From 81e3fcb9dbe31cd787a7bb0d77dcce9782bd1286 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Wed, 27 May 2020 18:18:14 +0930 Subject: [PATCH] Clean up lidar device setting to only use one environment variable --- car/src/car/tracking/devices/factory.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/car/src/car/tracking/devices/factory.py b/car/src/car/tracking/devices/factory.py index fd17874..527a6b5 100644 --- a/car/src/car/tracking/devices/factory.py +++ b/car/src/car/tracking/devices/factory.py @@ -3,10 +3,9 @@ from .. import lidar_loader as loader import os MOCK_DEVICE = "LIDAR_MOCK" -RPLIDAR = "LIDAR_RPLIDAR" -def get_lidar(device=None, connection='/dev/ttyUSB0'): +def get_lidar(device=None): actual_device = None try: actual_device = device if device is not None else os.environ["CAR_LIDAR"] @@ -15,16 +14,13 @@ def get_lidar(device=None, connection='/dev/ttyUSB0'): 'No lidar device specified and the CAR_LIDAR environment variable is not set.') if actual_device == MOCK_DEVICE: return MockLidar(loader.load_scans_bytes_file("car/src/car/tracking/out.pickle")) - elif actual_device == RPLIDAR: + elif actual_device != '': try: - # TODO: Cleanup connection setting, probably don't need to pass it into the method. from rplidar import RPLidar - if "LIDAR_DEVICE" in os.environ: - return RPLidar(os.environ['LIDAR_DEVICE']) - return RPLidar(connection) + return RPLidar(device) except ImportError: print('Could not import RPLidar. Have you downloaded rplidar?') else: - print('No valid lidar device found. Please choose one of ' + - MOCK_DEVICE + ' or ' + RPLIDAR) + print('No valid lidar device found. Please choose ' + + MOCK_DEVICE + ' or a dn address for the lidar device.') return None