创建子系统

Subsystems are classes that encapsulate (or contain) all the data and code that make a subsystem on your robot operate. The first step in creating a robot program with the RobotBuilder is to identify and create all the subsystems on the robot. Examples of subsystems are grippers, ball collectors, the drive base, elevators, arms, etc. Each subsystem contains all the sensors and actuators that are used to make it work. For example, an elevator might have a Victor SPX motor controller and a potentiometer to provide feedback of the robot position.

使用面板创建子系统

../../../../../_images/creating-subsystem-1.png

将子系统图标从面板拖到 “robot description” 中的 “Subsystems” 文件夹中,以创建子系统类。

使用上下文菜单创建子系统

../../../../../_images/creating-subsystem-2.png

右键单击 “robot description” 中的 “subsystem” 文件夹然后将子系统添加到该文件夹。

命名子系统

../../../../../_images/creating-subsystem-3.png

如上所述通过拖动或使用上下文菜单创建子系统后,只需键入您要为子系统指定的名称。名称可以是多个由空格分隔的单词,RobotBuilder 会连接这些单词为您生成合适的 Java 或 C++ 类名称。

添加常量

../../../../../_images/creating-subsystem-4.png

常量对于减少代码中的幻数数量非常有用。在子系统中,它们可用于跟踪某些值,例如升降机特定高度的传感器值,或驱动机器人的速度。

默认情况下,子系统中没有常量。按“常量”旁边的按钮打开一个对话框来创建一些。

创建常量

../../../../../_images/creating-subsystem-5.png

常量表一开始是空的。按“添加常量”添加一个。

添加常量

../../../../../_images/creating-subsystem-6.png
  1. 常量的名称。将其更改为描述性内容。在传动系统的这个例子中,一些好的常数可能是“PlaceDistance”和“BackAwayDistance”。

  2. 常量的类型。这很可能是一个双精度值,但您可以选择以下之一:字符串、双精度、整数、长整数、布尔值或字节。

  3. 常量的值。

保存常量

../../../../../_images/creating-subsystem-7.png

添加常量并设置其值后,只需按“保存并关闭”即可保存常量并关闭对话框。如果您不想保存,请按窗口顶部的退出按钮。

在保存之后

../../../../../_images/creating-subsystem-8.png

保存常量后,名称将出现在子系统属性的“常量”按钮中。

将执行器/传感器拖入子系统

../../../../../_images/creating-subsystem-9.png

将组件添加到子系统需要三个步骤:

  1. 根据需要将执行器或传感器从调色板拖到子系统中。

  2. 给执行器或传感器起一个有意义的名字

  3. 编辑子系统中每个项目的属性,例如模块编号和通道编号。

RobotBuilder 将自动为机器人上的每个模块使用递增的通道编号。如果您尚未为机器人接线,您可以让 RobotBuilder 为每个传感器或执行器分配唯一的通道编号,并根据生成的接线表为机器人接线。

这只是在 RobotBuilder 中创建子系统,随后将为子系统生成骨架代码。要使其实际操作您的机器人,请参阅:ref:为子系统编写代码 <docs/software/wpilib-tools/robotbuilder/writing-code/robotbuilder-writing-subsystem-code:Writing the Code for a Subsystem> .