There's a request from the Microsoft Robotics Studio Team to post my code for controlling the robot using Microsoft Robotics Studio (MSRS), Lego Mindstorms NXT, and Bluetooth.
Here are the steps:
1. Buy a Nintendo Wii gamepad (Wiimote) if you don't have a Wii. It will cost you between $40-$70.
2. Buy a Bluetooth dongle with Cambridge Silicon Radio (CSR) or Integrated System Solution Corp (ISSC) radios embedded. This is because not all Bluetooth dongles can communicate with the unique Wiimote. My USB Bluetooth dongle brand is Billionton, so if you have Billionton, rest assured you have CSR radio.
3. Download a trial copy of ISV BlueSoleil here: http://www.bluesoleil.com/products/index.asp?topic=bluesoleil_v5. This is the software stack that works well with the Wiimote. And this software stack only works with CSR-based and ISSC-based radios.
4. Download Microsoft Robotics Studio 1.5.
5. Download Brian Peek's .NET Wiimote Library from CodePlex here.
6. Build the .NET Wiimote Library. Copy the *.dll from \WiimoteMSRS\bin\service to \Microsoft Robotics Studio (1.5)\bin
7. Create a copy of the folder \Microsoft Robotics Studio (1.5)\samples\RoboticsTutorials\Tutorial4\CSharp and rename the duplicate folder "WiimoteTutorial4"
8. Open the "WiimoteTutorial4" solution in Visual Studio. Add a Reference to \Microsoft Robotics Studio (1.5)\bin\Wiimote.Y2007.M06.Proxy.dll
9. Open the file "RoboticsTutorial4.cs". Add a using statement on the top:
1
2
using wiimote = WiimoteLib.Proxy;
Add the following code to the Class member declarations area (after "private drive.DriveOperations _driveNotify = new drive.DriveOperations();")
1
2
3
4
5
6
7
8
9
10
11
12
13
[Partner(
"Wiimote", Contract = wiimote.Contract.Id

entifier,
CreationPolicy = PartnerCreationPolicy.UseExisting

OrCreate)]
private wiimote.WiimoteOperations _wiimotePort = n

ew wiimote.WiimoteOperations();
private wiimote.WiimoteState _stateLast =
new wiim

ote.WiimoteState();
10. Add the following code to the end of the Start() method:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
wiimote.WiimoteOperations _wiimoteNotify =
new wii

mote.WiimoteOperations();
Activate(Arbiter.Receive<wiimote.WiimoteChanged>(t

rue, _wiimoteNotify, WiimoteChangedHandler));
Arbiter.Choice(
_wiimotePort.Subscribe(_wiimoteNotify),
delegate(SubscribeResponseType response) { Log

Info(
"Subscribed to Wiimote service"); },
delegate(Fault fault) { LogError(fault); }
);
11. Add the Wiimote Handler method after Start() method:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
private void WiimoteChangedHandler(wiimote.Wiimote

Changed msg)
{
wiimote.WiimoteState state = msg.Body;
if (state.AccelState.Y > 0.5f)
_mainPort.Post(
new Forward());
else if (state.AccelState.Y < -0.5f)
_mainPort.Post(
new Backward());
if (state.AccelState.X < -0.5f)
_mainPort.Post(
new TurnLeft());
else if (state.AccelState.X > 0.5f)
_mainPort.Post(
new TurnRight());
if (state.ButtonState.A)
_mainPort.Post(
new Stop());
if (state.AccelState.Y <= 0.5f &&
state.AccelState.Y >= -0.5f &&
state.AccelState.X <= 0.5f &&
state.AccelState.X >= -0.5f)
_mainPort.Post(
new Stop());
_stateLast = (wiimote.WiimoteState)state.Clone

();
}
12. Right-click the Project Properties. Under the Debug tab, edit the Command Line Arguments to:
-p:50000 -t:50001
-m:"samples/Config/Wiimote.manifest.xml"
-m:"Samples\Config\RoboticsTutorial4.manifest.xml"
-m:"samples\config\LEGO.NXT.Tribot.manifest.xml"
13. Debug your app and control your robot's destiny with your Wiimote :)
If you're too lazy to type and understand all the above codes, download my project file at the end of this post (available below as post attachment).