commit d314ad6fea816f8332fb75069e78048c881193a8
Author: galberding <galberding@techfak.uni-bielefeld.de>
Date:   Tue Nov 19 16:40:25 2019 +0100

    Refactor and add doc

diff --git a/devices/DiWheelDrive/linefollow.hpp b/devices/DiWheelDrive/linefollow.hpp
index b1f8323..8320b85 100644
--- a/devices/DiWheelDrive/linefollow.hpp
+++ b/devices/DiWheelDrive/linefollow.hpp
@@ -10,12 +10,12 @@
 namespace amiro {
   
   enum LineFollowStrategy{
-  EDGE_LEFT,
-  TRANSITION_L_R,
-  TRANSITION_R_L,
-  EDGE_RIGHT,
+  EDGE_LEFT,      // driving on the left edge of a black line
+  TRANSITION_L_R, // Transition from left to right edge
+  TRANSITION_R_L, // transition from right to left edge
+  EDGE_RIGHT,     // driving on the right edge of a black line
   REVERSE,
-  MIDDLE,
+  MIDDLE,         // not working, use FUZZY instead
   FUZZY,
   NONE
   };
@@ -30,12 +30,26 @@ class LineFollow
 {
 public:
 
-  // TODO: Documentation
   int biggestDiff = 0;
   Global *global;
   LineFollow(Global *global);
   LineFollow(Global *global, LineFollowStrategy strategy);
+  /**
+   * Entry method which should be called to follow a line.
+   * 
+   * @param rpmSpeed speed that will be determained
+   * @return white flag, 1 if white is detected  
+   */
   int followLine(int (&rpmSpeed)[2]);
+
+  /**
+   * Setter for LineFollowStrategy which triggers transition behavior.
+   * 
+   * To prevent random turns while changeing the strategy a transition state is set.
+   * In case the strategy needs to be switched immediately use promptStrategyChange().
+   * 
+   * @param strategy 
+   */
   void setStrategy(LineFollowStrategy strategy);
   void promptStrategyChange(LineFollowStrategy strategy);
   LineFollowStrategy getStrategy();
@@ -63,29 +77,51 @@ public:
   const int greyStartRising = blackStartFalling; // Where grey starts rising
   const int greyOff = whiteOn; // Where grey is completely off again
 
-  private:
-    int delta();
-    int getError();
-    int transitionError(int FL, int FR, int targetL, int targetR);
-    int getPidCorrectionSpeed();
-    void lineFollowing(int (&proximity)[4], int (&rpmFuzzyCtrl)[2]);
-    // void defuzz(colorMember (&member)[4], int (&rpmFuzzyCtrl)[2]);
-    Color memberToLed(colorMember member);
-    void defuzzyfication(colorMember (&member)[4], int (&rpmFuzzyCtrl)[2]);
-    colorMember getMember(float (&fuzzyValue)[3]);
-    void fuzzyfication(int sensorValue, float (&fuzziedValue)[3]);
-    void copyRpmSpeed(const int (&source)[2], int (&target)[2]);
-
-    char whiteFlag = 0;
-    LineFollowStrategy strategy = LineFollowStrategy::EDGE_RIGHT;
-    float K_p = 0.002;
-    float K_i = 0;
-    float K_d = 0;
-    int accumHist = 0;
-    float oldError = 0;
-    int trans = 0;
-    int vcnl4020AmbientLight[4] = {0};
-    int vcnl4020Proximity[4] = {0};
+private:
+  /**
+   * Calculate the error from front sensors.
+   */
+  int getError();
+
+  /**
+   * Error calculation while changing from one EDGE_* strategy to another.
+   * This prevents the AMiRo from random turns while switching strategies.
+   * 
+   * @param FL value of left front sensor
+   * @param FR value of right front sensor
+   * @param targetL left threshold 
+   * @param targetR right threshold
+   */
+  int transitionError(int FL, int FR, int targetL, int targetR);
+
+  /**
+   * Use the error according to the strategy to calculate the correction speed.
+   * Currently only the P part of the PID controller is used to calculate the 
+   * correction speed.
+   */
+  int getPidCorrectionSpeed();
+
+  // Fuzzy line following methods--------------
+  void lineFollowing(int (&proximity)[4], int (&rpmFuzzyCtrl)[2]);
+  Color memberToLed(colorMember member);
+  void defuzzyfication(colorMember (&member)[4], int (&rpmFuzzyCtrl)[2]);
+  colorMember getMember(float (&fuzzyValue)[3]);
+  void fuzzyfication(int sensorValue, float (&fuzziedValue)[3]);
+  void copyRpmSpeed(const int (&source)[2], int (&target)[2]);
+  int vcnl4020AmbientLight[4] = {0};
+  int vcnl4020Proximity[4] = {0};
+  // -----------------------------------------
+  LineFollowStrategy strategy = LineFollowStrategy::EDGE_RIGHT;
+  char whiteFlag = 0;
+  int trans = 0;
+
+  // PID controller components ---------------
+  float K_p = 0.002;
+  float K_i = 0;
+  float K_d = 0;
+  int accumHist = 0;
+  float oldError = 0;
+  // ----------------------------------------
 };
 
 
