Files
allwpilib/wpilibc/wpilibC++/include/Commands/PIDSubsystem.h
James Kuszmaul f65e697107 Revert changes preventing old user code from compiling.
I'm not 100% sure whether we want these, but they are a quick
find and replace to do.

Basically, there are two primary things that we have done
this summer that break existing user code:
-Changing GetInstance() calls to return references instead
 of pointers. This forces users to change from doing something
 like LiveWindow::GetInstance()->AddSensor() to LiveWindow::GetInstance().AddSensor().
-Making PIDGet() and related calls const, forcing users to change
 the function signatures wherever they override them.

The GetInstance() calls don't really matter to me either way,
especially since there are no real ownership issues going on there,
unlike the rest of the smart pointer-related changes.

For the const stuff, it is certainly more correct to mandate that
user PIDGet() functions be const and the such, but at the same time,
I'm not sure that there is any strong need for it, and the errors
generated are not the most helpful. While this wouldn't necessarily
be an issue for more experienced teams or completely new teams (who
don't have any old code to be reusing), it may cause issues for more
average teams who aren't familiar with the intricacies of C++ anything.

Change-Id: I6e7007982069292ea70e6d0fc8ca40203340df1b
2015-09-16 19:10:01 -04:00

77 lines
2.5 KiB
C++

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. 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 $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PID_SUBSYSTEM_H__
#define __PID_SUBSYSTEM_H__
#include "Commands/Subsystem.h"
#include "PIDController.h"
#include "PIDSource.h"
#include "PIDOutput.h"
#include <memory>
/**
* This class is designed to handle the case where there is a {@link Subsystem}
* which uses a single {@link PIDController} almost constantly (for instance,
* an elevator which attempts to stay at a constant height).
*
* <p>It provides some convenience methods to run an internal {@link
* PIDController}.
* It also allows access to the internal {@link PIDController} in order to give
* total control
* to the programmer.</p>
*
*/
class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
public:
PIDSubsystem(const std::string &name, double p, double i, double d);
PIDSubsystem(const std::string &name, double p, double i, double d, double f);
PIDSubsystem(const std::string &name, double p, double i, double d, double f,
double period);
PIDSubsystem(double p, double i, double d);
PIDSubsystem(double p, double i, double d, double f);
PIDSubsystem(double p, double i, double d, double f, double period);
virtual ~PIDSubsystem() = default;
void Enable();
void Disable();
// PIDOutput interface
virtual void PIDWrite(float output);
// PIDSource interface
virtual double PIDGet();
void SetSetpoint(double setpoint);
void SetSetpointRelative(double deltaSetpoint);
void SetInputRange(float minimumInput, float maximumInput);
void SetOutputRange(float minimumOutput, float maximumOutput);
double GetSetpoint();
double GetPosition();
double GetRate();
virtual void SetAbsoluteTolerance(float absValue);
virtual void SetPercentTolerance(float percent);
virtual bool OnTarget() const;
protected:
std::shared_ptr<PIDController> GetPIDController();
virtual double ReturnPIDInput() = 0;
virtual void UsePIDOutput(double output) = 0;
private:
/** The internal {@link PIDController} */
std::shared_ptr<PIDController> m_controller;
public:
virtual void InitTable(std::shared_ptr<ITable> table);
virtual std::string GetSmartDashboardType() const;
};
#endif