autotest: fixed sleep_overhead calculation in sim_multicopter.py

This commit is contained in:
Andrew Tridgell 2013-04-08 06:59:36 +10:00
parent 8d992ae615
commit 960574cccf
1 changed files with 6 additions and 5 deletions

View File

@ -176,10 +176,11 @@ while True:
frame_count += 1 frame_count += 1
t = time.time() t = time.time()
if t - lastt > 1.0: if t - lastt > 1.0:
#print("%.2f fps zspeed=%.2f zaccel=%.2f h=%.1f a=%.1f yaw=%.1f yawrate=%.1f" % ( # print("%.2f fps sleepOverhead=%f zspeed=%.2f zaccel=%.2f h=%.1f a=%.1f yaw=%.1f" % (
# frame_count/(t-lastt), # frame_count/(t-lastt),
# a.velocity.z, a.accel.z, a.position.z, a.altitude, # sleep_overhead,
# a.yaw, a.yaw_rate)) # a.velocity.z, a.accelerometer.z, a.position.z, a.altitude,
# a.yaw))
lastt = t lastt = t
frame_count = 0 frame_count = 0
frame_end = time.time() frame_end = time.time()
@ -188,4 +189,4 @@ while True:
dt -= sleep_overhead dt -= sleep_overhead
if dt > 0: if dt > 0:
time.sleep(dt) time.sleep(dt)
sleep_overhead = 0.99*sleep_overhead + 0.01*(time.time() - frame_end) sleep_overhead = 0.99*sleep_overhead + 0.01*(time.time() - frame_end - dt)