This is a tutorial I put together which shows you how to programmatically create a remote control services for the Lego Mindstorms NXT. It is based on the video’s available on the Microsoft Robotics Studio Website.
Open a new MSRS Prompt.
Run the following command:
This will create a new Visual Studio Project (called DialogDrive).
Open the project in Visual Studio from the MSRS Prompt:
Once the project has opened, right click on Resources and select Add Reference, adding references to:
a) Robotics.Common.Proxy
b) DirectionDialog.Y2006.Proxy
In the Visual Studio Solution Explorer open dialogdrive.cs
Add using statements below existing ones:
using drive = Microsoft.Robotics.Services.Drive.Proxy;
Dialog & drive make it simpler to reference the libraries.
Scroll to the Service Class
Add 2 new services ports to communicate with our other services by adding (at the very beginning of class):
private drive.DriveOperations _drivePort = new drive.DriveOperations();
Now partner ports to services by adding (above each port created in the above step):
…_dialogPort code from step above…
The CreateAlways creation policy tells the port to always create the service that it will connect to.
[Partner(“drive”, Contract = drive.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExisitng]
…_drivePort code from step above…
Now in the Start() method add:
SubscribeToDirectionDialog();
Add the SubscribeToDirectionDialog() method stubs using intellisense.
Add port to listen for events in the new method:
Subscribe to notificaitons from _dialogPort by adding:
Tell our service/port what to do when a message is recieved by adding:
Arbiter.Recieve(true,dialogNotifications, DialogButtonPressHandler),
Arbiter.Recieve(true, dialogNotifications, DialogButtonReleaseHandler)
);
Now create the handler methods:
LogInfo(LogGroups.Console, buttonPress.Body.Name + ” Pressed”); // Logs output to console Switch (buttonPress.body.Name) {
case “Forwards”:
_drivePort.SetDrivePower(new drive.SetDrivePowerRequest(1.0,1.0));
break;
case “Backwards”:
_drivePort.SetDrivePower(new drive.SetDrivePowerRequest(-1.0,-1.0));
break;
case “Left”:
_drivePort.SetDrivePower(new drive.SetDrivePowerRequest(1.0,-1.0));
break;
case “Right”:
_drivePort.SetDrivePower(new drive.SetDrivePowerRequest(-1.0,1.0));
break;
case “Stop”:
_drivePort.SetDrivePower(new drive.SetDrivePowerRequest(0.0,0.0));
break;
}
}
LogInfo(LogGroups.Console, buttonRelease.Body.Name + ” Released”); // Logs output to console
_drivePort.SetDrivePower(new drive.SetDrivePowerRequest(0.0,0.0));
}
Now compile our project (Press F5).
Now we can run our project.
However we need to also start the services needed by our service on our dsshost node. So run the following in the MSRS Prompt:
The following starts the tribot service and our service. Note that the dialog service is started by our service automatically as we specified in the partnering directives.
The NXT config page will popup as it will need to be configured