LabVIEW中用于FRC的局部变量和全局变量

本示例介绍了局部变量和全局变量、如何在默认LabVIEW for FRC® Robot Project中使用它们以及如何在您的项目中使用它们。

Local variables and global variables may be used to transfer data between locations within the same VI (local variables) or within different VI’s (global variables), breaking the conventional Data Flow Paradigm for which LabVIEW is famous.  Thus, they may be useful when, for whatever reason, you cannot wire the value directly to the node to another.

Note: One possible reason may be that you need to pass data between consecutive loop iterations; Miro_T covered this in this post.  It should also be noted that the feedback node in LabVIEW may be used as an equivalent to the shift register, although that may be a topic for another day!

局部和全局变量简介

局部变量可在同一VI中使用。通过右键单击前面板上的输入控件或显示控件来创建局部变量:

../../../../_images/11.png

您也可以从程序框图的“结构”选项板中创建局部变量。当一个VI中有多个局部变量时,可以单击鼠标左键选择它是哪个变量:

../../../../_images/22.png

全局变量的创建略有不同。从“结构”选项板中向框图添加一个,然后注意,双击它会打开一个单独的前面板。该前面板没有程序框图,但是您可以根据需要向该前面板添加尽可能多的控件,并将其另存为* .vi文件:

../../../../_images/32.png

备注

Be very careful to avoid race conditions when using local and global variables! Essentially, make sure that you are not accidentally writing to the same variable in multiple locations without a way to know to which location it was last written. For a more thorough explanation, see this help document

在默认的LabVIEW for FRC机器人项目中如何使用它们

在Robot Main VI的每次迭代期间,都会写入“Enable Vision”和“Image Size”两个全局变量。

../../../../_images/41.png

…然后在Vision Processing VI的每次迭代中进行读取:

../../../../_images/5.png

这使用户可以在将程序从LabVIEW开发环境部署到Robot Main VI时,从Robot Main的前面板启用/禁用视觉并更改图像大小。

您如何在项目中使用它们?

请查看Periodic Tasks VI的框图。可能存在一些值,例如布尔值,可以将其写入Teleop VI中的全局变量,然后从Periodical Tasks VI中读取。然后,可以根据布尔型全局变量决定在Periodic Tasks VI中使用哪些代码或值:

../../../../_images/6.png