MRMS
mrm-pid.h
1 #pragma once
2 #include "Arduino.h"
3 
4 #define PrintSpeed // If defined, a speed calculation will be displayed.
5 
12 class Mrm_pid
13 {
14  float cumulativeValue = 0;
15  float derivative; // A derivative component, depends on error change (not on error value).
16  // For example, if a robot follows a line and the line is the below robot's center (error 0), it will not mean that we will not have to
17  // correct the robots direction. If, at that moment, the robot is turning sharply to the left (but the current error is the mentioned 0), You will
18  // have to set the motors' speed so that the robot turns to the right. It will not turn to the right as it has a big rotational
19  // speed to the left, but the speed will be reduced. By doing nothing, robot would turn to much to the left. The proportional
20  // component would start to influence the motion but it would be too late - You would see a periodic left - right rotation.
21  float integrative; // Integral component, corrects a long term error. For example when left motors are stronger causing the robot to go more to the right, when it should go straight.
22  unsigned long lastCalcuationAtMicros = micros();
23  float lastValue = 0;
24  float proportional; // Proportional component. A bigger error causes a bigger correction.
25  HardwareSerial * serial; //Additional serial port
26 
31  void print(String message, bool eol = false);
32 
33 public:
40  Mrm_pid(float proportionalComponent, float derivativeComponent, float integrativeComponent, HardwareSerial * hardwareSerial = 0);
41 
47  float calculate(float inputValue, bool verbose = false);
48 };
49 
Definition: mrm-pid.h:13
Mrm_pid(float proportionalComponent, float derivativeComponent, float integrativeComponent, HardwareSerial *hardwareSerial=0)
Definition: mrm-pid.cpp:9
float calculate(float inputValue, bool verbose=false)
Definition: mrm-pid.cpp:22