Brief Introduction: Microsoft Robotics Studio (MSRS) is a Windows-based
environment for hobbyist, academic and commercial developers to create
robotics ...
ROBOTICS (01CFIDV,02CFICY) Introductory Lab on Microsoft Robotics Studio Brief Introduction: Microsoft Robotics Studio (MSRS) is a Windows-based environment for hobbyist, academic and commercial developers to create robotics applications for a variety of hardware platforms. MSRS enables developers to create services for a wide-variety of robot hardware. Here there are listed some of the most relevant features of the environment: Non-programmers can create robot applications using the Visual Programming Language (VPL) Simulate robotics applications in 3D physics-based virtual environments Makes Asynchronous Programming Simple Real-time Monitoring of Robotics Sensors and Response to Motors and Actuators Reuse Modular Services Using a Composable model Supports both remotely connected (PC-based) and robot-based (autonomous) application scenarios Develop using a wide range of programming languages For more detailed informations, and to download the MSRS environment, refer to http://msdn2.microsoft.com/it-it/robotics/default(en-us).aspx The goal of this first and introductory lab is to get in touch with the basics of the Visual Programming Language (VPL), offered by the MSRS suite, through three exercises.
Exercise 1: Display a string on the screen Prerequisites: Hardware: no special hardware is requested Software: only VPL, which comes with the basic installation of MSRS
Objective: Create a VPL diagram which displays a string (for instance “Hello World”) on the screen 1. Run VPL 2. Create a NEW PROJECT by selecting New from the File menu.
3. Now insert (double-click or drag and drop) a Data activity from the Basic Activities toolbox. Select string from the dropdown list. Click in the text box of the Data block and type in a string, for instance Hello World. 4. Insert a Simple Dialog activity, by dragging one from the Services toolbox and place it to the right of the Data activity block. 5. Now drag a link starting from the output connection pin of the Data block onto the Simple Dialog block. The Connections dialog box automatically opens. Select DataValue in the first list and Alert Dialog in the second list, then click OK. 6. The Data Connections dialog box opens. In the dropdown list, choose value. 7. This tells VPL that you want to apply the value of the Data activity to the message text for the Alert form of this dialog. The scheme should now look like in FIGURE 1:
FIGURE 1
8. Now select the Run command on the Run menu (or press F5). If you haven't saved your project yet, VPL opens the Save dialog. Enter a name for your project and click Save. VPL now proceeds to run your application. What you should see is a simple alert dialog box appears with the text, Hello World, in it. 9. To stop your application, click the Stop button in the Run dialog that VPL displays.
Exercise 2: Calculate the factorial Prerequisites: Hardware: no special hardware is requested Software: only VPL, which comes with the basic installation of MSRS
Objective: Create a VPL diagram able to calculate the factorial of a given number. At the end we should hear the value from the pc speakers and/or see it in a dialogbox.
1. Run VPL 2. Create a NEW PROJECT by selecting New from the File menu. 3. Now insert a Data block and two Variable blocks from the basic activities toolbox. In the Data block it will be inserted the value of which we can calculate the factorial. Generate two new variables: fact and prod. Assign one variable per block. Now drag a link starting from the output connection pin of the Data block onto each Variable block. The Connections dialog box automatically opens. Select SetValue. 4. Then, since we have to check a special case (i.e. the value inserted equals 0) we insert an If block, followed by a Calculate block and a TexttoSpeech block. Write “fact == 0” in the If block, write "The factorial is" + fact into the Calculate block. Connect the Variable block which contains the variable fact to the If block. Connect the If block to the Calculate block, an connect the Calculate block with the TexttoSpeech block. Two dialog boxes open: mark SayText in the first and select value in the second. Then connect also the Calculate block with a SimpleDialog. Two dialog boxes open: select AlertDialog in the first and select value in the second.
FIGURE 2
5. At this point our VPL diagram should appear as can be seen in FIGURE 2. Now we should have understood some basics about how to interact with VPL. What remains to be done in this example, is how to handle the other cases, where fact is not equal to 0. For this purpose the scheme has to be completed as suggested in FIGURE 3. Implement the scheme, try to understand it and analyze how it works. For instance, try to discover what state.prod is.
Now , in order to complete the Exercise 2, some open points are left to you. Try to do the following two points: If the calculated factorial cannot be represented with a double, an unhandled overflow occurs. Try to catch and handle this situation somehow. Think about a VPL scheme that creates a variable, initializes it, then counts to ten, telling the value on each iteration using Text-To-Speech (and/or visualizing it with a SimpleDialog box).
FIGURE 3
Exercise 3: Create your own activity Prerequisites: Hardware: no special hardware is requested Software: only VPL, which comes with the basic installation of MSRS
Objective: Learn how to create your own activity in order to modularize the code.
1. Create a new project (using the File > New menu command) . Now create a new activity by inserting an Activity block on your diagram. Click in its title and rename it Factorial, then open it (using the Open command on its pop-up context menu or double-clicking on it). A new
tabbed page appears. Use the Action dropdown and select the Action entry. This switches to the Action handler page. While the diagram page looks similar to your top level dataflow page, you can see that it has connection borders on each side which is how you connect its internal dataflow to another dataflow. 2. Use the Actions and Notifications command in the Edit menu or press the button next to the action selector dropdown on top of the page. Select the Action in the list. Add an input value to the action. This is the value we want to calculate he factorial. Change the name of the input value to StartValue and select int as its type. Click OK. 3. Then we need to use part of the VPL scheme built in the Exercise 2. So copy it and paste it into the Factorial tab. 4. Begin by placing a Calculate block near to the left border and connect its input to the input. Type StartValue in the Calculate textbox. This extracts the start value from the actions input message. Then connect this Calculate with the Variable blocks which contain the variables fact and prod. 5. Remove all the Simple Dialog and Text to speech boxes from the diagram. 6. To connect the other end of your dataflow, select the Actions and Notifications command from the Edit menu. In the dialog box, click the Notifications tab and then click Add. Add a new value OutText by clicking on Add and set the type as string, then click OK. Do the same with the Actions Tab to create a new Result variable. 7. Now put a Calculate block, write state.prod in its text Box. Connect the output of the If block which contains “fact == 1” with the input of this Calculate block, and the output of the Calculate block with the square pin in the upper-right part of the diagram. 8. Now put a Merge block in the diagram, connect the output of both the If blocks with the input of the Merge block. Then connect the Merge with the Calculate which contains the string "The
FIGURE 4
factorial is" + state.prod and the Calculate with the round Notification pin. You should now be in the situation of FIGURE 4. We have now generated a new activity which is able to calculate the factorial of a number and to provide, as a notification, a string telling “The factorial is ” followed by the value of the factorial converted in a string. Now the Factorial block can be used in a VPL diagram.
FIGURE 5
See for example FIGURE 5. In this example the block Factorial calculates the factorial of a number written in the Data box ( 4 in this case ), and the result will be visualized in a Dialog box, while a voice will tell us the value of the factorial.