Issues with Autonomous Program

I recently added a drivetrain PID loop to my program and tested it out with our catapult. But when I ran it with timed run/autonomous skills on the controller, nothing would happen. I tried to check if anything was wrong with my PID and the drivetrain ran fine when I programmed it to only move forward and make a turn. But when I put in a line of code to spin my catapult before telling the drivetrain to move, the catapult would spin, and it would stop there. And if I did the opposite where the catapult moves after the drivetrain, nothing would happen. I already ran the controller through the program and the catapult wasn’t running into any issues. Is there anything I can do to fix this? I can post my code, but it’s just kinda long.

what was that line of code ?

3 Likes

cata.spinFor(reverse, 920, degrees);

so most likely the cata motor cannot spin for 920 degrees and the command blocks while it waits for the motor to complete. Add a timeout for that motor or adjust to an amount that the motor can spin for.

2 Likes

I don’t believe that is the problem, because in the past, I had a simpler PID with somewhat the same structure as my current one and the cata and drivetrain ran just fine.

So… What happens when you try to change the spin degrees, as @jpearman recommended as a first step? It’s a quick and easy thing to test, and more data will give you (and people trying to help you) more insight into potential issues.

Have you run any other tests? Were you able to get this working, and what was the issue (as that could help people with similar problems)?

1 Like

Never mind, I found a random fix, so the catapult should be fine for now. But I ran into another problem, where my two PID loops (one for lateral movement and the other for turning) are fighting against each other, and it’s not letting the drivetrain make a smooth turn. Is there a way to fix this? I tried to turn one of them off while the other is running, but it didn’t really do anything.

How are you combing them? Usually, you would give both motors the lateral and one motor would get -turning and the other would get +turning.

Never mind, I fixed the issue, thank you for your concern though.

1 Like

I’ll include the things that fixed my problem, because a friend called me out on the vex discord for not doing so.

How I fixed the catapult issue:

I realized the “cata.spinFor” command doesn’t like to work with the PID loop for some reason, so I just created a function within that loop. It was something like:
while (moveCata) {
cata.spinFor(reverse, x, degrees);
moveCata = false;
vex::task::sleep(20)
}

And the second problem, where my PID loops were fighting against each other, I just changed the while to an if. How I had it originally was “while the desired value was equal to x number”, and it would trigger the PID. I believe since all of my chains worked like that, they kept fighting with each other whenever both event occurs at least once. By changing the “while” to an “if” and “else if,” everything went fine. The PID is still a loop, because everything is under a while (bool) statement, and it repeatedly checks if any of the following is true.

Hope this makes you happy Connor.

2 Likes