line_following
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
line_following [2025/02/20 12:36] – [Special Section - Wall Following with PID Control] arim | line_following [2025/02/20 12:44] (current) – [Special Section - Wall Following with PID Control] arim | ||
---|---|---|---|
Line 207: | Line 207: | ||
===== Special Section - Wall Following with PID Control | ===== Special Section - Wall Following with PID Control | ||
- | Code: | + | Code: {{ : |
\\ Video: [[https:// | \\ Video: [[https:// | ||
\\ {{ : | \\ {{ : | ||
Line 244: | Line 244: | ||
\\ **- Wall Following with PID** | \\ **- Wall Following with PID** | ||
+ | \\ Refer to this example for the PID gain values, but adjust them to best suit your Domabot. | ||
- | | + | //Variable initializations --------------------------------------------------- |
- | //motor getting > 2*speedBase (if speedBase > 50, this means >100) | + | xWall = 0; // |
- | if(wCorr > 0 && wCorr > speedBase) { | + | dWall = 10; //Desired distance from wall [cm] |
- | wCorr = speedBase; | + | wKp = 1.25; //Wall P gain e.g. (PID) = [1.5, 0.005, 30.0] |
- | //So Motor C speed min will be 0 | + | wKi = 0.001; |
- | }; | + | wKd = 7.5; //Wall D gain |
- | if(wCorr < 0 && wCorr < -speedBase) { | + | |
- | wCorr = -speedBase; | + | // |
- | | + | wE = xWall - dWall; |
- | }; | + | wEInt +=wE; |
- | //(1B) If PID gains all zero, then wCorr = 0 so do bang-bang | + | wEDot = wE - wEPrev; |
- | if(wCorr == 0 && xWall < dWall) { | + | wCorr = (wKp * wE) + (wKi * wEInt) + (wKd * wEDot); |
- | wCorr = -speedBase; | + | |
- | }; | + | |
- | if(wCorr == 0 && xWall >= dWall) { | + | //motor getting > 2*speedBase (if speedBase > 50, this means >100) |
- | wCorr = speedBase; | + | if(wCorr > 0 && wCorr > speedBase) { |
- | }; | + | wCorr = speedBase; |
- | + | //So Motor C speed min will be 0 | |
- | // | + | }; |
- | speedA = speedBase + wCorr; | + | if(wCorr < 0 && wCorr < -speedBase) { |
- | speedC = speedBase - wCorr; | + | wCorr = -speedBase; |
- | OnFwd(OUT_C, | + | |
- | OnFwd(OUT_A, | + | }; |
- | + | //(1B) If PID gains all zero, then wCorr = 0 so do bang-bang | |
- | //(3) update wall errors for next derivative calculation | + | if(wCorr == 0 && xWall < dWall) { |
- | wEPrev = wE; | + | wCorr = -speedBase; |
+ | }; | ||
+ | if(wCorr == 0 && xWall >= dWall) { | ||
+ | wCorr = speedBase; | ||
+ | }; | ||
+ | |||
+ | // | ||
+ | speedA = speedBase + wCorr; | ||
+ | speedC = speedBase - wCorr; | ||
+ | OnFwd(OUT_C, | ||
+ | OnFwd(OUT_A, | ||
+ | | ||
+ | | ||
+ | wEPrev = wE; |
line_following.1740083797.txt.gz · Last modified: by arim