Jump to content

Houdini + Arduino + Robotic Claw


GallenWolf

Recommended Posts

Hello fellow Houdniks! I have been remiss in attending this forum, but here's my latest houdini-related thingy. Controlling a 2 dof robotic arm.

Notes:

- OTL included will give a python error if there is no serial device on /dev/ttyACM0 - please note that I am running Linux, so I have no idea what this will be like on Windows.

- I'm using __main__ to store global variables. I am not sure if this is the correct way to do it, and would love the python gurus out there to comment on it.

- I have included awesome* diagrams of my state transition diagram and how the arduino is wired to the servos

- The Arduino .C code is included, just rename it to .pde for use with the UI.

Special thanks to Graham Thompson for helping out with the callback functions. I won't have known those existed!!!

Regards,

Alvin

*this is sarcasm.

servoControl_MK02.otl

post-1921-130116159107_thumb.jpg

post-1921-130116159813_thumb.jpg

ServoSerialComms_004.txt

Link to comment
Share on other sites

Found your great video on Makezine today (congrats on that). I've never heard of Houdini, but I was amazed by the video. I just have one question, can the same setup be used to replay a series of claw positions? Rephrased: can you create a rendered animation in Houdini and have each timestep of the servo data sent to the claw in real time? Could it work if it wasn't in real time (I'm thinking maybe a script or really slowed down animation that can just send it frame by frame automagically)?

I'm pretty sure Houdini will be my next software tool to learn because of your video.

Cheers,

Cole

Link to comment
Share on other sites

Found your great video on Makezine today (congrats on that). I've never heard of Houdini, but I was amazed by the video. I just have one question, can the same setup be used to replay a series of claw positions? Rephrased: can you create a rendered animation in Houdini and have each timestep of the servo data sent to the claw in real time? Could it work if it wasn't in real time (I'm thinking maybe a script or really slowed down animation that can just send it frame by frame automagically)?

I'm pretty sure Houdini will be my next software tool to learn because of your video.

Cheers,

Cole

Oh wow, didn't realize it was posted on make! In reply to your question, yes, it is definitely possible, simply by either keyframing the values of the parameters (if you need really detailed control) or some procedural input (noise function, or reaction to something etc), it can put the claw into pre-defined positions.

One thing you may want to consider is servo speed/torque versus the speed of the animation - if it's changing too fast the servo may not be able to keep up. Also, what is "animation" and how heavy is this? Many ways to do it - houdini's not a 3d/effect application - it's a 3d operating system :3 You can definitely create animation of all sorts from characters to collapsing bridges and use that data to drive the arduino, and from there, maybe with a little tinkering, a proton canon. But I digress.

Let me know if I can help further. My next project is using ADXL335 data, however I'm a little stuck at data acquisition - digital filtering, convolution of signals and all that jazz. Houdini is a great package to learn, and the community here is awesome :D

Regards,

Alvin

Link to comment
Share on other sites

  • 2 weeks later...

Great work Alvin!

I've been working on an motorized remote head for use on a jib crane, that I wanted to be controllable from Houdini via Arduino.

Your OTL and Graham's callback functions are a huge help!

Here's my build journal: http://johnpilgrim.net/MoCo/

I've got the gwServoControlMk2 OTL up and running, and can view the serial stream on an LCD connected to the Arduino.

I have one issue:

Houdini sends serial data to the Arduino when I scrub the values in the parameter pane.

But if I keyframe the same rx2 ry2 rz2 parameters and then play the animation, Houdini doesn't send any serial data.

What other events besides hou.nodeEventType.ParmTupleChanged would need to be included?

Or, better yet, is there a way to simply send the data at every frame?

Thanks for your help on this and for the huge head start with the script,

John

PS: Hou 11.0.636 on Mac OS X 10.5.8

Edited by John Pilgrim
Link to comment
Share on other sites

I have one issue:

Houdini sends serial data to the Arduino when I scrub the values in the parameter pane.

But if I keyframe the same rx2 ry2 rz2 parameters and then play the animation, Houdini doesn't send any serial data.

What other events besides hou.nodeEventType.ParmTupleChanged would need to be included?

ParmTupleChanged is only called upon interactive parameter changes. If you want also want to get called when the frame changes, then I recommend using a Python SOP (in a separate displayed Object) instead. As the Python SOP's input, use an Object Merge ("Transform" parameter set to "Into This Object") that merges a dummy Null from inside each of your objects. Now, whenever any of those objects need to cook, your Python SOP should also recook as well. I don't have Houdini in front of me but at worst, you might need to have it generate a single point as I forget whether the viewer will recook SOPs that contain no geometry.

Link to comment
Share on other sites

ParmTupleChanged is only called upon interactive parameter changes. If you want also want to get called when the frame changes, then I recommend using a Python SOP (in a separate displayed Object) instead. As the Python SOP's input, use an Object Merge ("Transform" parameter set to "Into This Object") that merges a dummy Null from inside each of your objects. Now, whenever any of those objects need to cook, your Python SOP should also recook as well. I don't have Houdini in front of me but at worst, you might need to have it generate a single point as I forget whether the viewer will recook SOPs that contain no geometry.

So perhaps he should dump all his parameters onto detail attributes and then the Python SOP's only duty would be to send those to the Arduino?

Link to comment
Share on other sites

*doh* Just tested this, yup doesn't work with keyframes. Edward, Jason, thanks for the hints! I'll see what I can do to make it work for keyframes. I'm thinking maybe putting the serial code data into a function inside the hda, and then when either a python sop updates per frame, or the callback function works, this function can be called to update the servos. I need to test it out, will be slow - it's kinda crunch time where I'm at ;-)

@John: That setup looks amazing. One of my long term hobby goals is camera stabilization - hence my purchase of the 2 dof pan/tilt mechnism :) All the best to your project!

Regards,

Alvin

Link to comment
Share on other sites

Thanks for the input everyone!

I followed Edward's suggestion re Python SOP and Object Merge nodes and then used hou.ch to access the parameter data I wanted to send to the Arduino.

(Jason, could you detail a bit more about how you'd set up the detail attributes.)

The following transmits the data to the Arduino LCD, in an easier to read but bandwidth wasting string format.

# from the Code tab of the Python SOP

import __main__

geo = hou.pwd().geometry()

__main__.ser.write(chr(2)+"frm"+str(int(hou.frame()))+" ry2="+str(round(hou.ch("../../ry2"),3)))

# Note: "../../ry2" resolves to "/obj/gwServoControlMk2/ry2"

2011Apr12_P1140132.jpg

I also had to add an On Loaded script to the OTL (with the same content as the On Created) in order to open the serial connection when opening a saved hip file that already contained the OTL.

Note that the Python SOP cooks and sends the data both when playing the animation as well as when dragging the sliders in the param pane, so the ParmTupleChanged callback becomes redundant.

John

Link to comment
Share on other sites

Hi John! You got it working? Great!

I got mine working too, but it's not using a python SOP, rather just using a Script SOP set to time dependant and calling the functions inside hdaModule()

I tested it this time (well only on the claw ;-)) but it definitely responds to keyframes as well as the sliders. Updated OTL attached!

That was fun!

Alvin

servoControl_MK03.otl

Link to comment
Share on other sites

Thanks for posting the files guys. Even though I don't have one of these, after seeing what you guys were doing, I thought I'd take a look at solving the problem in a bit of a different way.

To get around worrying about cooking and updating I created a Python Object asset that mimics a servo and then gave it various parameters to control the axis of rotation, port number, actual rotation, input and output angle ranges and the pivot. Like the geo objects they can easily be chained together. The cook code of this object builds the data and sends it for each servo separately and easily every time the object is cooked. Since the rotation is linked to the channels/handles on the top asset, no matter what happens the objects will always cook when needed and therefor update the physical model without the need for callbacks. The code also is responsible for transforming the Houdini objects and even enforces the input range restrictions.

All the code dealing with opening and closing serial connections is also handled by the servo assets using PreFirstCreate and PostLastDelete handlers calling to some simple functions in the PythonModule. The pre one opens a connection and assigns it to hou.session. The post closes any connection it finds on hou.session and removes references to it after the last one is deleted. All the scripts from the original asset have been removed since the servos can handle all that themselves.

Since I don't have one to test I'm curious if the attached files would technically even work. I did my best to do something that should work in theory but no way to test. If anyone is brave enough to test I'd be most appreciative to know if this approach works.

Edit: If you do try it out you'll need to uncomment lines in the Code tab and PythonModule to have it work. In theory anyway.

servoControl_MK03.otl

servo_test.hipnc

object_servo.otl

Edited by graham
Link to comment
Share on other sites

  • 4 weeks later...

That is excellent. Thanks for sharing the work here! I haven't thought about using Houdini with an Arduino before, so many possibilities. Also good to see other people using the Arduino platform. This was my last project.

http://www.whenpicsfly.com/tool/arduino/highSpeedShutterRelease/v1.1_overview.jpg

http://www.whenpicsfly.com/tool/arduino/highSpeedShutterRelease/v1.1_breadboard.jpg

http://www.whenpicsfly.com/tool/arduino/highSpeedShutterRelease/bulbTest1.jpg

http://www.whenpicsfly.com/tool/arduino/highSpeedShutterRelease/bulbTest2.jpg

http://www.whenpicsfly.com/tool/arduino/highSpeedShutterRelease/bulbTest3.jpg

I will download the files that have been posted previously and check them out after work. :ph34r:

Edited by lukeiamyourfather
Link to comment
Share on other sites

  • 4 weeks later...

It works!

I've also attached the OTL with uncommented code that works for me.

Sesi - you rule :3

Quote from the video: "You guys are so awesome" :P

In my turn, I can really, not sure if 'enjoy' is the right word or 'appreciate it', when other people get really exited about something :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...