视觉编程策略

使用计算机视觉是使您的机器人对现场的元素做出反应并使其更加自动化的一种好方法。通常在FRC | reg |比赛中,可以通过自动将球或其他比赛物件射入目标,或导航到场地上获得奖励分数。计算机视觉是解决其中许多问题的好方法。而且,如果您拥有可以实现这一操作的自动代码,那么它也可以在遥控操作期间使用,以帮助驾驶员。

视觉处理系统的的组件以及视觉程序应该运行的位置有多种选项。WPILib和相关的工具也支持多种选项,并为团队的决定提供了很大的灵活性。本文将让您了解许多可用的选择和权衡。

Different vision workflows in FRC.

OpenCV计算机视觉库

**OpenCV**是一个计算机视觉软件库,在学术界和工业界广泛使用。它有来自硬件制造商的支持,提供GPU加速处理,它绑定多种语言,包括c++, Java,和Python。它还在许多web站点、书籍、视频和培训课程有详细的文档,因此有许多可用资源来帮助学习如何使用它。c++和WPILib Java版本都包含有OpenCV库,可提供捕获、处理和查看的视频,以及帮助创建视觉算法的工具。有关OpenCV的更多信息,请参见 https://opencv.org

在roboRIO上运行视觉代码

The chain from a USB Webcam to roboRIO to Ethernet Switch over a video stream to the driver station computer.

Vision code can be embedded into the main robot program on the roboRIO. Building and running the vision code is straightforward because it is built and deployed along with the robot program. The vision code can be written in C++, Java, or Python. The disadvantage of this approach is that having vision code running on the same processor as the robot program can cause performance issues. This is something you will have to evaluate depending on the requirements for your robot and vision program.

In this approach, the vision code simply produces results that the robot code directly uses. Be careful about synchronization issues when writing robot code that is getting values from a vision thread. The VisionRunner class in WPILib make this easier.

使用CameraServer类提供的函数,视频流可以发送到仪表盘,比如Shuffleboard,这样操作手就可以看到摄像头看到的内容。此外,可以使用OpenCV命令将注释添加到图像中,以便在仪表盘视图中识别目标或其他感兴趣的对象。

DS计算机上的视觉代码

Same as the above diagram but the Driver Station computer must process that video and send NetworkTables updates back to the roboRIO.

When vision code is running on the DS computer, the video is streamed back to the Driver Station laptop for processing. Even the older Classmate laptops are substantially faster at vision processing than the roboRIO. You can write your own vision program using a language of your choosing. Python makes a good choice since there is a native NetworkTables implementation and the OpenCV bindings are very good.

图像处理后,关键值,如目标位置、距离或任何您需要的东西,可以通过网络表格发送回机器人。这种方法通常具有较高的延迟,因为需要将图像发送到笔记本电脑会增加延迟。带宽的限制也限制了用于处理的图像的最大分辨率和FPS。

The video stream can be displayed on Shuffleboard or SmartDashboard.

协处理器上的视觉代码

Coprocessor is on same network as the roboRIO so it off loads the compute without having the latency of going to the Driver Station and back.

像Raspberry Pi这样的协处理器是支持视觉代码的理想选择(参见:ref: ‘ docs/software/vision-processing/frcvision/ using-raspberry - pie -for- FRC:Using the Raspberry Pi for FRC ‘)。优点是它们可以全速运行,不干扰机器人程序。在这种情况下,摄像机可能连接到协处理器,或者(对于以太网摄像机来说)机器人上的一个以太网开关。该程序可以用任何语言编写;Python是一个很好的选择,因为它可以简单地绑定到OpenCV和NetworkTables。一些团队使用高性能的视觉协同处理器,如Nvidia Jetson,以获得最快的速度和最高的分辨率,尽管这种方法通常需要高级的Linux和编程知识。

与其他两种方法相比,这种方法需要更多的编程专业知识和少量的额外权重,但除此之外,它带来了两个方面的最佳效果,因为协处理器比roboRIO快得多,并且图像处理可以以最小的延迟或带宽使用进行。

据可以通过网络或串行连接从协处理器上的视觉程序发送到机器人。

相机选择

WPILib支持多种摄像机选项。 摄像机有许多影响操作的参数;例如,帧频和图像分辨率影响接收图像的质量,但当设置过高的影响处理时间时,如果发送到操控站,可能会超过现场的可用带宽。

c++和Java中的CameraServer用于与连接到机器人的摄像机进行对接。它通过源对象检索用于本地处理的帧,并将流发送到您的操控站,以便在那里查看或处理。