Announcement

Collapse
No announcement yet.

PID Line Follower

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PID Line Follower

    Hey guys! My team did a video tutorial about PID Line Follower. In recent days, we decided to put subtitles to reach more people in the world and so receive a greater feedback.

    We hope that the video help you somehow! We are open to any kind of feedback! Thank you!

    Video link: https://www.youtube.com/watch?v=tn6vj7AjEaU&t=2s




    Thunderboticos Robotic Team (Brazil)

  • #2
    Re: PID Line Follower

    Thanks Thunder! Its really nice how you explain why the parts are necessary. My team wrote their PID line follower 3 years ago and some of those team members are aging out. During the off season I wanted the younger team members to follow down the same exploratory path to come up with their own line follower and I think the first half of the video (before the code) sets the discussion up nicely. Thanks for the translation!

    Comment


    • #3
      Re: PID Line Follower

      I've never seen any benefit from integral and derivative. I've written several PID line followers starting on the RCX and as recently as a few weeks ago. Integrator just wants to make the the robot spin out of control and derivative just makes it jumpy, I never get any damping. Has anyone else seen benefits from using PID over just proportional.

      Comment


      • #4
        Re: PID Line Follower

        I made a PID gyro follower that would let me spin a robot 180 degrees by hitting it with my hand and it would turn back around, overshoot, and come back to essentially the same path it had been on. The integral term was important to pulling it back on the original path vs. just pointing in the same direction based on my observation. This isn't an FLL use case, however.

        I did not find much benefit for line following. I think this is because the input to the light sensor is not a nice slow-moving process like the temperature in a furnace. The distance over which the reflected light signal goes from rail to rail is relatively tiny (1/4" maybe?). I think a line follower tends to spend a lot of time closer to the rails vs. the target due to this small distance (unless it moves really slowly). That would throw off the integral term and tend to cause it to go out of control. Integral term is helpful for fixing small deltas from the target (i.e., a line follower sitting at 52 for a long time might stay at 52 with just the proportional term, the integral would wind up a stronger correction over time to pull it back toward 50).

        I think a PID might be more useful for line following if the lines were a wide gradient vs. a sharp edge. However, I think the bigger question is if a more complicated follower matters for FLL. A proportional follower can be pretty smooth, and it's hard (for me anyway) to come up with a need for anything better.

        Comment


        • #5
          Re: PID Line Follower

          Originally posted by Dean Hystad View Post
          I've never seen any benefit from integral and derivative. I've written several PID line followers starting on the RCX and as recently as a few weeks ago. Integrator just wants to make the the robot spin out of control and derivative just makes it jumpy, I never get any damping. Has anyone else seen benefits from using PID over just proportional.
          I suspected that a derivative term would be needed to follow the line around the milker, but it wasn't true for my team's robot/program. Far more useful to spend the finite time budget on better solutions, or more testing, or project research (or almost anything else).

          I've always put a lot of effort into reminding my teams to think about time. There's only so many weeks in the season, only so many hours in any meeting, only 2.5 minutes in the robot game. I don't know if it sticks, but I feel remiss if I don't remind them.

          Comment


          • #6
            Re: PID Line Follower

            Proportional-only seems to work adequately for LEGO League-related tasks (can't call it "FLL" any more...).
            FIRST Tech Challenge Judge: 2010, Referee: 2017
            FIRST LEGO League Mentor, Instructor, and/or Referee/Head Referee since 2011
            FIRST Robotics Competition judge (Chairman's Award): 2014
            Dean says I'm an "Oompa Loompa of Science"

            Comment


            • #7
              Re: PID Line Follower

              Indeed, in terms of efficiency, a proportional line follower is enough to follow the line in an FLL competition. We used the P algorithm for several seasons and had no problem. However, as of the Trash Trek season, we were encouraged by our coach to delve into the line followers, thus gaining more learning (after all, what we discover is more important than what we win ). Honestly, by performing a performance analysis between the P and PID line followers, we have identified some improvements. And understanding PID logic has encouraged us to learn more and more about other things. Thanks for the feedback guys!

              Comment


              • #8
                Re: PID Line Follower

                Originally posted by mkirkwood View Post
                I made a PID gyro follower that would let me spin a robot 180 degrees by hitting it with my hand and it would turn back around, overshoot, and come back to essentially the same path it had been on. The integral term was important to pulling it back on the original path vs. just pointing in the same direction based on my observation. This isn't an FLL use case, however.

                I did not find much benefit for line following. I think this is because the input to the light sensor is not a nice slow-moving process like the temperature in a furnace. The distance over which the reflected light signal goes from rail to rail is relatively tiny (1/4" maybe?). I think a line follower tends to spend a lot of time closer to the rails vs. the target due to this small distance (unless it moves really slowly). That would throw off the integral term and tend to cause it to go out of control. Integral term is helpful for fixing small deltas from the target (i.e., a line follower sitting at 52 for a long time might stay at 52 with just the proportional term, the integral would wind up a stronger correction over time to pull it back toward 50).

                I think a PID might be more useful for line following if the lines were a wide gradient vs. a sharp edge. However, I think the bigger question is if a more complicated follower matters for FLL. A proportional follower can be pretty smooth, and it's hard (for me anyway) to come up with a need for anything better.
                Integral is important when you have a continuous or DC type error that cannot be removed using proportional alone. I can see where that would be the case trying to control to some gyro heading. When you stop steering the heading quits changing, and really small errors will hang around because the steering correction drops to zero when the heading error is small.

                Line following is a different kind of beast. It has a built in integrator. Let's say I have a straight line and my robot is slightly to the right of the edge of the line but otherwise perfectly aligned with the line (robot heading and line are parallel). I make a slight steering turn to the left which is followed by driving perfectly straight. Even though my steering correction is zero, the robot continues to move closer and closer to the line as it drives forward. Driving forward "integrates" the previous correction. If I put the steering correction in a loop, computing a new steer based on the difference between the light sensor intensity and some threshold, the steering correction will decrease as the sensor gets closer and closer to centered over the edge. However, the heading change between the robot and the line continues to increase. Eventually the light sensor will be centered over the line, but when it gets there the heading will be way off and the robot will overshoot.

                Your example of the line follower having a small delta that remains constant is not realistic. The only way it could happen is if the robot heading and line are perfectly parallel and the robot is nearly centered on the line. This could drive perfectly straight with a tiny line following error, but it is nearly impossible for such a condition to exist. And in this case, adding an integrator would only induce a wobble. Once the robot and line are out of alignment they can never again become aligned. All you can hope for is an ever decreasing oscillation.

                I can see how derivative could be useful. As the sensor crosses the edge, and the error becomes smaller and smaller, derivative will start the robot turning the opposite direction. In other words, if the robot is to the right of the line the proportional gain will tell the robot to turn left. While the robot is crossing the line from the right the derivative gain will tell the robot to turn right. The proportional term fixes the displacement error, and the derivative term fixes the heading error. In practice I am not seeing this. My experiments with derivative gain show almost no damping until the derivative goes out of control and introduces a high frequency oscillation.

                I think the problem I have using integral and derivative is caused by the nature of the feedback. Much of the time you are trying to follow the edge of the line you are not seeing the edge. The area the sensor "sees" is very small, and much of the time that area is either completely black or completely white. In this state you no longer have a proportional line follower and the correction is saturated; The proportional gain is turning is fast as it can, the integrator winds up, and derivative goes to zero because old error equals new error. When the sensing area sweeps over the edge of the line the steering has over-corrected and the robot is pointing the wrong direction to follow the edge. Soon the sensor sweeps past the edge and you are blind again, only knowing you are left or right. PID works much better when I use a continuous feedback like the gyro angle or ultrasonic sensor distance.
                Last edited by Dean Hystad; 03-03-2017, 11:57 AM.

                Comment


                • #9
                  Re: PID Line Follower

                  Originally posted by tjhawkey View Post
                  I suspected that a derivative term would be needed to follow the line around the milker, but it wasn't true for my team's robot/program. Far more useful to spend the finite time budget on better solutions, or more testing, or project research (or almost anything else).

                  I've always put a lot of effort into reminding my teams to think about time. There's only so many weeks in the season, only so many hours in any meeting, only 2.5 minutes in the robot game. I don't know if it sticks, but I feel remiss if I don't remind them.
                  A circular path like the line around the milking machine might benefit from an integrator. Unlike a straight line, corrections made in the past don't get us closer to the line because the line is curving away. However the integrator would have to be perfectly tuned for the curvature of the line. Derivative would work (or not work) the same way it does for straight lines.

                  I was surprised to see only one team that realized they could "wall follow" on the milking machine instead of trying to track the line. I was also surprised by the large number of teams that used the gyro sensor to decide when to stop. The milking machine is a case where dead reckoning using the rotation sensors gives much better results.

                  Comment


                  • #10
                    Re: PID Line Follower

                    Originally posted by mkirkwood View Post
                    I think a PID might be more useful for line following if the lines were a wide gradient vs. a sharp edge.
                    I want fuzzy lines! I think we should start a petition.

                    Comment


                    • #11
                      Re: PID Line Follower

                      Originally posted by Dean Hystad View Post
                      I want fuzzy lines! I think we should start a petition.
                      Too late. Fuzzy lines would have been appropriate for "Animal Allies". For "Hydro Dynamics", we'll get wavy lines...

                      Comment


                      • #12
                        Re: PID Line Follower

                        Originally posted by Dean Hystad View Post
                        I want fuzzy lines! I think we should start a petition.
                        I'm sure there'd be a way to encode a secret message in the fuzzy lines, and award bonus points for the robot autonomously decoding it.
                        FIRST Tech Challenge Judge: 2010, Referee: 2017
                        FIRST LEGO League Mentor, Instructor, and/or Referee/Head Referee since 2011
                        FIRST Robotics Competition judge (Chairman's Award): 2014
                        Dean says I'm an "Oompa Loompa of Science"

                        Comment


                        • #13
                          Re: PID Line Follower

                          The integral term is very useful when the robot needs to provide a sharper correction when "lost" on one side of the edge or the other. If I'm in white, and the next cycle I'm still in white, I want to increase the degree of turn to find my way back (whereas the proportional term is already maxed out). Integral does this ... when properly tuned. Our team found that they needed to have a damped integral to prevent windup for their robot design. Note you also want to use derivative to prevent overshoot, and it's useful to zero the integral upon the line crossing, again to minimize overshot or out-of-control oscillation.
                          A good proportional will stay on the (straight) line once there, and will align for small degrees of error coming to the line. Having the ID terms helps with a non-straight line, or aligning with a line that wasn't approached well. I do work with the kids to "not be lazy" and have them work out the multiple small "corrections" (e.g. overshoot line then swing to ensure better alignment) rather than rely on the PID to align itself. It's a few more steps of code, but ensures better success since they are solving a "known" position problem rather than letting the algorithm attempt a solve.
                          Technical Coach of the Newton Busters
                          Chicago 'Burbs, IL, USA, Planet Earth

                          Comment


                          • #14
                            Re: PID Line Follower

                            Originally posted by Dean Hystad View Post
                            Line following is a different kind of beast. It has a built in integrator.
                            That's a great insight! Also a good argument for why not to use a PID for line following. The typical line follower is not a linear process. A line follower doesn't act like a typical control process because the act of making a correction causes a continuing change in the signal. For a line follower to act like a typical process, the robot would need to slide left and right perpendicular to the angle it is traveling instead of turning. I can't simply add correction in one direction then return to straight, because the robot is no longer perpendicular to the line. Temperature chambers I work with will alternate between heating and cooling to maintain a temperature, but that's not usually necessary. If it's above room temp it adds heat or doesn't add heat. The line follower adds some positive feedback that would be like if adding heat caused it to keep heating even after the heat was turned off. Cooling would always be necessary, which would cause it to keep cooling by itself, which would need heat again.

                            I built a robot with a color sensor directly in the middle of the robot between the axles, and it liked following lines. I'm guessing this configuration minimizes the problem mentioned above, but doesn't eliminate it. A skid-steer robot can't correct a line position problem without creating a heading problem.


                            Originally posted by Dean Hystad View Post
                            I think the problem I have using integral and derivative is caused by the nature of the feedback.
                            Yup, that's why I think fuzzy lines would be great! As you said, I think a proportional line follower spends a lot of time railed dark or light and doesn't spend much time in a nice linear range. I'll have to find some time to play with this before I'm forced to take down the table until August.

                            Comment


                            • #15
                              Re: PID Line Follower

                              Originally posted by gof View Post
                              The integral term is very useful when the robot needs to provide a sharper correction when "lost" on one side of the edge or the other. If I'm in white, and the next cycle I'm still in white, I want to increase the degree of turn to find my way back (whereas the proportional term is already maxed out). Integral does this ... when properly tuned. Our team found that they needed to have a damped integral to prevent windup for their robot design. Note you also want to use derivative to prevent overshoot, and it's useful to zero the integral upon the line crossing, again to minimize overshot or out-of-control oscillation.
                              A good proportional will stay on the (straight) line once there, and will align for small degrees of error coming to the line. Having the ID terms helps with a non-straight line, or aligning with a line that wasn't approached well. I do work with the kids to "not be lazy" and have them work out the multiple small "corrections" (e.g. overshoot line then swing to ensure better alignment) rather than rely on the PID to align itself. It's a few more steps of code, but ensures better success since they are solving a "known" position problem rather than letting the algorithm attempt a solve.
                              Sounds like the trick to getting integrator to work for line following is using decay and a reset to unwind the integrator. I've tried just using decay and it didn't help much. I've tried clipping and it didn't help much either. I've never tried resetting the integrator sum when the error crosses zero. You are already going to get a ton of overshoot, but resetting the sum lets you forget your earlier transgressions.
                              Last edited by Dean Hystad; 03-15-2017, 08:05 PM.

                              Comment

                              Working...
                              X