How to Create and Simulate a Microsoft Robotics Studio Service

How to Create and Simulate a Microsoft Robotics Studio Service

This will show you how C # and the Microsoft Robotics Studio Manifest Editor are used to create a service and run it in a simulation environment.

Install the Microsoft Robotic Studio.

Go to Microsoft Download

Search for robotics

Download Microsoft Robotics Studio 1.5

Download Runtime and Tools Update for Microsoft Robotics Studio (1.5) Nov 2007

Install both of them

Create a new blank service

Create a blank service from Start, Programs, Microsoft Robotics Studio (1.5)

Run MSRS Command Prompt

Type ‘md My’ to create a new directory for your projects

Type ‘cd My’ to move into that directory

Type ‘dssnewservice /service:Simplest’

Add some basic handling to your project so we will reference a drive partner

Type ‘cd Simplest’ to move into your new services’ directory

Type ‘Simplest.sln’ to open your service in Visual Studio C#

Open the Solution Explorer (ctrl-w, s)

Add a reference to RoboticsCommon.proxy

Open the file Simplest.cs from the Solution Explorer

Add a new using statement at the top ‘using drive = Microsoft.Robotics.Services.Drive.Proxy;’

Add a partner reference below _mainPort declaration ‘[Partner(“drive”, Contract=drive.Contract.Identifier, CreationPolicy=PartnerCreationPolicy.UsePartnerListEntry)]’

Add a port for this partner just below the [Service…] line you just added ‘private drive.DriveOperations _drivePort = new drive.DriveOperations();’

Add another port just below that one ‘private drive.DriveOperations _driveNotify = new drive.DriveOperations();’

This port will be what we use to actually handle notifications that are sent to us. It allows the _drivePort to be free as often as possible

Now let’s listen to this partners notification messages

We want the _driveNotify port to get messages sent to the _drivePort. So, add ‘_drivePort.Subscribe(_driveNotify);’ below ‘base.Start();’ in the Start function.

Now we need to add a function to listen to messages that come in on the _driveNotify port. The code we add is complex for the simple concept we want to achieve. But it allows the runtime to synchronize the processing better (from what I understand of it at least)

Code Block 1

We made reference in that block of code to a function named DriveUpdateHandler. Here’s the implementation. All it does is to set the robot into a wide circle. This is NOT the best way to do this. But it gives you a quick understanding of how everything gets wired up.

Code Block 2

Build the project. It should compile and build just fine.

Now that we’re wired up with the partner so it will listen for the update message we want to connect to the simulation environment. We didn’t specifically state that we’re connecting to the simulation environment in our code. So we have to do it somewhere else. That place is in the manifest file. The one for this project is called Simplest.manifest.xml. We want to open it in the manifest editor.

From Start, Programs, Microsoft Robotics Studio (1.5) run Microsoft Dss Manifest Editor.

Click File, Open, choose your manifest file C:\Microsoft Robotics Studio (1.5)\My\Simplest\Simplest.manifest.xml

Find the Simulation Engine service from the list of services on the left. Add it to your manifest.

With the SimulationEngine selected IN your manifest, Click the Import Initial State button in the properties window.

Change to the samples\config folder (C:\Microsoft Robotics Studio (1.5)\samples\Config)

Change the file type to Any XML File

Choose iRobot.Create.Simulation.xml

This will load a bunch of standard entities (blocks and such) as well as the iRobot Create entity. It is named IRobotCreateMotorBase

Now we choose the simplest service in the manifest editor

Then find Simulated Generic Differential Drive in the list of services on the left

Add it to the manifest diagram by dragging it ON TOP OF the simplest drive entry in the manifest. This will do two things. Add the SimulatedGenericDifferentialDrive service AND associate it with the simplest drive service. This is why we chose PartnerCreationPolicy.UsePartnerListEntry in the [Partner…] declaration in our code.

The only thing left is to associate the SimulatedGenericDifferentialDrive service to an actual entity in the SimulationEngine configuration. So, click on the Entity reference under SimulatedDifferentialDrive and set the Simulation Entity property to ‘http://localhost/IRobotCreateMotorBase’.

Push F5. I am by no means an expert. It has taken me a couple weeks to figure this stuff out. And since these parts finally clicked I decided to post them for everyone’s benefit.

Creative Commons License

Source- wikihow

Leave a Reply