Add setVoltage method to SpeedController (#1997)

Add a voltage-compensated setVoltage method to SpeedController, which is sorely needed to help teams use feedforward-based controls effectively. Also uses correct units on the cpp side.

Also update relevant examples.
This commit is contained in:
Oblarg
2019-11-01 12:32:40 -04:00
committed by Peter Johnson
parent f6e311ef86
commit 9ebd23d61e
12 changed files with 88 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,6 +7,8 @@
#pragma once
#include <units/units.h>
#include "frc/PIDOutput.h"
namespace frc {
@@ -25,6 +27,20 @@ class SpeedController : public PIDOutput {
*/
virtual void Set(double speed) = 0;
/**
* Sets the voltage output of the SpeedController. Compensates for
* the current bus voltage to ensure that the desired voltage is output even
* if the battery voltage is below 12V - highly useful when the voltage
* outputs are "meaningful" (e.g. they come from a feedforward calculation).
*
* <p>NOTE: This function *must* be called regularly in order for voltage
* compensation to work properly - unlike the ordinary set function, it is not
* "set it and forget it."
*
* @param output The voltage to output.
*/
virtual void SetVoltage(units::volt_t output);
/**
* Common interface for getting the current set speed of a speed controller.
*