Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Задани на лабораторные работы. ПРК / Professional Microsoft Robotics Developer Studio

.pdf
Скачиваний:
128
Добавлен:
20.04.2015
Размер:
16.82 Mб
Скачать

www.it-ebooks.info

Chapter 3: Decentralized Software Services (DSS)

Figure 3-6

In the drop-down list beside each service, you can find a list of all of the manifests that DSS found that refer to the service. You can either select one of these manifests or just leave the drop-down set on <<Start without manifest>> and click the Create button to start a new instance of the service. If you have a web camera, make sure that it is plugged into your PC and click the Create button beside the Webcam service. (Don’t select a manifest.)

The Service Directory

A new Webcam service will be started on your computer. You can verify this by selecting Service Directory from the menu (see Figure 3-7).

103

www.it-ebooks.info

Part I: Robotics Developer Studio Fundamentals

Figure 3-7

Every DSS node has a service directory that lists the currently running services. Two Webcam services are listed (the second one is cut off a little at the bottom of the window in Figure 3-7) because there is a generic Webcam contract and the service implements both the generic contract and its own contract.

Notice that there are several other services as well, such as the manifest loader, console output, and the Control Panel.

Click the Webcam service in the Service Instance list to see what the output from the service looks like. An example is shown in Figure 3-8. If you look carefully in the address bar, you might be able to see that the URL is http://localhost:50000/webcam/c7354581-c28f-4b4c-b419-d5b7ea06aab9. Before you panic, assuming you have to know these magic numbers, it should be pointed out that they change every time you run a service — they are only there to make service URIs unique. The main point is that the Webcam service can be accessed just by appending its name to the end of the DSS node URL; the numbers are not necessary unless there are multiple instances of a service.

104

www.it-ebooks.info

Chapter 3: Decentralized Software Services (DSS)

Figure 3-8

The Webcam service formats its output when you make a HttpGet request to the service and presents it as a Web Form. The form enables you to set the camera parameters, including refresh interval, display

format, and capture format (image resolution). You can also select from several cameras if you have more than one connected to your PC. Finally, you can run the viewer continuously or refresh the image manually using the Start, Stop, and Refresh buttons. This is an advanced example of a web interface to

a service.

The Debug and Trace Messages Page

Select Debug and Trace Messages from the menu. You should see something like what is shown in Figure 3-9.

105

www.it-ebooks.info

Part I: Robotics Developer Studio Fundamentals

Figure 3-9

The Console Output, as it is known (the URL is http://localhost:50000/console/output), lists all of the informational and error messages that are generated by services running in the DSS node. You can use this to assist you with debugging.

Don’t be confused by the name “console output” because any messages that you write using Console

.WriteLine do not appear on this page.

Notice that you can select the level of messages in the Filters section. This is one of the advantages of using LogInfo and the other methods: You can select at runtime what level of messages you want to see. Another advantage is that you can expand the information available by clicking the small, downwardpointing arrow in the View column beside each message. This shows you information from the stack, including the name of the source file and the line number. You might find this useful if you can’t remember where a particular message comes from.

The default trace levels are set in the DssHost application configuration file, which is in the MRDS bin folder and is called dsshost.exe.config. (This is really a .NET feature, not MRDS.) Recall that the config file is an XML file, so you can open it in Notepad. It contains some helpful comments.

You can also enable timeout tracking on all messages in the config, so that you can detect services that are not responding to messages. You can also log all message traffic if you really want to!

The Manifest Load Results option is covered shortly because there is no manifest loaded at the moment.

The Contract Directory

Next, click the Contract Directory menu option. This displays a screen like the one shown in Figure 3-10. This is not very exciting; it just tells you where the services reside on the local hard drive.

106

www.it-ebooks.info

Chapter 3: Decentralized Software Services (DSS)

Figure 3-10

The Security Manager Page

Select the Security Manager from the menu. This displays a Web Form. If you click the Edit button, the screen should look like the one shown in Figure 3-11.

Figure 3-11

107

www.it-ebooks.info

Part I: Robotics Developer Studio Fundamentals

Some users have experienced problems running DssHost due to firewall or security settings on their computers. This is most likely to happen if you are not logged in as an Administrator on your PC.

The Security Manager page shows the contents of the file store\SecuritySettings.xml, which you can edit if you wish. (If you cannot find the file, then the default security settings will be in force.) However, there is another part to the puzzle: The name of the security settings file is set in the .NET application configuration file for DssHost (which was mentioned above) — namely, bin\dsshost

.exe.config. If you look in this file you should find a key called Security:

<!-- Comment the line below to disable security -->

<add key=”Security” value=”..\store\SecuritySettings.xml”/>

Security is discussed in more detail in the online documentation. You can also search the Discussion Forum if you have problems.

Resource Diagnostics

The last menu option is Resource Diagnostics. This page shows information about each of the dispatchers (and their queues) running in the DSS node. You might find this information helpful when trying to diagnose a problem. An example is shown in Figure 3-12.

When you have finished exploring DSS in the web browser, enter Ctrl+C in the MRDS Command Prompt window or simply close down the window. This is a nasty way to shut down DssHost, but it works.

Figure 3-12

108

www.it-ebooks.info

Chapter 3: Decentralized Software Services (DSS)

Running a Robot Service

To run a robot service, you need to supply a manifest on the command line. Several manifests are supplied for you in the MRDS samples\Config folder. After you have installed the code that comes with this book, you will also have a folder called ProMRDS\Config.

You will no doubt find yourself typing the same DssHost command over and over again as you test your services. You might want to create batch files to run various services. If you place them into the MRDS bin folder, then they will be on the search path and will be found automatically when you type a command in an MRDS Command Prompt window. These files are fairly simple, but they save you a lot of time.

For example, here is a batch file that runs a Boe-Bot (called RunBoeBot.cmd):

@ECHO ON

REM Run a Parallax Boe-Bot

REM Type Ctrl-C in this window when you want to stop the program. dsshost -port:50000 -tcpport:50001 -manifest:”../ProMRDS/Config/Parallax.BoeBot.manifest.xml” -manifest:”../ProMRDS/Config/Dashboard.manifest.xml”

The DssHost command is all on one line in the batch file, not wrapped as it appears here in print.

Two manifests are specified on the command line: the Boe-Bot and the Dashboard. This is because the two services are not directly related — the Dashboard connects to other services dynamically.

Notice that the paths to the manifests are relative to the location of the batch file. If you place the batch file into a different folder, i.e., not the bin folder, then you will need a relative path to DssHost.exe, and the relative paths to the manifests will be different as well.

To run this batch file, you can just double-click it in Windows Explorer. Alternatively, to run it from an MRDS Command Prompt window, enter the following command:

C:\Microsoft Robotics Studio (1.5) >RunBoeBot

Manifest Load Results

Once you have the Boe-Bot running (or your particular robot), start a web browser again and browse to the DSS node at http://localhost:50000. Select Manifest Load Results in the menu; the result should look similar to what is displayed in Figure 3-13. You can expand each manifest to see additional information. Notice that the Boe-Bot manifest loaded the BASICStamp2 and BSDrive services, each with a StateService partner (an initial config file).

109

www.it-ebooks.info

Part I: Robotics Developer Studio Fundamentals

Figure 3-13

Now select the Service Instance Directory (see Figure 3-14).

Figure 3-14

110

www.it-ebooks.info

Chapter 3: Decentralized Software Services (DSS)

Viewing Service State

Figure 3-14 indicates that many different services are running. Click the basicstamp2 service to view its state. This output should look like the window shown in Figure 3-15.

Figure 3-15

Notice in Figure 3-15 that the right infrared sensor specifies true, which indicates an obstacle in the immediate vicinity of the Boe-Bot. This page is nicely formatted because it uses an XSLT (Extensible Stylesheet Language Transform) file to format the XML output from the service.

The state information on the page does not update automatically — you need to keep clicking on the browser’s refresh button.

Go back to the Service Directory and click the bsdrive service. The output should look like Figure 3-16. This is raw XML code. If you look back at Figure 3-15, you will see an XML button in the window’s topright corner. You can click this to see the raw XML behind a formatted state page.

111

www.it-ebooks.info

Part I: Robotics Developer Studio Fundamentals

Figure 3-16

The BSDrive service does not have an associated XSLT file to format its output. However, the output is still intelligible. This is one of the advantages of XML — it is human-readable.

That completes the pictorial overview of DSS. It is hoped that the many pages it took to show the screenshots were worth more than several thousand words.

Creating a New Service

As an MRDS programmer, services are your bread and butter. Therefore, it makes sense to begin by discussing exactly what a service is and how it operates. The best way to learn is to make a new service.

In this section you will build two services, called ServiceA and ServiceB. For your convenience, completed versions of these services are supplied in the ProMRDS\Chapter3 folder.

ServiceA is the “master,” and it partners with ServiceB so that it can get information from ServiceB. As you work through the exercises, make sure you add code to the correct service.

Building a Service from Scratch

In this section you build a brand-new service. It is advisable to keep your code separate from the MRDS distribution. The Service Tutorials suggest creating new services under the samples folder, but this results in your code being intermixed with the Microsoft code. All of the code for the book is under the

112