Flywheels Dying Down Only when Take-Back-Half Used

We’re having an issue with our dual flywheel with ratchets (horizontal, 1:17.5 gear ratio with 2 torque motors on each side). When we run the flywheels with just a motor power, they can go for 3+ minutes. But when we run the flywheels with our take-back-half algorithm, the flywheels seem to burn out after shooter around 25 balls. However, the accuracy is very high (~80-90%).

Before I include the code, I want to give some reasons I can think of that might be causing this:

  1. Something is accumulating in the take-back-half algorithm and making it want to run the motors at 127, causing them to burn out (we ran the flywheels at 100 power for 2 minutes straight and had no issues).
  2. If you look at the code below, you’ll see that we’re using a really high gain. Essentially, we find that with this flywheel, the lower gains make it too passive and make recovery times too high. The effect of this gain is that it’s jittery and oscillates when we leave it alone. After we shoot, there’s a big spike, and we make the next shot as the motor power starts to decrease after the spike. Could it be that the motors oscillating are causing them to draw too much power? We are using a power expander, with side of the flywheel for the Cortex and one for the power expander.
  3. Since take-back-half is essentially a weighted moving average, the 0 value for error at the start of the program is causing problems with the calculation and changing the error in some way. I don’t think this is the issue because our other flywheel that has the same configuration runs with a lower gain with no issues.

Here’s a link to the relevant code: TBH controller code · GitHub

If you have any suggestions about what might be happening here, they would be greatly appreciated. While we could take a break after shooting 25 balls and continue at the end of the match, that wouldn’t be ideal (we have a tournament Saturday).

Is it possible that we just didn’t find the right “low” gain? Our other flywheel robot’s gains are 0.00735 and 0.00725 and shoots about just as accurately.

I don’t have much experience with the TBH algorithm, but I’m pretty familiar with PID so I’ll try to troubleshoot this with you.

I was under the impression that TBH was supposed to maintain a constant velocity even after shooting the ball. The oscillation you described shouldn’t be there and is most likely a result of poor tuning.(Oscillation occurs with poorly tuned PID loops as well.) I’d definitely recommend going back and retuning the TBH loop on your flywheels.

On that note, I’d also recommend trying to lower the value of your constant. In PID at least, the value of constants is usually never more than 1. I’d assume that the same is true for TBH.

@Nehalem - Thanks for the advice. From the start I knew that our gain was (very) abnormal; ironically, it worked surprisingly well once we fixed the underlying issue (see below), and we won programming skills at our competition yesterday.

I have some ideas to reduce that oscillation before we hopefully move to PID; however, it seems like we were actually experiencing some kind of power sharing issue. We were using a power expander on the side of the flywheel that was dying, and apparently the power expander splits power into ports A and B, and C and D, like the Cortex does with ports 1-5 and 6-10. We moved one of the dying flywheel’s motors to port D (so we had ports A and D for the flywheel). At our competition, I also noticed that when our battery was too high (most annoying thing ever, also >~8.5V), that side of the flywheel would die. I think it caused the oscillations to be too fast because the motors were too capable with the extra power, causing them to trip the power expander PTC, which doesn’t necessarily just cut power to the motors.

We managed to do pretty well at our competition by being way too paranoid about our battery voltage, although we did lose in the semifinals to the top team in our state. In the future, I’d like for this to not be an issue by making our flywheel algorithm less volatile.

FYI, the information on the wiki page refers to the older PIC 0.5 controller and original 3-wire motors. The general concept is the same with the cortex except that there are two 4A circuits and motor stall current for the 393 is much higher.