F#, Kinect and a little LegoNXT
- Posted: Jan 06, 2012 at 6:00 AM
- 5,839 Views
How can mixing F#, the Kinect for Windows SDK and LegoNXT not be cool? This might give you a few ideas to play with over the weekend...
I've been having some fun playing with the Kinect SDK and the Lego NXT kit. The protocol to talk to the Lego brick over Bluetooth is pretty straight forward. Below is a little F# module for most of the basic commands
Using this along with Kinect skeletal tracking makes for a quick, pretty cool little project with the boys!
Project Information URL: http://blogs.msdn.com/b/ashleyf/archive/2011/12/23/lego-kinnxt.aspx
open LegoBot
open Microsoft.Research.Kinect.Nui
printfn "Connecting..."
let bot = new LegoBot "COM3"
printfn "Initializing Kinect..."
if Runtime.Kinects.Count = 0 then failwith "Kinect missing"
let kinect = Runtime.Kinects.Item 0
kinect.Initialize(RuntimeOptions.UseDepth ||| RuntimeOptions.UseSkeletalTracking)
kinect.SkeletonEngine.IsEnabled <- true
kinect.SkeletonEngine.TransformSmooth <- true
kinect.SkeletonFrameReady.Add(fun frame ->
let drive port position =
let power = position * 2.f * 100.f |> int
bot.SetOutputState power port OutputMode.MotorOn RegulationMode.Idle 0 RunState.Running 0ul
let joints = frame.SkeletonFrame.Skeletons.[0].Joints
let left = joints.[JointID.HandLeft]
let right = joints.[JointID.HandRight]
printfn "Left: %A Right %A" left right
drive 0 left.Position.Y
drive 2 right.Position.Y)
System.Console.ReadLine() |> ignore
bot.Disconnect()
Contact Information:
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?