Robot randomly freezing during autonomous code

The robot randomly freezes during autonomous runs. You can either wait for around a minute and then it carries on, or you can give it a nudge. How do I fix this?

In case it helps, I am using a Version 1 brain with 2.4 gHz radio module, and I code using Vexcode IQ C++

1 Like

It might be the motors spending a minute trying to get to the correct position before it gives up.

Try setting the motor timeout time to something like 3 seconds. Which means after 3 seconds of the robot trying to turn a motor it gives up and goes onto the next line.

This would be a single line at the start of the program for each motor:
motor.setTimeout(3, seconds);

5 Likes

As noted above, could be timeout or a code issue.
Can you share your code?

Sorry, it didn’t let me put both photos in the same reply

Thanks for your reply. Will this not mean that the robot will not complete the line of code (e.g. not turn for the complete number of degrees)?

If you pick your robot up, and hold it off the droukx fir the entire run, does it randomly stop the motors?

1 Like

If you do this, you’ll need to turn the robot to get through the gyro turns and vision sensor parts as the code has sections that wait for this to be completed.
Timeouts as suggested by @StuartV seem like the most likely issue here.

1 Like

Thank you for the reply! Sorry, this is probably just me not understanding, but please can you clarify?

Instead of putting your robot on the field and running it, hold it so that the heeled don’t touch the ground. When the robot is supposed to turn using the gyro, just turn the robot in your hands

3 Likes

I am not using a gyro for the turns, and am instead using drivetrain measurements

Then just set your robot down where no wheels touches the ground, and run the program. Does it run as expected? When it is off the ground, does it also stop randomly?

2 Likes

That’s not usually an issue. It only take a second to make most turns, so if it’s taking more than a few seconds than something is probably wrong. When a motor gets stuck, it usually has already competed most of it’s turn and just can’t get the last 5%, such as picking up a game piece.

2 Likes

I had this same problem, but this is an easy fix. Let’s say if the robot is going up against a wall and randomly stops, and your code it says “drive reverse 350mm”. The code will keep running until it completes the step, so if the distance from your robot and the wall is 300, the robot will line up on the wall and stay there until it moves the extra 50mm. To fix this you just make it drive reverse and make it wait a certain amount of seconds and then stop the drivetrain

1 Like

If I had known this a month ago, my auton skills would be so much easier to code…

True, but autonomous isn’t reliable at all, if someone builds an autonomous that can run on any field, then lets say they would probably crush everyone