Catapult PID help

I’m trying to make a P loop to retract the catapult to a certain position. However, it has trouble working a lot of the time.

void retractCata(void) {
  // if (!engageCata) {
    retracting = false;
    PID cataPID(reduce_0_to_360(Catapult.position(degrees) - 60 /*target*/ ), 2, 0, 0, 0);
    while (cataPID.is_settled == false) {
      retracting = true;
      float error = reduce_0_to_360(Catapult.position(degrees) - 60);
      float output = cataPID.compute(error);
      display.Print(append("error: ", error));
      display.Print(append("output: " , output));
      Catapult.spin(fwd, output*0.1 /* testing to see output*/, pct);
      display.resetPrints();
      if (error <= 1) {
        retracting = false;
        Catapult.stop(hold);
        break;
      }
    }
  // }
}

What I noticed was that while the cata was spinning for a period of time, the error and output would start rapidly increasing. However, I have my kI and startI values set to 0, meaning this would not be integral windup, so I don’t know why this would be happening.

Why are you using PID for a catapult? I am assuming that you are using a slip gear. You don’t need a lot of precision for a catapult. I think a Catapult.spin() will work just fine. If you want it to stop at the same spot every time, then just make the Catapult motor spin 360 degrees. If you want to make sure that the gear starts in the same position every time you start your code, then you can set the motor torque to 30 percent or some other low number, and then have it spin for 360 degrees in the other direction. The slip gear will stop when it makes contact with the other gear. You can then set your motor torque back to 100 percent.

1 Like

It may help to share the entire PID class.
cataPID.compute(error);
This is a black box to us and the calculation error could be here.
Other than that, you want to be tracking the angle of the catapult arm, not the motor angle. These can differ greatly since they are not mechanically linked during the firing process.

Assuming the compute method returns the desired motor velocity, there isn’t a need for angle constraining here if we use the cata arm angle as it is physically constrained already. This would simplify the calculation by comparing the current arm angle to the desired angle. Sure this means that you need an extra sensor, but if you use a potentiometer you won’t ever have to worry about the starting orientation of the cata motor relative to the cata arm. This will also work regardless of the motor speed, gear ratio, firing time, drawback angle, and any other physical characteristics. The cata arm will always go to whatever angle we want.

I would argue the opposite as the difference between one tooth on a catapult slip gear can result in the catapult firing which can not only be inefficient but poses a safety hazard if you are not in control of your arm’s position at all times.

This looks like JAR-Template to me, so the compute function should be accurate.

1 Like

yes, I forgot to mention, this IS using jar template.

If error is going up then your catapult is spinning away from whatever your target is. Instead of making your target 60 degrees, you can try making it 360 + 60 so it’s the same angle but it should be in the positive direction of the catapult rotation instead of negative.

That would be the case if you are trying to stop the cata right before it fires, placing down the triball, and then firing the cata. In my experience with catapults, I just placed the tribal while it was going back. I just had to get the timing right, which took some practice. Also if there was a one tooth error that fired the catapult unexpectedly, PID would move the gear back after catapult already fired. I don’t think it would prevent the error, since being off by one tooth only needs a very small error. In general, you shouldn’t have one tooth, be the difference in firing the cata. And even if you did, it would probably still fire anyways because there aren’t enough teeth holding the cata back.

Sure, but op specifically called out wanting to:

As for your other points, The more precise you are the more efficient you can be. Sure this year contains a lot of continuous firing but there are plenty of examples where you would want your catapult to be responsive at any moment. Why waste precious time charging the cata when you really just want it to fire then and there?

Well, there are definitely catapults that can hold with one tooth. Using ratches to relieve stress from the motor and using adequately sized gears are two ways to increase catapult integrity. My advice is meant to be broader than just catapults for this game. Teaching good engineering principles such as having 100% control over your potentially dangerous, projectile launching mechanisms on a mechanical and software level is important.

1 Like

To answer the question here, iseau is close, but instead the error should be desired position minus current position. So in this case

60-Catapult.position(degrees)

Let’s talk about using the JAR template PID class for non-drivetrain mechanisms. I think it’s awesome and I also really like how you pattern matched the API. Be warned though, there are a couple code segments that are mostly there for drivetrains. Specifically, resetting integral control when the robot moves past error=0. This should not be too much of a problem for a catapult, but if you’re ever working with some system that requires steady state integral control then maybe check that out.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.