F#, Kinect and a little LegoNXT

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...

Lego KinNXT

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

image

image

image

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:

Follow the Discussion

Comments Closed

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.