Automatic identification and operation of rplidar port
I am using jetson nano to develop my project and all usb ports are full. in one of them rplidar is defined (/dev/ttyUSB0). I want to use lidar as payload in the project. I want it to be removable when not mapping. When I do this, the port that the lidar is plugged into may change. E.g; It can switch to ttyUSB1. I wrote a function to check this. The functions and their outputs are as follows.
self.command_port = "ls /dev | grep USB"
def check_port(self):
self.stream = os.popen(self.command_port)
self.output = self.stream.readlines()[0][0:7]
return self.output
def check_lidar(self):
print("CHECKİNG LİDAR PORT...")
self.param = self.check_port()
self.command_lidar = "roslaunch rplidar_ros view_rplidar.launch" + " value:=/dev/" + self.param
print(self.command_lidar)
stream = os.popen(self.command_lidar)
where the output variable produces the following as a string = "ttyUSB" . i.e. lidar generates whatever port it receives. (0,1,2,3...) The lidar_command variable then produces the following string. = "roslaunch rplidar_ros view_rplidar.launch value:=/dev/ttyUSB"
What I'm trying to do is this. Instead of manually entering the port where the lidar is plugged in, it will automatically detect and work. but when I send this command to the terminal, I see a warning saying that the lidar must be plugged in usb0. I hope it was self explanatory and I would greatly appreciate any help.