Project - Gadgeteer and Motors Part 3 - PID Controllers

I just posted Gadgeteer and Motors Part 3 - PID Controllers on Codeshare. Feel free to discuss and make suggestions here.

15 Likes

Excellent.

No video this time?

@ Gus - Had to wait for the video to finish processing at YouTube.

Another great job! Thanks!

Thanks for sharing.
:clap:

@ Duke Nukem - That was a very interesting and informative video… That definitely deserves some serious kudos.

@ Duke Nukem - Well done again!

:clap: Seriously good Duke! Really informative and explains PID really nicely.

@ Duke, I bought one of these electric mowers last night and every time I hear it automatically increase the power I think about you. Way to leave an impression! :smiley:


EDIT: Jump to 9:50 to hear it. @ Josh hasn’t fixed the video tags yet to support jumping to a specific time…

1 Like

Is it an autonomous electric, or a push? (can’t see the video here, will at home)

I have a robotic mover I bought years ago that I want to play with.

It’s an 80V cordless electric push. Of course, I’m already dreaming of ways to make it more autonomous (while keeping the 5 yr warranty intact).

well, it’s kinda a “soft” approach rather than a “hardware” approach. Make your kids do the lawn. Fully autonomous once you get the job started. May still require re-work. And nagging, probably plenty of that. Really, not much different to what you have today :slight_smile: Never hurt me, so can’t be bad for current generation, right ?!?! :think: .

1 Like

Well in full disclosure… One of the big motivators for the electric vs another gas mower was the reduced weight which makes it easier for my 8 year old to push :wink:

1 Like

I meant to ask - where did you get the encoder wheel and sensor, or were they part of the motor ? I’m adding position sensing to my coffee roaster controller so that I can cut power only when the load opening (aka sliding door) is facing up, which really only needs me to have a single window position and a beam breaker module from Justin (which I don’t have and Justin’s are still in the UK :frowning: ) but I find myself peering at this rabbit hole wondering if I should go down there :slight_smile: .

@ Brett - For this project the motor had the encoder built on as part of the motor. As a good Scottish lad that motor cost me squat as I salvaged it from a paper handling system from a junked printer I picked up from my local electronics recycler. I’ve gotten all sorts of motors from doing that, steppers, DC with and without encoders, brushless DC motors, solenoids, interrupters, etc all for free. You know how they make copper wire, they throw a penny on the ground between two Scotsmen.

@ Duke Nuken:
Regarding the PID control routines, I had a couple of questions on the code in this part of the solution:

if (_lastUpdate != -1)
            {
                double dT = (nowTime - _lastUpdate);
                dT = dT/TicksPerSecond; //convert to seconds


                //Compute the integral if we have to...
                if (pv >= PVMin && pv <= PVMax)
                {
                    partialSum = _errSum + dT*err;
                    iTerm = IGain*partialSum;
                }

                if (dT > 0.0)
                    dTerm = DGain*(pv - _lastPV)/dT;
            }

First, PVMin and PVMax are not scaled, but PV is. In your case if the scaled PV is <0, the I term will not be computed as PVMin = 0. I believe that PVMin and PVMax should first be scaled. This was also noted in a comment on the codeproject site that you adapted the code from, but was not answered by the original author.

Second, also in the codeproject comments, some thought that the the dTerm should be calculated on lastError not lastPV giving:



I was hoping you could comment on these issues.

And, thanks for posting the code and the video!  

Rocky