Monday, 22 August 2011

How to find dt or time interval?

Well, there are two methods mostly used by people as far as I know
1) they do not measure it every single time, they measure it once and then they use it as a constant. Because the time interval is almost the same it may change for 1 to 5 percent according to my experience. They are some people out there that they use this method although it may not look so accurate but it works. If you want to use this approach you have to use the same way that will be explained in part 2.

2) You use a timer and you count number of times that your timer overflow. you times the number of time your timer overflowed to maximum amount that your timer counts plus one (plus one is needed because your timer starts from zero) and then you add the final value of the timer to result of last multiplication. Then you times that to the 1/frequency of your timer and it gives you the time in second.
   total_timer_value = (Number_of_time_ overflowed  *  (the maximum amount that timer can hold + 1) ) + timer_value_right_now 

   time_in_seconds  = total_timer_value * ( 1 / frequency_of_timer )

If you want the accurate way you have to repeat this for every loop of your program, but if your controller is not fast enough or you want it easy way then just use method one and find the dt in same way that I just explained and use it as a constant in your program.

3) (introduction does not include this)
I recently found a new way which was done by my friend Shane colton (http://scolton.blogspot.com/), he used a timer interrupt for his quad. which means that no matter what happens in every certain period of time it will start the loop from the beginning. This method can be used, but I personally can't use it because my IMU is giving me the data in serial and I can't estimate how much time I need to read the data.(I am not using interrupt to read the data from sensor, because of my sensor)

No comments:

Post a Comment