CONTACT
US
2018-04-20 Viewed: 719 Tags:

Microsoft Robotics Studio Tutorials

Microsoft Robotics Studio Tutorials

 

MRS provides a reusable design framework for writing services. Users can write services for a common hardware specification and then reuse it on different robot hardware platforms.

 

 

In this tutorial, you will learn to write a service that is associated with a virtual hardware service that has a basic definition, and then, based on a configuration file (description file), binds to specific implementations of these hardware services at run time. on. This tutorial will implement a basic random walk behavior, which is described as follows:

n If the front contact sensor is triggered, the robot rotates randomly and provides equal negative power to the two wheels of the motor (motor reversed, corresponding to obstacles encountered ahead)

n If the rear contact sensor is triggered, the robot rotates randomly and provides equal forward power for the two wheels of the motor (the motor rotates in the forward direction, corresponding to obstacles in the rear).

 

This very primitive behavior will cause the wheeled robot to hit the obstacle and turn it. More intelligent, more advanced collaborative services, see Robotics Tutorial 5 and the Explorer Service.

 

In this tutorial you will learn:

1. Understand the general definition of contact sensors and differentials, and how to use these definitions

2, Learn how to issue advanced instructions to the driver service

3, use contact sensor event notification to trigger a "roaming" behavior

4. Learn how to write a description file for a specific hardware specification service that implements the basic common definitions used in this tutorial.

premise

hardware

This tutorial is based on the following robot hardware platforms, and the SDK provides services for these hardware. You can also use hardware that provides equivalent services. Among the hardware platforms listed below, the physical configuration you need includes: At least one contact sensor, two-wheeled differential/brake with two motors installed.

n LEGO? MINDSTORMS? RCX

n LEGO? MINDSTORMS? NXT

n fischertechnik?

n If you use simulation services, you need to meet the simulation requirements of the graphics accelerator card

 

software

This tutorial uses C#, which you can develop using Visual Studio 2005 Lite, Standard, Professional, and Team Edition software.

 

Start

In this tutorial we will not create the service but will use the service that has been created in the samples/RoboticsTutorials/Tutorial3/CSharp directory. Open RoboticsTutorial3.csproj in the development environment. If you are using Visual studio, you will see the following in the solution browser in the VS window:

Step 1 Establish Associations on the Virtual Device

At the beginning of RoboticsTutorial3.cs, add the following using statement.

 

Using Microsoft.Ccr.Core;

Using Microsoft.Dss.Core;

Using Microsoft.Dss.Core.Attributes;

Using Microsoft.Dss.ServiceModel.Wsap;

Using Microsoft.Dss.ServiceModel.WsapServiceBase;

Using System;

Using System.Collections.Generic;

Using System.Security.Permissions;

Using xml = System.Xml;

Using contactsensor = Microsoft.Robotics.Services.ContactSensor.Proxy;

Using drive = Microsoft.Robotics.Services.Drive.Proxy;

Using motor = Microsoft.Robotics.Services.Motor.Proxy;

 

The types in these namespaces are implemented in RoboticsCommon.Proxy.Dll and the dynamic library is added as a reference in our service. At the same time, use the following associations in the service class definition.

[Contract(Contract.Namespace)]

    [PermissionSet(SecurityAction.PermitOnly, Name="Execution")]

    Public class Tutorial3 : WsapServiceBase

    {

 

        [Partner("Bumper",

            Contract = contactsensor.Contract.Namespace,

            CreationPolicy = PartnerCreationPolicy.UseExisting)]

        contactsensor.ContactSensorArrayOperations _contactSensorPort = new contactsensor.ContactSensorArrayOperations();

 

        [Partner("Drive",

            Contract = drive.Contract.Namespace,

            CreationPolicy = PartnerCreationPolicy.UseExisting)]

        drive.DriveOperations _drivePort = new drive.DriveOperations();

 

        // target port for bumper notifications

        contactsensor.ContactSensorArrayOperations _contactNotificationPort = new contactsensor.ContactSensorArrayOperations();

 

The difference with the previous association statement is the value of PartnerCreationPolicy:

 

CreationPolicy = PartnerCreationPolicy.UseExisting

 

Since the virtual service definition is for generic touch sensors and drivers, there is no service implementation needed to create and bind at runtime. Instead, we rely on some of the services that have been enabled and implement touch sensor contracts (such as the LegoRCX Bumper service) as its alternate contract. The service that implements the preliminary contract will appear twice in the service instance directory, essentially representing two different services. Most of the sample services provided in the SDK implement a preliminary contract.

 

Step 2 Using Contact Sensors to Trigger Behavior

To start a roaming behavior, one of the touch sensors must be triggered first. In order to receive sensor event notifications, you need to subscribe to the contact sensor port and provide an event notification destination port. The relevant code snippet is highlighted as follows:

 

   [Contract(Contract.Namespace)]

    [PermissionSet(SecurityAction.PermitOnly, Name="Execution")]

    Public class Tutorial3 : WsapServiceBase

    {

 

        [Partner("Bumper",

            Contract = contactsensor.Contract.Namespace,

            CreationPolicy = PartnerCreationPolicy.UseExisting)]

        contactsensor.ContactSensorArrayOperations _contactSensorPort = new contactsensor.ContactSensorArrayOperations();

 

        [Partner("Drive",

            Contract = drive.Contract.Namespace,

            CreationPolicy = PartnerCreationPolicy.UseExisting)]

        drive.DriveOperations _drivePort = new drive.DriveOperations();

 

        // target port for bumper notifications

        contactsensor.ContactSensorArrayOperations _contactNotificationPort = new contactsensor.ContactSensorArrayOperations();

 

        [ServicePort("/RoboticsTutorial3", AllowMultipleInstances=false)]

        Private RoboticsTutorial3Operations _mainPort = new RoboticsTutorial3Operations();

        Public Tutorial3(WsapServiceCreationPort creationPort) :

                Base(creationPort)

        {

                  CreateSuccess();

        }

        Protected override void Start()

        {

 

            // Listen on the main port for requests and call the appropriate handler.

            ActivateWsapOperationHandlers();

 

            // Publish the service to the local Node Directory

            DirectoryInsert();

 

            // display HTTP service Uri

            LogInfo(LogGroups.Activation, "Service uri: " + base.FindServiceAliasFromScheme(Uri.UriSchemeHttp));

 

            SubscribeToBumperSensors();

        }

 

        Void SubscribeToBumperSensors()

        {

            _contactSensorPort.Subscribe(_contactNotificationPort);

 

            // attach handler to update notification on bumpers

            Activate(Arbiter.Receive<contactsensor.Replace>(true, _contactNotificationPort, BumperNotificationHandler));

        }

 

Add the SubscribeToBumperSensors method in the service's Start method. This method subscribes to the service bound to _contactSensorPort. After that, activate the event handler on the event port. Depending on which contact sensor is pressed, the processor triggers two different processes. The TurnAndGoBackwards method is executed when the front sensor is pressed and the TurnAndGoForward method is executed when the rear sensor is pressed.

 

    Void BumperNotificationHan




More blogs    


所有评论仅代表网友意见