DeepSpace  2019
PIDController.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
9 
10 rr::PIDController::PIDController(double kp, double ki, double kd) {
11  this->kp = kp;
12  this->ki = ki;
13  this->kd = kd;
14  this->output = 0.0;
15  this->prevError = 0.0;
16 }
17 
18 double rr::PIDController::Feed(double input, double current){
19  this->error = input - current;
20  this->i += (error * ROBOT_PERIOD);
21  this->d = (error - this->prevError) / ROBOT_PERIOD;
22  this->output = (this->kp * this->error) + (this->ki * this->i) + (this->kd * this->d);
23  this->prevError = this->error;
24  std::cout << "IN: " << input << " err: " << this->error << " i: " << this->i << " d: " << this->d << " out: " << this->output << std::endl;
25  return this->output;
26 }
#define ROBOT_PERIOD
Definition: RobotMap.h:17
double Feed(double input, double current)
PIDController(double kp, double ki, double kd)