Monday, April 29, 2013

Python precision timing a loop with sleep

Here is my lovely timed loop, making use of suggestions that I'd already picked up earlier from several places. Since there's stuff in the loop that has an indeterminate run time, in order to make the loop start at the same interval of elapsed time every time, the secret is to count in increments of elapsed time from a start time taken before the first loop, and use while and sleep to wait until the next time interval threshold is crossed to do the next iteration (rather than just doing a single hard-coded wait, which will result in drift):


import datetime as dt

starttime = dt.datetime.now()
loopcount = 0
period = x #seconds

while([loop condition]):
[stuff that the loop does]
loopcount = loopcount + 1
nexttime = starttime + dt.timedelta(seconds=(period*loopcount))
timenow = dt.datetime.now()
while (nexttime > timenow):
time.sleep(0.1)
timenow = dt.datetime.now()

Here's a nice link that I found this time that shows how to do adding seconds to a time in python:
http://stackoverflow.com/questions/100210/python-easy-way-to-add-n-seconds-to-a-datetime-time

Thursday, April 25, 2013

StoopidTall

Everything I have been able to find online about this fun video:

The neatorama link:

http://www.neatorama.com/2013/04/24/STOOPID-TALL-145-foot-Bike/

The video on YouTube:

http://www.youtube.com/watch?v=bJXXckWLc0E

A great video with some of the same scenes except shot at ground level, with no music overlay (amazing silence):

http://www.youtube.com/watch?v=xh6tw6GcFyI

Some flikr postings from the ground:

http://www.flickr.com/photos/pyrokinetic/

The blog post on the topic by the same guy, with lots of good words:

http://blog.halbergman.com/2013/04/22

Links to the "apparently very underground" band that the music from the original video is: Listed as "Amoebaz - Rune!"

"The album is called "Nascence". It's very underground apparently." http://youmustlearn.us/2009/12/09/paint-the-town-rune/

http://www.mediafire.com/download.php?tdkgywegnmm

The guy's AMA on Reddit:

http://tinyurl.com/STOOPIDTALLAMA

A music video showing one of the guy's earlier tallbikes. This whole production is so Los Angeles that I feel like I'm back there:

http://www.youtube.com/watch?v=hTMrlHHVx8A