Hi! We are having lots of trouble with our autonomous. A couple weeks ago, it was working just fine. However, recently, it has been freezing at random points in the code. We have tried using timeout functions to fix this, but it still freezes. We don’t believe that it’s a connection issue, since we don’t have problems during driving. However, it seems unlikely that it is a problem with our code either, because it was working perfectly fine earlier and we didn’t change it. Does anyone have any suggestions on how to fix this? If needed, I can post the code, but I’m not sure if that will be useful. Thank you!
sometimes your program will try to complete an action (for example driving forwards 1 foot) and most of the time it is able to complete this action and continue, but sometimes your robot might attempt to complete this action but fall just short (say instead of 1 foot it moves 11 inches and stops) then the code will be stuck at the point unable to continue. to me, the problem you describe sounds like this kind of issue.
posting your code would help us to find anything that might be causing unreliable program completion.
Here is a snippet of our code, the robot tends to freeze after the first line (but sometimes it goes on). The timeout command is a function that we created to put timeouts over multiple motors. We added those commands to attempt to fix the freezing problem, but it still does not work.
could you post your entire program? especially the functions you’re using.
try getting rid of the whole
waitUnit(LForward && LBack && RForward && RBack)
stuff in your code. I have a feeling that’s what’s causing you problems.
A much better way of making your functions wait until completion to progress is using
spinFor, and making the last one blocking so that the program waits for it to complete. like this:
leftForward.rotateFor( revolutions, rotationUnits::rev, false ); leftBack.rotateFor( revolutions, rotationUnits::rev false ); rightForward.rotateFor( revolutions, rotationUnits::rev, false ); rightBack.rotateFor( revolutions, rotationUnits::rev, true );
the last parameter of rotateFor is asking whether or not the program will wait for this function to complete before moving on. this means you don’t need to have all those booleans to detect if a motor is moving or not. (which is probably your problem in the first place)
hopefully this helps! (and that I got it right because I’m not a coder)
Thank you so much! It worked! Thanks again!