NXT Workflow Sample
This sample demonstrates how you can use Windows Workflow Foundation to remote control a Lego (R) Mindstorms (R) NXT robot through a Bluetooth connection. It includes a console driver program, as well as a Winforms based application that hosts the Workflow designer. The designer hosted version is based on the excellent MSDN hosting example by Vihang Dalal found at
http://msdn2.microsoft.com/en-us/library/aa480213.aspx. The bluetooth communication uses a wrapper called NXT# written by Bram Fokke at
http://nxtsharp.fokke.net.
Screenshot of the controller application:
New in version 1.0.0.1 There is a while activity that loops until a sensor crosses a threshold. For example, this program enables a robot to find its way out of a room using a touch sensor attached to its front. Whenever it touches an obstruction it backs up, turns and goes forward again.
The NXT robot I used for this application:
This sample was developed using Visual Studio 2008 and targets the .NET 3.5 framework, although with a few modifications it could easily be converted back to a .NET 3.0 / Visual Studio 2005 project if required.
It was developed simply to learn how to work with Windows Workflow Foundation, and as such, is only a proof of concept,
and incomplete. But the basic idea could be expanded upon by someone with more time.
The NxtActivities project currently has only two workflow activities to control motor ports. Eventually this could be expanded to include input activities to read and react to the state of the various input sensors, but this part of the sample remains to be completed.
The two activities are:
- Motor - Control one output port (example: run motor A for 2 seconds on power 100)
- Move - Control two output ports in sync (example: move a robot with two drive motors in a straight line for 10 seconds on power 100)
Prerequisites
This project uses the excellent NXT# which can be found here
http://nxtsharp.fokke.net In order to build it you must first download
NxtSharp.binaries.zip from the download section.and place the latest version of these two
assemblies in the lib folder:
- Bram.Utilities.dll
- Bram.NxtSharp.dll
This sample was developed using version 0.3 of NXT#.
Contents
- lib - External dependencies, place the two NXT# assemblies here
- NxtActivities - The activities library containing the two activities, and various workflow helper classes.
- NxtController - The Winform application that hosts the workflow designer
- NxtControllerConsole - The sample console controller
- WorkflowDesignerControl - A control that simplifies the designer hosting
Instructions
Console version:
- Open NxtWorkflow.sln in Visual Studio 2008
- Connect your PC to your NXT through Bluetooth, note the COM port used, (default is COM8)
- Set NxtControllerConsole as your startup project
- In the NxtControllerConsole project, modify this line in Program.cs to use the correct COM port NxtWorkflowRunner runner = new NxtWorkflowRunner("COM8");
- Inspect Workflow1.cs to make sure all of the motor ports are correct for your robot.
- Run.
Winform version:
- Open NxtWorkflow.sln in Visual Studio 2008
- Connect your PC to your NXT through Bluetooth, note the COM port used, (default is COM8)
- Set NxtController as your startup project
- Run the app, use the Tools | Options menu to set the COM port
- Use the File | Open... menu to open ....\NxtController\Workflows\Workflow3.xoml
- Inspect the workflow to make sure all of the motor ports are correct for your robot.
- Press the green play button on the toolbar.
--Loren Halvorson
My Blog can be found at
http://weblogs.asp.net/lorenh