VPL Lab 3 - DriveDistance and RotateDegrees

Glossary Item Box

VPL Hands On Labs: VPL Lab 4 - Drive in a Square

VPL User Guide: Getting Started

See Also Microsoft Robotics Developer Studio Send feedback on this topic

VPL Lab 3 - DriveDistance and RotateDegrees

In this lab you will learn about some advanced behaviors, called DriveDistance and RotateDegrees, that are available with the Generic Differential Drive.

This lab is provided in the language. You can find the project files for this lab at the following location under the Microsoft Robotics Developer Studio installation folder:

Samples\VplHandsOnLabs\Lab3

This lab teaches you how to:

  • Step 1: Read Commands from the Direction Dialog
  • Step 2: Issue Requests to the Drive
  • Step 3: Display Notifications
  • Step 4: Run the Program

See Also:

  • Robotics Tutorial - Drive By Wire
  • VPL Examples - Drive In Triangle

Prerequisites

Hardware

This lab can be completed either in simulation or with a real robot and has been set up to use the simulated Create. If you are using a real robot, it needs to move around and is should have a wireless connection to your PC. To use a real robot you will have to change the manifest associated with the Generic Differential Drive.

Software

This lab requires Microsoft Robotics Developer Studio, in particular it uses Microsoft Visual Programming Language (VPL).

Step 1: Read Commands from the Direction Dialog

Open VPL to create a new diagram.

Start by dragging a DirectionDialog to the diagram. This service displays a Windows Form with buttons on it so that you can drive a robot in different directions. Note that the DirectionDialog on its own does not know anything about robots or how to drive them - it is just a set of buttons.

Add an If activity to your diagram, and then add all of the expressions shown in Figure 1. Notice that these expressions use an enumerated data type that is defined in the DirectionDialog to identify the various buttons.

Figure 1

Figure 1 - Handling Direction Dialog buttons

Step 2: Issue Requests to the Drive

In this section you will build the rest of the diagram, as shown below in Figure 4 at the end of the section. Skip forward and refer to Figure 4 if you do not understand the instructions.

Locate the GenericDifferentialDrive in the Services panel and drag it to the diagram. In the Properties panel under Configuration, select "Use Manifest" in the dropdown list. You need to select the appropriate manifest for your robot. The VPL program supplied with RDS is configured to use an iRobot Create simulation called IRobot.Create.Simulation.Manifest.xml.

Now connect the first of the output pins from the If (the one corresponding to Forwards) to the GenericDifferentialDrive. You should select the DriveDistance request. When the Data Connections dialog appears, tick the "Edit values directly" checkbox and then fill it in as shown in Figure 2.

Figure 2

Figure 2 - DriveDistance parameters

Distances in RDS are measured in meters, so setting Distance to 0.5 means the robot will move half a meter or about 1.64 feet. The Power setting of 0.5 is half power because RDS power settings range from -1.0 to 1.0, with negative values meaning the robot travels backwards.

The value for DriveDistanceStage requires a little explanation. When you make a request, this value must be set to DriveStage.InitialRequest. (For convenience, you can leave it empty, i.e. null, and this will have the same effect). As the drive executes the request, it sends notification messages and this field is filled in with a value that indicates the progress of the motion. This is discussed further below.

Cc998517.hs-note(en-us,MSDN.10).gif

The DriveDistance and RotateDegrees operations are not implmented by some drive services. If your robot does not work with this lab, this could be the reason. Alternatively, some services implement these operations using timers because the robot does not have wheel encoders to measure the distance travelled. In this case, the motions might not be accurate.

Copy the GenericDifferentialDrive activity and paste it back into the diagram. Alternatively, you can drag a new GenericDifferentialDrive onto the diagram and select the option to use the existing activity when the dialog appears. Note that both of these activity blocks represent the same drive. They are displayed in VPL as separate blocks to make it easier to write programs. If you inadvertently create a different drive, its name will have a zero appended to it (GenericDifferentialDrive0) because the names must be unique.

Connect the second output of the If (the one for Left) to the new GenericDifferentialDrive, but this time select RotateDegrees as the request type.

When the Data Connections dialog appears, fill it in as shown in Figure 3. The Degrees value of 90 is a quarter turn to the left. Angles in RDS are measured anti-clockwise about the robot's center as you look down on it from above. Negative angles are clockwise, or to the right.

Figure 3

Figure 3 - RotateDegrees parameters

Continue creating new GenericDifferentialDrive blocks and attaching them to the If outputs. The parameters are as in the following table. Remember that you need to use DriveStage.InitialRequest in all cases.

Direction Request Distance Degrees Power
Forwards DriveDistance 0.5
0.5
Left RotateDegrees
90
0.5
Right RotateDegrees
-90
0.5
Backwards DriveDistance 0.5
-0.5

The last output from the If is for Stop. This one should be connected to the GenericDifferentialDrive using the SetDrivePower request. Set both the Left and Right Wheel Power to zero. This allows you to stop the robot while one of the other motions is in progress.

Drag a Merge activity to the diagram and connect all of the GenericDifferentialDrive outputs to it, selecting Fault as the message type. This will allow you to see if any errors occur.

Add a SimpleDialog to the diagram and connect the output of the Merge to it. This saves you having to create a whole set of activity blocks with one for each GenericDifferentialDrive.

Figure 4

Figure 4 - Completed diagram

Step 3: Display Notifications

This step is not essential to make the program work, but you will find it very useful in understanding how the GenericDifferentialDrive works.

Create another activity block for the GenericDifferentialDrive. This time it will not have any inputs. Create two more SimpleDialog blocks beside it to display the notification messages. (Refer to Figure 5 if you need to).

Add a connection by dragging from the round pin (the notification pin) on the GenericDifferentialDrive to the first SimpleDialog. Select the DriveDistance message type and send it to the Alert Dialog. In the Data Connections, select value.DriveDistanceStage.

Add another connection between by dragging from the round pin on the GenericDifferentialDrive again, but this time to the second SimpleDialog. Select the RotateDegrees message type and send it to the Alert Dialog. In the Data Connections, select value.RotateDegreesStage.

Figure 5

Figure 5 - Displaying notifications

Step 4: Run the Program

Save your diagram and then run it. Try clicking on the buttons on the DirectionDialog and see what happens.

If you set up the notifications, you should see a "Started" notification message displayed (in an Alert dialog) when you click on a button, and then a "Completed" message when the motion finishes. Note that the "Completed" notification message is not sent until the robot has stopped moving.

Try clicking on a button more than once without waiting for the motion to finish. This will result in a "Canceled" message, followed immediately by another "Started" message.

This is an important point because it demonstrates that only one operation can be in progress at a time, and the requests are not queued up. If you keep clicking the Forwards button for example, the robot will keep driving forwards, but only because you cancel the current operation before it completes and start a new one.

You can also click the Stop button to cancel any operation that is currently running.

Cc998517.hs-tip(en-us,MSDN.10).gif

The hardware capabilities of different robots vary. As a result, some robots can perform DriveDistance and RotateDegrees but others cannot. (If a robot cannot execute these functions it should return a Fault when you make a request). The accuracy of these operations will also vary from one robot to another. And lastly, some robots cannot be interrupted once they begin an operation, so the Stop button might not work or the robot might queue up multiple requests. You should find this example useful for exploring the behavior of your particular robot to see how it handles these operations.

Play around with this program until you understand how it works. You should be aware that the response message from the GenericDifferentialDrive activity block (on the triangular output pin) is sent immediately, so you cannot wait on the response. However, the notifications are not sent until the motions complete (or are canceled). The next lab shows you how to use these notifications to perform a sequence of moves.

Robotics Tutorial - Drive By Wire

The Drive By Wire example in Robotics Tutorials is similar to this program, but it uses SetDrivePower. You should compare the two examples.

VPL Examples - Drive In Triangle

The Drive In Triangle example in the VPL Examples shows you how to use the DriveDistance and RotateDegrees operations to make a robot drive in a pattern. In particular, it waits for each operation to complete before starting the next one. It uses a different approach from the next VPL Hands On Lab called Drive In Square.

Summary

This lab covered:

  • Step 1: Read Commands from the Direction Dialog
  • Step 2: Issue Requests to the Drive
  • Step 3: Display Notifications
  • Step 4: Run the Program
See Also 

VPL Hands On Labs: VPL Lab 4 - Drive in a Square

VPL User Guide: Getting Started

 

 

© 2012 Microsoft Corporation. All Rights Reserved.