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

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

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

www.it-ebooks.info

Chapter 14: Remotely Controlling a Mobile Robot

your Control Panel — one from the hardware manufacturer and the other from Microsoft — and you will probably find that the Microsoft control panel applet won’t work.

If you have trouble getting Bluetooth to work, one brand of software that has worked successfully for many people was written by WIDCOMM. This company was purchased by Broadcom in 2004, but the name was retained. You can download the latest version of the BTW software from Broadcom’s website (www.broadcom.com/products/bluetooth_update.php). Note that this should be a last resort because there is no guarantee that this software will work with your device.

The instructions here are based on using an Anycom Blue USB-240 Adapter. (For more information see www.anycom.com.) This is a Class-1 device, which means that it should have a range of up to 100m. It comes with a CD and installation of the software is very simple, so it is not covered here.

Once you have a Bluetooth icon in your taskbar, you can set up the connection:

1.

2.

Plug in your Bluetooth USB dongle or turn on Bluetooth on your PC or laptop.

Turn on your Tribot and set it up as follows:

a.

b.

c.

On the main menu, scroll through the options using the gray arrow buttons on the brick until you find Bluetooth and then select it by pressing the orange Enter button.

In the Bluetooth menu, find the option labeled On/Off and select it.

Select the On option.

Now that you have done this, Bluetooth will always be enabled when you turn on your Tribot, unless you replace the batteries — there is no need to repeat this step every time you use the Tribot.

3. Either from the icon in the system tray or from the Windows Control Panel, start the Bluetooth Devices applet (see Figure 14-3).

Bluetooth Discovery

Bluetooth devices can broadcast their name and the services that they offer so that other devices can find them. The process of finding other devices is called discovery. Note that you do not have to turn on discovery in the Options panel as shown on the right in Figure 14-3. Discovery should be left off on the PC for security reasons. MRDS will make an outgoing connection to the NXT; it is not necessary for the PC to broadcast its availability.

The NXT, however, does have to have discovery enabled. There is an option in the Bluetooth menu on the NXT called Visibility. You must make sure that this is set to Visible (which is the default setting).

603

www.it-ebooks.info

Part IV: Robotics Hardware

Figure 14-3

4. Click the Add button in the Devices panel. This starts the Add Bluetooth Device Wizard, shown in Figure 14-4. Enable the checkbox “My device is set up and ready to be found.”

Figure 14-4

5. When you click Next, the wizard will start looking for Bluetooth devices. After a short delay, the LEGO NXT should appear in the list. Select it and click the Next button.

604

www.it-ebooks.info

Chapter 14: Remotely Controlling a Mobile Robot

Bluetooth Device Names

If you have a Bluetooth-enabled mobile phone or PDA and they are within range, you might see them listed also. The LEGO NXT has a default name of NXT, so it is easy to identify. However, if you are working in a classroom environment, you will probably want to change the names on all of the NXT bricks so that they are unique. Refer to the LEGO documentation for how to do this.

6. The next Wizard screen asks you for a passkey. Before Bluetooth devices can communicate with each other, they must be paired. The passkey is used as a security measure. Without it, you could sit at a curbside cafe and read information off every Bluetooth-enabled phone or PDA that passed by! The LEGO NXT has a default passkey of 1234. Therefore, you should select the option to enter a passkey as shown in Figure 14-5 and ignore the warning that it should be at least eight digits long.

Figure 14-5

7. When you click the Next button, the LEGO NXT will make a sound and display a message asking you to enter a passkey. You can simply click the Enter (orange) button on the NXT because you are using the default passkey. Note that this pairing process will time out if you are not quick enough. In that case, you can back up in the wizard and try again.

8. After the Bluetooth device has been installed (which takes a few seconds), the wizard displays one final screen, shown in Figure 14-6. This lists the COM ports that have been set up for you. Figure 14-6 indicates that there is an outgoing port COM5 and an incoming port COM6. Make a note of the outgoing port number because you will need it later. If you forget, you can open the Bluetooth Devices applet and look in the COM Ports panel.

605

www.it-ebooks.info

Part IV: Robotics Hardware

Figure 14-6

9. Click Finish. You have now paired your LEGO NXT with your PC. This pairing will be remembered in the future unless you delete it in the Bluetooth Devices applet on the PC or in the Bluetooth Connections menu on the LEGO NXT.

Now that you have a working Bluetooth connection, it is time to establish a link using MRDS. You might want to turn your LEGO NXT off and on again just to be sure that you are starting from scratch.

Communicating with the LEGO NXT Brick

The LEGO NXT brick runs the monitor program that controls the Tribot. MRDS downloads this program automatically when the Brick service connects to the NXT.

The monitor code for V1.5 is available in samples\Platforms\LEGO\NXT\Resources. (This code is no longer used by the V2 services.) If you want to change it, you have to use the Mindstorms software from LEGO to modify it and recompile. This process is specific to the LEGO NXT and is outside the scope of this book.

The following instructions apply to using the V1.5 services. The V2 services are covered later.

1.

2.

Start a MRDS command prompt by clicking Start All Programs Microsoft Robotics Studio (1.5) Command Prompt.

At the command prompt, enter the following command to start the LEGO NXT Brick service:

dsshost /p:50000 /t:50001 /m:”ProMRDS\Config\LEGO.NXT.Brick.manifest.xml”

606

www.it-ebooks.info

Chapter 14: Remotely Controlling a Mobile Robot

Backwards or Forwards Slashes?

You might notice in examples of dsshost commands that sometimes the manifest paths are shown using backslashes (\) and sometimes using forward slashes (/). Technically, they should be forward slashes because they are supposed to be URLs. However, Windows uses backslashes for directory paths so either of them is acceptable. This is not an important point, but users are sometimes puzzled by it.

Another possible source of confusion is that the dsshost command line can use either slashes (/) or hyphens (-) to introduce parameters. Furthermore, you can abbreviate commands to their first letter — for example, /manifest simply becomes /m.

In the Command Prompt window you will see the DSS node starting up. A web browser window should also appear and display the LEGO NXT Brick service, as shown in Figure 14-7. Notice that there is an error message saying that the NXT is not connected, and the COM port is shown as 0 (zero).

Figure 14-7

607

www.it-ebooks.info

Part IV: Robotics Hardware

3.

4.

Enter the COM port number for the outgoing port that you made a note of when you set up the Bluetooth connection. Scroll down to the bottom of the web page and click the Connect button. The NXT will display “Microsoft Robotics Studio” and an hourglass. After a couple of seconds, the hourglass should disappear and the NXT will beep. It is now ready to be controlled via MRDS.

You can close down the MRDS command prompt and browser windows and turn off the NXT. (Press the dark gray Cancel button on the brick to exit the MRDS program, and then a couple more times until you get to the “Turn off?” prompt.)

After successfully connecting to the LEGO NXT, MRDS writes the COM port number into the config file so that you won’t have to enter it in the future. You can look in ProMRDS\Config\LEGO.NXT

.Brick.Config.xml to find the ComPort setting. If you have problems with your NXT and need to start again from the beginning, you can always edit this config file and put 0 (zero) in as the ComPort setting and run the Brick service again to reconfigure it.

If you upgrade the firmware in your NXT, you will lose the configuration information in the brick. In this case, you should set the ComPort back to 0 and repeat the preceding steps.

Although you have made a connection between MRDS and the NXT brick, you need a suitable service to be able to control the Tribot. The Dashboard is a good starting point (it is covered later in the chapter). If you can’t wait and want to jump ahead, you can run the following command:

dsshost /p:50000 /t:50001 /m:”ProMRDS\Config\Tribot.manifest.xml” /m: “ProMRDS\Config\Dashboard.xml”

Make sure you type this all on one line, not on two lines as it appears here.

At this stage you have successfully configured your LEGO NXT using the original LEGO services and you can quite happily continue to use these services. However, you have not configured the sensors on your NXT, which can be done on the Brick web page. This needs to be done before you can use the sensors, but you will come back to that later when you set up the V2 services, which are much better. Please continue on to the next section.

LEGO NXT V2 Services

When you download the LEGO NXT V2 services (available from the MRDS Downloads web page) and run the installation, the source code will be copied into the following folder:

samples\Platforms\LEGO\NXT\V2

Source code is provided for all of the supported platforms. The original LEGO NXT services will not be overwritten when you install the V2 services.

There is a solution file in this directory called nxtbrick.sln that you can open in Visual Studio. This contains all of the services in four different projects.

608

www.it-ebooks.info

Chapter 14: Remotely Controlling a Mobile Robot

MRDS Service Versioning

MRDS uses strong versioning to ensure that the various services are all compatible with one another. If you make even minor changes to any of the code while you are editing nxtbrick.sln and then recompile, you might have to do a complete rebuild of all the LEGO NXT V2 services.

This has caused some people trouble in the past because the interdependencies between services are quite complex. If you get errors when you are trying to start MRDS services that are related to version mismatches, it might be necessary to recompile all of the affected services twice. The second compilation is required to pick up dependencies that could not be resolved during the first compilation.

Note that there is no need to change the V2 services at this stage!

To use the V2 services, you simply need to set up the appropriate config files and a manifest. The way that V2 works is quite different from V1.5. In particular, the individual sensors have their own config files, which specify where the sensors are connected on the brick. (In V1.5 the sensor configuration was attached to the brick as shown in Figure 14-7.)

Initially, it is not important to get the sensor configuration correct. You can change it later using the Manifest Editor or simply by editing the config files. However, as with V1.5, you have to specify the correct COM port for the Bluetooth serial connection.

Look in the ProMRDS\Config directory. You will find several config files related to the LEGO NXT V2 configuration:

Lego.Nxt.v2.Brick.Config.xml

Lego.Nxt.v2.Drive.Config.xml

Lego.Nxt.v2.TouchSensor.Config.xml (Sensor1)

Lego.Nxt.v2.UltrasonicSensor.Config.xml (Sensor4)

HiTechnicCompassSensor.Config.xml (Sensor3)

There are also several manifests in the directory, but the two of interest are TriBotV2.manifest.xml and MyTriBotV2.manifest.xml. The first one is a simple manifest that just loads the basic Tribot with a differential drive. The second manifest includes all of the sensors listed above (assuming they are attached to the sensor ports as specified in the list).

Unlike the V1.5 services, if you run the LEGO NXT V2 services with no serial port specified, then the browser window does not allow you to edit the setting.

If you open Lego.Nxt.v2.Brick.Config.xml in Notepad, you will see that it is only a short file:

609

www.it-ebooks.info

Part IV: Robotics Hardware

<?xml version=”1.0” encoding=”utf-8”?>

<NxtBrickState xmlns:s=”http://www.w3.org/2003/05/soap-envelope” xmlns:wsa=”http://schemas.xmlsoap.org/ws/2004/08/addressing” xmlns:d=”http://schemas.microsoft.com/xw/2004/10/dssp.html” xmlns=”http://schemas.microsoft.com/robotics/2007/07/lego/nxt/brick.html”>

<Configuration> <SerialPort>5</SerialPort> <BaudRate>115200</BaudRate>

<ConnectionType>Bluetooth</ConnectionType> <ShowInBrowser>true</ShowInBrowser>

</Configuration> </NxtBrickState>

The SerialPort is specified as number 5 in the preceding code. You need to change this to the same outgoing port that you used previously to configure the LEGO NXT Brick service in the web browser. That is the only change required. You can then run your LEGO NXT Tribot using the manifests listed above. For example,

dsshost /p:50000 /t:50001 /m:”ProMRDS\Config\TribotV2.manifest.xml”

starts the Tribot and launches the Dashboard (because it is in the manifest). The Dashboard is covered later in this chapter. The LEGO NXT should beep, and then you can use the Dashboard to drive it around.

An interesting point about this configuration is that ShowInBrowser is set to true, so a web browser is displayed showing the details of the brick. An example of the main LEGO NXT V2 Brick service is shown in Figure 14-8 for MyTribotV2.manifest.xml, which includes several sensors.

Figure 14-8

610

www.it-ebooks.info

Chapter 14: Remotely Controlling a Mobile Robot

If you have not used the web browser interface before, you should poke around and become familiar with it. In particular, look in the Service Directory and click some of the services. Figure 14-9 shows thumbnails of the new V2 Touch Sensor, HiTechnic Compass, Ultrasonic Sensor, and Differential Drive. These interfaces update dynamically and are quite impressive.

Figure 14-9

Using a Parallax Boe-Bot with MRDS

Building a Parallax Boe-Bot is relatively easy but it is time consuming. It is not necessary to work through the entire book Robotics with the Boe-Bot that comes with the robot, so it will not take you the 40 hours indicated on the front of the book. The relevant chapters are as follows:

Chapter 1: Activities 1, 2, 3, and 4

Chapter 2: Activities 3, 4, and 6

Chapter 3: Activities 1, 2, and 3

611

www.it-ebooks.info

Part IV: Robotics Hardware

If you are not familiar with breadboarding, you should read Appendix D in the Parallax book as well.

The instructions in the Parallax book will assist you in building the basic robot, and you can start driving it around immediately, but it will be blind because it has no sensors.

In order to use the Boe-Bot with MRDS, you need to download the relevant instructions from the Parallax website and then build the sensor package on the breadboard area. At the time of writing, this document was available from the Boe-Bot Kit for Microsoft Robotics Developer Studio page on the Parallax website, and it was called MRDS-Bluetooth-Boe-Bot-v1.5.pdf.

Note that some of the I/O port assignments for MRDS do not match those used in the Robotics with the Boe-Bot book, but you might find Chapter 5 (about the whiskers) helpful, as well as Chapter 7 (about the infrared “headlights”).

Once you have completed your Boe-Bot, it should look like the image in Figure 14-10.

Figure 14-10

Notice that the Boe-Bot in Figure 14-10 has the eb500 Bluetooth module installed (standing up in the middle of the Board of Education) and a lot of circuits in the breadboard area. The BASIC Stamp 2 has 16 I/O pins, allocated to the various devices as indicated in the following table:

612