Skip to main content

关于Pubsub

  • pubsub的最初目的是通过redis服务转发单目摄像头数据,供深度学习和ROS两方同时订阅
  • 实际使用过程中增加了转发FairMOT识别结果的用途,同时pubsub在主-从两台机器上进行部署
  • 在0.1.4版本中,增加了对主-从和多话题的支持,修改了配置文件的配置方式
  • 在0.1.5版本中,完善了setup.py,并发布到pypi
  • 在0.1.6版本中,增加了configs模块,可通过此模块直接获得配置信息

1. 遗留问题

1.1. redis.exceptions.ConnectionError: Connection closed by server.

https://github.com/andymccurdy/redis-py/issues/1140

使用try... except redis.exceptions.ConnectionError:的方法规避了此问题

FYI
- 在本项目下,使用`py37`没有出现此问题
- 在本项目下,使用`python`没有出现此问题
- 在`FairMOT`下出现此问题,初步怀疑是`timeout`问题

该问题通过安装hiredis的方式进行了修复,修复版本0.1.5,暂未出现此问题

2. 依赖

本工具依赖redis服务请先安装redis-server

apt install redis-server

为Python安装依赖

pip3.7 install opencv-python numpy pyyaml hiredis redis
pip2.7 install opencv-python numpy pyyaml hiredis redis
  • 补充说明

setup.py 文件本身指明了相关依赖,但是由于公司网络原因,可能会出现无法正常下载安装的情况,建议在安装之前手动完成依赖包的安装。

3. 作为程序部署

step1. 在~路径下新建路径robot\configs,注意:请勿使用其他路径

step2. 将项目目录下的配置文件config\pubsub.yaml拷贝到~\robot\configs路径下,注意:请勿修改文件名称

step3. 按实际情况修改~\robot\configs\pubsub.yaml文件

# camera data pub & sub config
mono:
  type: "pub"
  source: "0"
  host: "172.172.0.10"
  port: "6379"
  db: 3
  name: "robot_mono"
  topic: "robot_mono"

# bbox from FairMOT pub & sub config
track:
  type: "pub"
  source: "0"
  host: "172.172.0.11"
  port: "6379"
  db: 3
  name: "robot_track"
  topic: "robot_track"

参数说明:

mono: 指定为单目相机,该名称请勿修改
  type: 发布消息,请勿修改
  source: camera device id, 通过 ls /dev/video* 配合 v4l2-ctl -d  /dev/video0 --all查看
  host: 消息发布ip,对应部署了pubsub程序的服务器的IP地址
  port: 消息发布端口,对应部署了pubsub程序的服务器的Redis服务的端口
  db: 不需改动
  name: 消息发布服务的名称
  topic: 消息发布话题的名称

track: 指定为跟踪算法,该名称请勿修改
  type: 发布消息,请勿修改
  source: 请勿修改
  host: 消息发布ip,对应部署了tracking算法的服务器的IP地址
  port: 消息发布端口,对应部署了tracking算法的服务器的Redis服务的端口
  db: 不需改动
  name: 消息发布服务的名称
  topic: 消息发布话题的名称

step5. 在~/.bashrc中声明configs地址

  • 执行下面的命令,将configs的路径加入到系统环境
echo export ROBOT_CONFIGS=$(dirname ~/.)'/robot/configs' >> ~/.bashrc && source ~/.bashrc
  • 请务必注意将配置文件放在上述指定文件夹下

setp6. 如果存在主-从部署,请在从机上重复上述过程

请注意:

  • 模块和程序使用同样的配置文件!!!

3.1. 开机自启动[未测试]

在/etc/rc.local脚本中增加了开机自启动代码,代码如下

export PUBLISHERPATH=$(dirname ~/.)'/robot/pubsub'
source $(dirname $(which conda))/activate pubsub
cd $PUBLISHERPATH
python app.py

第一段申明了MONOPUB的路径

第二段进入到该路径

第三段在后台启动脚本publish.sh 并输出日志到pub.log

第三段回到home

可使用ps -ef | grep python查看

4. 作为模块使用

分别在python2.7和python3.7版本下进行测试。

4.1. 安装

pip install aa-pubsub

4.2. 配置

  • 如果主-从部署在同一IP下,可以不必另外配置
  • 如果主-从部署在不同IP下,从机需要依照主机的配置方法自行配置

请注意:

  • 模块和程序使用同样的配置文件!!!

5. 性能

目前Publisher端读取摄像头数据到Subscriber端得到数据拥有约100ms的延时,其中有20秒是docker造成的延时。

1 2

6. 开发/贡献代码

6.1. 测试用例

测试用例的统一运行入口是test.py文件

python test.py
  • 各测试用例请统一在testcases路径下实现,以test_{name}.py的形式命名
  • py文件中,测试类以{name}Test的形式命名
  • 更多请参考unittest

6.2. 提交pip

  • 安装提交需要的工具
pip install twine
  • 更新version.py的版本号
  • 提交
python setup.py sdist
twine upload dist/*

Metadata

Release files for aa-camera 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aa-camera 0.1.6
File Size Uploaded Provenance Actions
aa-camera-0.1.6.tar.gz 8.3 kB Without provenance Details for aa-camera-0.1.6.tar.gz

Release files / aa-camera-0.1.6.tar.gz

Download URL aa-camera-0.1.6.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
02b85515de3ecdb7d213592306e678751a8044fd32fefe50894842b5493b4850
BLAKE2b-256 checksum
How to use checksums
9b06102625ac18092b68dcebf8413e75a0c64906b1de5d8530fff69d3b2efc7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

Security for aa-camera 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.6 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page