ROBOTC.net forums
http://robotc.net/forums/

Timing Issue
http://robotc.net/forums/viewtopic.php?f=52&t=8197
Page 1 of 1

Author:  FTCBrowncoats [ Wed Mar 12, 2014 2:36 pm ]
Post subject:  Timing Issue

We're trying to return to the start point after scoring the IR cube, but we don't have any sensors that can be used for timing or distance measure so we elected to use a simple raw int incriment decrement timer. The problem is, that whenver we run it, it doesn't return back, it just sits there.

Code:
while (findDirection() != 8) {
      timeRun++;
   }

   motor[frontRight] = -40;
   motor[frontLeft] = -40;

   wait1Msec(600);

   motor[frontRight] = 0;
   motor[frontLeft] = 0;

   deployServo();
   
   motor[frontLeft] = -50;
   motor[frontRight] = -50;
   
   while (0 <= timeRun) {
      timeRun--;
   }
   
   motor[frontLeft] = 0;
   motor[frontRight] = 0;
   
}


findDirection() returns the highest IR sensor zone reading as an int

Author:  BurningLights [ Wed Mar 12, 2014 6:34 pm ]
Post subject:  Re: Timing Issue

My guess it that either your first loop runs significantly slower than your second loop because of the IR sensor stuff, or you're running into variable overflow. Either way, I would recommend that you use a timer to track how long your first loop takes, instead of incrementing a variable. The code for using a timer looks like this:
Code:
// Clear out the first timer
ClearTimer(T1);

// Do your IR beacon finding loop

// Get the number of milliseconds the first timer has been running
long milliseconds = time1[T1];


Then to retrace your steps:
Code:
// Drive backwards

// Clear out first timer again
ClearTimer(T1);

while (time1[T1] < milliseconds){}

// Stop driving

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/