Wait For Drive Completion

Microsoft Robotics

Glossary Item Box

Microsoft Robotics Developer StudioSend feedback on this topic

Wait For Drive Completion

Wait For Drive Completion

The WaitForDriveCompletion service was written specifically for use in VPL to simplify using services that implement the Generic Differential Drive contract.

There are two operations available on a Generic Differential Drive that run for an indeterminate amount of time: DriveDistance and RotateDegrees. Because there is no way to know in advance how long these operations will take to complete, it is not possible to create a sequence of operations to make a robot drive in a pre-defined pattern such as a square. (If any new request is sent to the drive before the previous one has finished, then the first operation is canceled). By using WaitForDriveCompletion after each DriveDistance or RotateDegrees request to a Generic Differential Drive service you can ensure that the next motion in a sequence is not executed until the previous one has finished.

The WaitForDriveCompletion service has only one operation of interest and it is called Wait. This operation takes no parameters. It listens for notifications from a Differential Drive, and sends back a response as soon as it sees the final completion status of a DriveDistance or RotateDegrees command, which is either Canceled or Completed.


If you are using WaitForDriveCompletion, do not pass the DriveStage value from its response message as the input parameter to a DriveDistance or RotateDegrees request. You must initialize new requests with the value DriveStage.InitialRequest, otherwise the request will not function as expected.

A sample diagram that illustrates the use of WaitForDriveCompletion is available. It drives a robot in a triangle by issuing successive drive and rotate commands. You can find this sample at:



Technical Notes

Both DriveDistance and RotateDegrees use notifications to send information about what is happening to the Differential Drive. These notifications contain various status values that are declared in the DriveStage enum (an enumerated list of values).

Note that WaitForDriveDistance sends the final status in its response message and you can check for DriveStage.Completed or DriveState.Canceled. It is possible that a motion might be canceled. For example, if you have code that monitors a sensor and it detects an obstacle in the robot's path then you might send an AllStop request to the drive. Any new drive operation request, including SetDrivePower, cancels a DriveDistance or RotateDegrees that is currently running.


If you use the AllStop operation to stop a robot in an emergency, then you will have to send an EnableDrive request to allow the robot to drive again. This is a safety feature.

VPL activities can be wired up to receive notifications. However, an activity that is connected to the notification pin on a service will receive all notifications as long as the diagram is running. It is not possible to receive a single notification and then unsubscribe from the service. In some cases this is not an issue, as is demonstrated in the Drive in a Square example in the VPL Hands On Labs.

For reasons related to Exclusivity, it is not possible to receive notifications inside a VPL Custom Activity. Therefore a C# service was required to wait for the notifications rather than hiding them in a Custom Activity. 

Although it might seem easier to have the Differential Drive operations wait until the motions have completed before sending a response message, this is not the intended design of DSSP. In the past, some implementations of the Differential Drive actually did this. Any code that relies on this behavior will no longer work. However, the simple addition of WaitForDriveCompletion to your diagram allows the original behavior to be restored.

VPL Hands On Labs: VPL Lab 3 - DriveDistance and RotateDegreesVPL Lab 4 - Drive in a Square

VPL Robotics Services: Robotics Services Overview



© 2012 Microsoft Corporation. All Rights Reserved.