Re: nMotorEncoderTarget Freeze
The quickest and easiest way to solve this problem is to add a time condition in the while loop (assuming you are using a while loop to wait for the nMotorRunState of a motor to reach runStateIdle, as shown in the sample programs on the ROBOTC wiki: http://www.robotc.net/wiki/NXT_Function ... oderTarget
To do this, we first need to choose a timer and clear it before we use it; the timers start tracking time from the start of the program, so any elapsed time up to the point it is used in the program will be returned by the timer. By clearing it, we ensure that we start the timer from a known quantity instead (a zero value). More information on using timers in a program can be found on the ROBOTC wiki: http://www.robotc.net/wiki/VEX2_Functions_Timing
Clearing the timer can be done with the ClearTimer() command:
Next, we simply need to add this into the while loop's condition with a logical AND (&&) operator:
For this example, I used the time1 command (time in milliseconds) and 5000 as the maximum value. The while loop now checks to make sure that motorB is not in a runStateIdle mode AND
motor C is not in a runStateIdle mode AND
that the T1 timer is less than 5000. Once one of these conditions becomes false (either by a motor going to the runStateIdle mode or by the T1 timer reaching a value of 5000ms), the motors will stop.
You may need to tweak the time value in order to increase/decrease the amount of time used by while loop. Decrease the value too much, and the loop may exit early. Increase the value too much, and the program will be wasting more time.
Check out our Blog
! And our Facebook page
Need help? Take a look at our Wiki
and our Forums.I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody