ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Automatic identification and operation of rplidar port

asked 2021-09-07 03:50:44 -0500

apprentice_user gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-09-08 11:02:55 -0500

Pratik Somaiya gravatar image

Hi, I am not really sure about the actual warning/ error you're getting, could you post the error message?

Also, you can use udev rules as described in robopeak github wiki or rplidar ros wiki to automatically detect the device. In my opinion, that would be more straightforward. In case, if you are not familiar with udev rules, you can check these guides by clearpath robotics or robotics knowledge base.

edit flag offensive delete link more

Comments

I set the udev rules. but my main problem is that the port is constantly changing. I can't assign a static port. for this, I am trying to recognize the port with python and open it that way.

"Error, cannot bind to the specified serial port /dev/ttyUSB0." This is exactly the error I get. It is now plugged into USB1. but it prevents lidar from working because USB0 is in the settings file.

apprentice_user gravatar image apprentice_user  ( 2021-09-09 06:11:22 -0500 )edit
1

I set the udev rules. but my main problem is that the port is constantly changing

if that's the case, your udev rule is incorrect.

If you've set a correct udev rule, you'd get the same device file each time you plug in.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-09 06:22:06 -0500 )edit

thank you both of you. i guess need to focus on that

apprentice_user gravatar image apprentice_user  ( 2021-09-09 06:41:58 -0500 )edit
1

No worries. In case your problem hasn't been resolved and If the device is plugged into USB1 right now, you can run the command udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB1) and you will see a list of all device attributes (more info clearpath robotics). Compare it with your udev rule from robopeak github which is as per below:

KERNEL=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0777", SYMLINK+="rplidar"

Hope this helps.

Pratik Somaiya gravatar image Pratik Somaiya  ( 2021-09-09 07:27:49 -0500 )edit

thank you this solved my problem

apprentice_user gravatar image apprentice_user  ( 2021-09-13 01:39:51 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-09-07 03:50:44 -0500

Seen: 577 times

Last updated: Sep 08 '21