Wednesday, August 17, 2016

Dancing Robots!! (...again)

This is QuadraPi, which is a Pi 2B upon which I've mounted a camera with a 2-axis motor mount (I got metal gear micro towers this time because I keep wearing out the plastic-geared cheapies that you can get for like $2 each.  These cost about $10 a piece but perform a lot better and hold up over time).  

I've been playing with OpenCV (at about 8 FPS) on the pi with this camera and working on some motion tracking stuff using the motorized mount (more on that some other time).  So here it is doing some choreographed moves:

(Edit: moved video to YouTube since Blogger seems to keep losing it)







So, big deal, more scripted servo stuff.  The reason this demo is cool though is that the script is running on another computer (my laptop) and controlling the camera in near-real time.

This is the result of a project that I've had in the back of my head for some time but just recently got working.  Using some of the same network code I wrote for OliWeb, I've built a much leaner interface using just sockets and and simple TCL-inspired command language.  The project is called ControlSocket and it's now working and available out on GitHub.  

The main reason I wanted this was to allow for tighter communications and control of robo-stuff than what would be possible using web service round-trips.  Now that I've got the back end working, the next step is to tie in control elements running on my phone / tablet (steering the 2-axis camera using the phone's accelerometer, for instance, or choreographing light displays with swipe gestures, just for instance).

I have more testing to do to measure round-trip latency and response time, which of course will be network-depedent.  You can see from the video though that the choreography of the camera motion as scripted from the laptop is pretty tight.

For the client side of the solution, I just wrote a text file consisting of a bunch of motor commands and piped it through telnet.  This makes for a really easy way to do remote scripting of *whatever* on your pi project remotely.  

Pi is not really very good at PWM (arduino is much, much better for this).  One thing I've done in the past is to connect a teensy 3.1 board via serial to the pi and let it do the lifting on all the PWM stuff with simple commands coming from the pi to tell it what duty cycle to put on which pin.  That "pi-duino" approach works pretty well.  The motor control you see here is done via the gpio_pwm command line utility that I built a while ago (software PWM pulse train generation from the command line - works just fine for steering servos or what have you if you don't need ultra-precise control or continuous PWM signals going to the hardware).  I have it on the to-do list to break this out into its own project for easier inclusion in other projects, but you can find it in the OliWeb distro on Git for the time being.

More updates to follow once I've made some progress on the front end and have more razzle-dazzle to show off.

Oh, and: who's that guy next to QuadraPi?  That's flipper-bot, a teensy walker that also uses dual-servo action and is RC-controlled.  I'll post on that guy later.  


No comments:

Post a Comment