USB/VIDEO 设备端口绑定,以PX4mini为例

USB 设备端口绑定

1. ttyUSB* or /ttyACM*

方法一:

给固定USB设备一个别名 前提是/ttyUSB*才能设置

若为/ttyACM* 则采用方法二

1.查看usb设备信息

lsusb
会得到如下类似的信息:
Bus 002 Device 003: ID 2109:0715 VIA Labs, Inc. 
Bus 002 Device 002: ID 2109:0817 VIA Labs, Inc. 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 048d:c100 Integrated Technology Express, Inc. 
Bus 001 Device 003: ID 04ca:7070 Lite-On Technology Corp. 
Bus 001 Device 006: ID 8087:0aaa Intel Corp. 
Bus 001 Device 007: ID 0c45:a512 Microdia 
Bus 001 Device 005: ID 1532:0083 Razer USA, Ltd 
Bus 001 Device 024: ID 26ac:0032  
Bus 001 Device 002: ID 2109:2817 VIA Labs, Inc. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 024: ID 26ac:0032  #这个设备是我们的PX4

2.创建/打开文件

sudo vim /etc/udev/rules.d/myusb.rules

输入以下文本:

KERNEL=="ttyUSB*"
ATTRS{idVendor}=="26ac",
ATTRS{idProduct}=="0032",
SYMLINK+="myusb"

4.重新启动服务器即可

udevadm control --reload-rules && udevadm trigger

5.可以通过/dev/myusb查看设备

方法二:

1.查看usb设备信息

dmesg | grep tty 或者使用 ls /dev/tty*

2.查看ttyACM0设备的具体信息

udevadm info --name=/dev/ttyACM0 --attribute-walk
会得到如下类似信息:
looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.2/1-1.2:1.0/tty/ttyACM0':
    KERNEL=="ttyACM0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.2/1-1.2:1.0':
    KERNELS=="1-1.2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="cdc_acm"
    ATTRS{authorized}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceClass}=="02"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bInterfaceProtocol}=="01"
    ATTRS{bInterfaceSubClass}=="02"
    ATTRS{bNumEndpoints}=="01"
    ATTRS{bmCapabilities}=="6"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00,以PX4mini为例/0000:00:14.0/usb1/1-1/1-1.2':
    KERNELS=="1-1.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="02"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bDeviceSubClass}=="00"信息,以PX4mini为例
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 2"
    ATTRS{bcdDevice}=="0101"
    ATTRS{bmAttributes}=="80"
    ATTRS{busnum}=="1"
    ATTRS{configuration}=="Bulk"
    ATTRS{devnum}=="22"
    ATTRS{devpath}=="1.2"
    ATTRS{idProduct}=="0032"
    ATTRS{idVendor}=="26ac"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="3D Robotics"
    ATTRS{maxchild}=="0"
    ATTRS{product}=="PX4 FMU v5.x"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{rx_lanes}=="1"
    ATTRS{serial}=="0"
    ATTRS{speed}=="12"信息
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="8324"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="02"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"信息
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0214"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="1"
    ATTRS{configuration}==""
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="1"
    ATTRS{idProduct}=="2817"
    ATTRS{idVendor}=="2109"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="VIA Labs, Inc.         "
    ATTRS{maxchild}=="4"
    ATTRS{product}=="USB2.0 Hub             "
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="removable"
    ATTRS{rx_lanes}=="1"
    ATTRS{speed}=="480"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="1197"
    ATTRS{version}==" 2.10"
信息
  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0504"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="1"
    ATTRS{configuration}==""
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{idProduct}=="0002"重新启动服务器后,我们的 USB 加密狗除了它的随机 /dev/ttyACM 地址之外,现在也总是可以在 /dev/ttyUSB50 中找到。如果不想重新启动服务器,可以通过输入以下命令启用新别名:
    ATTRS{idVendor}=="1d6b"信息
    ATTRS{interface_authorized_default}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 5.4.0-72-generic xhci-hcd"
    ATTRS{maxchild}==信息"16"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{rx_lanes}=="1"
    ATTRS{serial}=="0000:00:14.0"
    ATTRS{speed}=="480"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="164"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{ari_enabled}=="0"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0330"
    ATTRS{consistent_dma_mask_bits}=="64"信息
    ATTRS{d3cold_allowed}=="1"
    ATTRS{dbc}=="disabled"
    ATTRS{device}=="0xa36d"
    ATTRS{dma_mask_bits}=="64"
    ATTRS{driver_override}=="(null)"
    ATTRS{enable}=="1"
    ATTRS{irq}=="124"
    ATTRS{local_cpulist}=="0-11"
    ATTRS{local_cpus}=="fff"
    ATTRS{msi_bus}=="1"
    ATTRS{numa_node}=="-1"信息
    ATTRS{revision}=="0x10"
    ATTRS{subsystem_device}=="0x3806"
    ATTRS{subsystem_vendor}=="0x17aa"
    ATTRS{vendor}=="0x8086"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    

上面的输出是一个“USB 树,从最低层开始,向内进入服务器中的 USB 主机。只需要关注USB设备即可(此处为PX4)

3.创建/打开文件

sudo vim /etc/udev/rules.d/myusb.rules

输入以下文本(使用PX4为示例):

ACTION=="add",
ATTRS{product}=="PX4 FMU v5.x",
ATTRS{idVendor}=="26ac",
ATTRS{idProduct}=="0032",
SYMLINK+="ttyPX4"

4.重新启动服务器后,我们的PX4除了它的随机 /dev/ttyACM 地址之外,现在也总是可以在 /dev/ttyPX4 中找到。如果不想重新启动服务器,可以通过输入以下命令启用新别名:

udevadm control --reload-rules && udevadm trigger

之后插拔即可

2. 完成方法一或者方法二之后,需要修改px4.launch

sudo gedit /opt/ros/melodic/share/mavros/launch/px4.launch 

得到以下内容

<launch>
	<!-- vim: set ft=xml noet : -->
	<!-- example launch script for PX4 based FCU's -->

	<arg name="fcu_url" default="/dev/ttyACM0:57600" />
	<arg name="gcs_url" default="" />
	<arg name="tgt_system" default="1" />
	<arg name="tgt_component" default="1" />
	<arg name="log_output" default="screen" />
	<arg name="fcu_protocol" default="v2.0" />
	<arg name="respawn_mavros" default="false" />

	<include file="$(find mavros)/launch/node.launch">
		<arg name="pluginlists_yaml" value="$(find mavros)/launch/px4_pluginlists.yaml" />
		<arg name="config_yaml" value="$(find mavros)/launch/px4_config.yaml" />

		<arg name="fcu_url" value="$(arg fcu_url)" />
		<arg name="gcs_url" value="$(arg gcs_url)" />
		<arg name="tgt_system" value="$(arg tgt_system)" />
		<arg name="tgt_component" value="$(arg tgt_component)" />
		<arg name="log_output" value="$(arg log_output)" />
		<arg name="fcu_protocol" value="$(arg fcu_protocol)" />
		<arg name="respawn_mavros" default="$(arg respawn_mavros)" />
	</include>
</launch>

修改这句

<arg name="fcu_url" default="/dev/ttyACM0:57600" />

但是修改之后发现px4.launch似乎只能使用原始的ttyACM0

暂时的解决办法是:若是发生串口冲突,则需要绑定另一个设备的USB端口,而非PX4

后续再更

上一篇:[ToneTuneToolkit][001]获取指定目录下所有某类型文件的名称


下一篇:com.mysql.cj.jdbc.exceptions.CommunicationsException