Announcement

Collapse
No announcement yet.

Tuning PID to 90 degrees

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

  • Tuning PID to 90 degrees

    For some reason, I've been having the most difficulty tuning my turns to 90 degrees with our robot. The other angles work just fine. When just working on tuning, it sometimes works and doesn't work. What other things can I do about the tuning for 90 degrees?

  • #2
    Please specify what "it doesn't work" means. Was it oscillating? Was it not reaching target?

    Comment


    • #3
      It wasn't reaching target like a small error around 3-4 degrees. The oscillations seem to happen when there's a continuous buildup of errors from previous turns because my autonomous drives forward, turns 30, drives, turns 60, drives forward, and turns 90 to be in alignment with a beacon. Sometimes, I manage to tune the turns so that the robot gets to 90 degrees a few times but then it doesn't work consistently. Also, I'm getting opMode stuck in loop() issues that need me to shut down the phone, wait 15 sec, and then turn on again. I'll go read up on another thread that has the same issue.

      Comment


      • #4
        Hmm, your spinPID code is interesting. You are implementing multiple sets of PID constants for different ranges of turns. Did you happen to look at our setTurnPID method? If so, I think I know why.
        Let me ask another question. When you call spinPID to turn 90 degrees, it is turning 90 degrees from the current heading, right?

        Comment


        • #5
          Yes it is turning 90 from the current heading. I realized that I needed different PID constants for sets of turns because of the power needed to turn 10 degrees would need a larger kP than 45 degrees. Your setTurnPID method had that layout that helped me.

          Comment


          • #6
            The other question I had was as you mentioned earlier that the loop is faster than the gyro sampling like in this run below. Were you able to find any way to work around that?

            Code:
            12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
            12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
            12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
            12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
            12-14 17:07:41.469 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
            12-14 17:07:41.469 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
            12-14 17:07:41.479 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
            12-14 17:07:41.499 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
            12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
            12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
            12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
            12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0

            Comment


            • #7
              Well, unfortunately, that code does not work for you because our code was doing absolute turns, not relative turn. Since you are using relative turn, your logic should look like this:
              Code:
              if(Math.abs(degrees) <= 10.0)
              {
                  pidControlTurn.setPID(0.05,0,0,0);
              } else if(Math.abs(degrees) <= 20.0)
              {
                  pidControlTurn.setPID(0.033,0,0.0001,0);
              } else if(Math.abs(degrees) <= 35.0)
              {
                  pidControlTurn.setPID(0.032,0,0.0002,0);
              } else if(Math.abs(degrees) <= 55.0)
              {
                  pidControlTurn.setPID(0.029,0,0.0,0);
              } else if(Math.abs(degrees) <= 90.0)
              {
                  pidControlTurn.setPID(0.025,0,0.0002,0);
              } else {
                  pidControlTurn.setPID(0.015,0,0.02,0);
              }
              Unfortunately, this means you have been applying random PID constants to your turns when you were tuning. I think with this correction, you don't need that many ranges. We only need two. Unfortunately, it also means you need to retune your turns.

              Comment


              • #8
                Originally posted by FTC8564 View Post
                The other question I had was as you mentioned earlier that the loop is faster than the gyro sampling like in this run below. Were you able to find any way to work around that?

                Code:
                12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
                12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
                12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
                12-14 17:07:41.459 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
                12-14 17:07:41.469 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
                12-14 17:07:41.469 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=75.0, Error=15.0
                12-14 17:07:41.479 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.3, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
                12-14 17:07:41.499 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
                12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
                12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
                12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
                12-14 17:07:41.509 14761-15609/com.qualcomm.ftcrobotcontroller I/System.out: minOutput=-0.5, Output=0.0, maxOutput=0.5Target=90.0, Input=90.0, Error=0.0
                Yes, we got rid of the Modern Robotics I2C gyro. We are now using an analog gyro which gives us different readings on every loop.

                Comment


                • #9
                  Where did you get an analog gyro from and how did it connect into your robot? Was it through the DIM?

                  Comment


                  • #10
                    Originally posted by FTC8564 View Post
                    Where did you get an analog gyro from and how did it connect into your robot? Was it through the DIM?
                    We have an FRC team. They got an analog gyro/accelerometer every year from the Kit Of Parts. So we have a few floating around. The CDIM has eight analog input ports. You just connect it to one of them.

                    Comment


                    • #11
                      BTW, I just looked at your drivePID turn, it has a problem too. It should be:
                      Code:
                      if (Math.abs(distance) < 10)
                      {
                          pidControl.setPID(0.05,0,0,0);
                      }
                      else
                      {
                          pidControl.setPID(0.03,0,0,0);
                      }

                      Comment


                      • #12
                        Would it be better if I got an analog gyro? If so, what changes would I need to make so that it would work as a gyro?

                        Comment


                        • #13
                          Originally posted by FTC8564 View Post
                          Would it be better if I got an analog gyro? If so, what changes would I need to make so that it would work as a gyro?
                          Well, if you can tune your turns okay, I would stick with modern robotics gyro. It is easy for us to use an analog gyro because:
                          1. We have a few of them floating around.
                          2. Our library supports it.
                          The problem with analog gyro is that it gives you the rotation rate, not heading. You need to integrate the rotation rate to get heading. Since you are not taking our whole library, you need to incorporate that feature into your code.

                          Comment


                          • #14
                            BTW, if you have problems with cumulative errors in your turns, you can change to use absolute turn instead of relative turn. That eliminates all errors except for the last one.

                            Comment


                            • #15
                              Also, is it wise to reset the encoders each time after running the PID or should I leave it out?

                              Comment

                              Working...
                              X