The Code for Controlling Robot using Wiimote & MS Robotics Studio

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 with wiimote service
[Partner("Wiimote", Contract = wiimote.Contract.Idwrap glyph
entifier,
CreationPolicy = PartnerCreationPolicy.UseExistingwrap glyph
OrCreate)]
private wiimote.WiimoteOperations _wiimotePort = nwrap glyph
ew wiimote.WiimoteOperations();

// maintain the previous state of the wiimote
private wiimote.WiimoteState _stateLast = new wiimwrap glyph
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 
// create an internal notification port
wiimote.WiimoteOperations _wiimoteNotify = new wiiwrap glyph
mote.WiimoteOperations();

// setup to receive WiimoteChanged msgs
Activate(Arbiter.Receive<wiimote.WiimoteChanged>(twrap glyph
rue, _wiimoteNotify, WiimoteChangedHandler));

// subscribe to the Wiimote
Arbiter.Choice(
    _wiimotePort.Subscribe(_wiimoteNotify),
    delegate(SubscribeResponseType response) { Logwrap glyph
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.Wiimotewrap glyph
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());

    // based on threshold, move left/right
    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());

    // cradled position - 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.Clonewrap glyph
();

}

 

 

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

Share this post: | | | |
Attachment: WiimoteTut4.zip
Published Tuesday, November 06, 2007 7:19 AM by zeddy
Filed under:

Comments

# re: The Code for Controlling Robot using Wiimote & MS Robotics Studio

Sunday, December 30, 2007 10:33 PM by paulo

Where is the Wiimote.manifest.xml file?

# re: The Code for Controlling Robot using Wiimote & MS Robotics Studio

Sunday, March 29, 2009 1:10 AM by Miguel angel

Hello,

When I do all the steps than you tell, and finally, I try to debug the projet, appears the next errors:

Error 1 The OutputPath property is not set for this project.  Please check to make sure that you have specified a valid Configuration/Platform combination.  Configuration='Debug'  Platform='MCD' RoboticsTutorial4

Error 2 El comando ""C:\Microsoft Robotics Studio (1.5)\bin\DssProxy.exe" /dll:"C:\Microsoft Robotics Studio (1.5)\bin\RoboticsTutorial4.Y2006.M06.dll" /proxyprojectpath:"C:\Microsoft Robotics Studio (1.5)\samples\RoboticsTutorials\Tutorial4\WiimoteTutorial4\Proxy " /keyfile:"C:\Microsoft Robotics Studio (1.5)\samples\mrisamples.snk"   /binpath:". " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) " /referencepath:"%(RootDir)%(Directory) "

" terminó con el código 20. RoboticsTutorial4

Can you explain me, if I do something bad.

Thank you very much.

Miguel.

Powered by Community Server (Commercial Edition), by Telligent Systems