OK, I know I promised you something else in my last post regarding how to animate the real-world data given up by DOPs on the Interceptor, but I got a little sidetracked instead. Today's exercise is how to make strange data talk dirty to Houdini.
I give you the humble PipeIN CHOP. The PipeIn CHOP has been around since before some of you could legally buy a beer, and its primary purpose is to take in data from external apps and sources. Oh great! Awesome! Now I can connect my Lego Mindstorms to Houdini and terrorize the cat! Not so fast, hoss. It's a little like the secret knock to the after-hours rave. Unless you send it exactly the bytes it needs, in exactly the right order, in exactly the right format, you ain't gettin' in. Houdini's PipeIn CHOP likes to get its data in very specific ways. You can't just blow bits at it and expect it to assemble you a pony at the molecular-genetic level.
The PipeIn CHOP gets its data from a named pipe, which is a temp file specifically created and written to for that purpose.
The docs are a bit terse, but what you need to know is this: You poke the PipeIn Chop with commands, the four most useful being 'reset,' 'send current sample,' 'send channel names,' and 'upload.' This is not very far from the ancient Commodore 64 cassette drive. Maybe some of your parents have one in the attic, put there when they had to make room for you.
The point is, once you can make that work for you, the rest is pretty much cake. Watch the video. Afterwards, I'll post some of the code that makes it happen.
Here's the python code for the reset command:
## reset command
def send_reset(fifo):
p = pack('cccc', chr(170), chr(0), chr(170), chr(0))
fifo.write(p)
fifo.flush()
The reset character is 170. We like it so much, we send it twice.
Here's the python code for the 'send current sample'
def send_single_sample(fifo, numchans, val):
cmd_type = 1
num_channels = numchans
vals = val
p = pack('>ii', cmd_type, num_channels )
fifo.write(p)
for i in range(numchans):
v = pack('>f', vals[i])
fifo.write(v)
The '>' character signifies the endian-ness of the data. If any of you have the misfortune to be running Houdini on IRIX, change this to '<.' Tongue firmly in cheek, of course. The 'ii' is part of the 'struct' module in python that formats the data as in, two integers, followed by as many floats as there are channels.
Obviously, this is part of a much bigger script, which I'll post as soon as I can figure out where to put it and link to it.
Thursday, February 11, 2010
Subscribe to:
Post Comments (Atom)
Looks really cool! Have you found a place to put the whole script?
ReplyDelete