F#, Kinect and a little LegoNXT
- Posted: Jan 06, 2012 at 6:00AM
- 5,986 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..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()