设定点指令
A Setpoint Command works in conjunction with a PIDSubsystem to drive an actuator to a particular angle or position that is measured using a potentiometer or encoder. This happens so often that there is a shortcut in RobotBuilder to do this task.
从PIDSubsystem开始
假设在机器人中有一个带有电位器的腕关节,该电位器可测量角度。首先,创建一个PIDSubsystem <robotbuilder-writing-pidsubsystem-code>,其中包括用于移动腕关节的电动机和用于测量角度的电位计。 PIDSubsystem应该具有所有PID常数,并且可以正常工作。
设置 “ 公差 ” 参数是很重要的。这可以控制当前值与设定值之间的距离,并且可以将其视为目标。这是SetpointCommand用于移至下一个指令的条件。
创建设定点指令
右键单击面板中的Commands文件夹,然后选择“添加设定点指令”。
设定点指令参数
Fill in the name of the new command. The Requires field is the PIDSubsystem that is being driven to a setpoint, in this case the Elevator subsystem.
Click on the Parameter Presets to set up the setpoints.
Select Add Preset
Enter a preset name (in this case ‘bottom’
Click the dropdown next to the setpoint entry box
Select the Elevator.Bottom constant, that was created in the Elevator subsystem previously
Repeat steps 2-5 for the other setpoints.
Click Save and close
There is no need to fill in any code for this command, it is automatically created by RobotBuilder.
每当调度此指令时,它会自动将子系统驱动到指定的设定值。当达到设定值在PIDSubsystem中指定的公差范围内时,该指令结束,下一条指令开始。在PIDSubsystem中,指定公差很重要,否则该指令可能永远不会结束,因为无法达到公差。
备注
有关PID控制的更多信息,请参阅高级控件简介<docs/software/advanced-controls/introduction/index:Advanced Controls Introduction>。