Before going on, I assume that you have a minimal knowledge of CCR and DSS libraries.
The verb says that "Writing an application using the Microsoft Robotics Studio is a simple matter of orchestrating the input and output between a set of services. Services represent the interface to software or hardware and allow you to communicate between processes that perform specific functions".
An interesting question is: how do I orchestrate input and output?
In the previous articles (padservice and padservicegui), we created two pad services: one handles pad actions such as stick movement or button pressing, the other one gives feedback about these actions. In this article, we will orchestrate them using VPL.
Visual Programming Language (VPL) is a new programming language released with Microsoft Robotics Studio. The first time I used the IDE, I was a little bit confused. After many VPL projects, I came to a decision: I will use VPL simply for message orchestration. VPL is very powerful, but when I need to develop something complex like variable manipulation or loops, I rapidly get confused. So whenever I have to develop something complex, I use C#( or VB.NET) to create services and I use them as logical block to connect using VPL. Whenever I need to coordinate services, I use VPL. I've tried to orchestrate services via code (C#), but VPL is really the master in this case. You could also use old C# (programmatic) approach to orchestrate message services, but the new IDE is simple, amazing, too fast to compete with. Try to emulate what we will do in VPL using C# and you'll see the differences. VPL has also the ability to create services that you can later reuse as the C# ones.
Well, the first unusual thing regarding VPL is that tutorials or samples are better as images. No code is normally written in VPL. Configurations and expressions require quite often a keyboard. But if you know C# syntax, you don't have a problem. Remember that this is not a basic tutorial and a very little bit of knowledge is required.
Let's begin, start opening VPL IDE. In the service section, type pad. You should see the pad services. You must download and compile pad services sources. Please read Introduction to download and compile them.
Drag and drop inside the diagram two services (Pad and PadGui) as shown:
From the message notification of Pad service, drag a message line to PadGui Service (from circle to square). A pop up window should open as in the following image. There we specify that whenever a
RightStickUpdate from pad service is notified, a
RightStickUpdate message is sent to the PadGui Service. That's the orchestration!
The next step is about values. Messages can be seen as typed vectors vor values. So the message from Pad Service takes a value that we will pass to the PadGui Service using a
RightStickUpdate message. Please note that Pad Service Message Types and PadGui Service Message Types have the same names but are of different type because of their different namespaces. The default value passed to destination is by default null.
Here we set the Stick destination value from the source Stick value.
After we set the value for this Connection, we should have the following diagram. Now when the pad service sends a notification of type
RightStickUpdate we send a message of type
RightStickUpdate to the PadGui Service.
Now copy and paste the PadGui Service. We have now two references to one service instance. You should have a similar diagram.
Now we repeat what we have done for message type
RightStickUpdate but now we consider the
The main difference regarding value is that now we expand the destination Stick value and we see that this is a Composite value. Instead of using a complex value, we use two double values.
LeftStickUpdate is composed by two double values. So here we don't pass a Stick as a value but we pass a Stick created from two double values. This allows us to use complex types when we have complex source values or simple values coming from different sources. Note that you have to enable Edit values directly to enter an expression. When writing expression, you have the support of intellisense.
The diagram is like the following picture. Now we orchestrate two different notifications from pad service.
Press F5 and move the pad sticks. You will see that the graphic indicators will move accordingly to the pad values.
As we have done for
LeftStickUpdate connect even the
ButtonReleased1Update message types notifications. The process is the same. You should arrive at this:
Press F5 and move your pad stick pressing button1. You will see that B1 label changes from black to red pressing and releasing the button1.
If you need to handle the 3 remaining buttons, handle the remaining type notifications.
In these three articles, you have seen the full process of writing and orchestrating services. I used the pad service to move a Lego NXT robot. You can imagine a robot as a set of services (2 motor services and 2 sensor services for example), and in the same way you orchestrate a pad you can orchestrate a robot. The next article will cover how to move the robot using the pad. Have fun with robotics and start projecting the next planet lander NASA will send out in the space. :)
As usual, comments and suggestions are welcome.
- Matteo Ameglio
- September 2007: First release