ROBOTC.net forumshttp://robotc.net/forums/ Stop encoder loop after a set time?http://robotc.net/forums/viewtopic.php?f=52&t=10505 Page 1 of 1

 Author: Cyks [ Mon Feb 09, 2015 10:01 pm ] Post subject: Stop encoder loop after a set time? Hi,Our robot sometimes can run into the wall and get stuck in autonomous, because it uses encoders and it tries to keep going until the encoder tics reach the set amount.Here is some of our code now://Set the motor encoders to zeronMotorEncoder[motorC] = 0;nMotorEncoder[motorD] = 0;nMotorEncoder[motorE] = 0;nMotorEncoder[motorF] = 0;//move forwardwhile ((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600){ motor[motorC] = -40; motor[motorD] = -40; motor[motorE] = 40; motor[motorF] = 40;}motor[motorC] = 0;motor[motorD] = 0;motor[motorE] = 0;motor[motorF] = 0;We want to make the current while encoder loop stop after a set time so that the program will continue to the next one even if it gets stuck. I would think that putting this inside a while(time1(T1) < 2000) loop wouldn't work, because it would get stuck on the encoder while loop and not read the time loop. Here is another way we though of doing it: Would this work the same way?//Set the motor encoders to zeronMotorEncoder[motorC] = 0;nMotorEncoder[motorD] = 0;nMotorEncoder[motorE] = 0;nMotorEncoder[motorF] = 0;//move forwardwhile (((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600) || time1(T1) < 2000){ motor[motorC] = -40; motor[motorD] = -40; motor[motorE] = 40; motor[motorF] = 40;}motor[motorC] = 0;motor[motorD] = 0;motor[motorE] = 0;motor[motorF] = 0;Thanks for any help! Author:  MHTS [ Mon Feb 09, 2015 11:34 pm ]
Post subject:  Re: Stop encoder loop after a set time?    Code://Set the motor encoders to zeronMotorEncoder[motorC] = 0;nMotorEncoder[motorD] = 0;nMotorEncoder[motorE] = 0;nMotorEncoder[motorF] = 0;clearTimer(T1);//move forwardwhile (((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600) && time1(T1) < 2000){    motor[motorC] = -40;    motor[motorD] = -40;    motor[motorE] = 40;    motor[motorF] = 40;}motor[motorC] = 0;motor[motorD] = 0;motor[motorE] = 0;motor[motorF] = 0;    Author:  Cyks [ Tue Feb 10, 2015 2:08 pm ]
Post subject:  Re: Stop encoder loop after a set time?    MHTS wrote:    Code://Set the motor encoders to zeronMotorEncoder[motorC] = 0;nMotorEncoder[motorD] = 0;nMotorEncoder[motorE] = 0;nMotorEncoder[motorF] = 0;clearTimer(T1);//move forwardwhile (((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600) && time1(T1) < 2000){    motor[motorC] = -40;    motor[motorD] = -40;    motor[motorE] = 40;    motor[motorF] = 40;}motor[motorC] = 0;motor[motorD] = 0;motor[motorE] = 0;motor[motorF] = 0;        