Hello! I would love some help with a function I wrote for our autonomous routines. Basically what the function does is it relies on input from quad encoders and attempts to hit our target value we call in the function. The issue is our routine keeps getting stuck in the function as can be seen in this video.
Video displaying problem
I know it would be easier just for me to copy/paste my code here, but anyone willing to help please just send me a pm and I’ll send you the code rather than it being public. Thanks in advance!
I’m willing to help. PM me the code.
It is probably not within the range you are looking for and there is not enough power to move the arm from there.
Another helpful trick is to have a timer kick out as well as a range of error to determine when to return from the function. Use the built in timers and if it is beyond a good deal of time that you would normally run that function, let it kick out.
We do this because of the issue in the video, or if we are waiting for the claw to reach a certain position and it doesn’t close right. We time the robot with low batteries, and those are our failsafe times (within reason).
@Team80_Giraffes yes, I had tried to make a kick out, but Barin pointed out a fatal flaw in how I had attempted to do it and now i have fixed it. It works a lot better now
This was a huge issue that I had to deal with when I first starting programming using functions. The solution I found was that when my error was larger than a certain point I would reset a timer, so once the error gets small the timer will start to count up, once the timer reaches a small value it will break from the loop.
here is an example:
if(abs(error) >75)
{
clearTimer(timer2) ;
}
if(time1[timer2] > 500)
{
break;
}