| XML Scripting Last Modified: 2006-08-18 | | |
| Acroname Robotics | |||
| Overview This tutorial discusses the creation of XML scripts for the Garcia. Scripts provide a convenient way to make the Garcia platform provide a sequence of behaviors. Scripts are stored in text files so they are easy to edit and refine when developing an application. A software tool called aGarciaScript is included in the Garcia download that may be used to test XML scripts. The Task How can I test Garcia behaviors without having to use a programming environment? The Concepts The Garcia contains a number of built in primitives that handle common tasks. The combination of a primitive with a specific set of parameters is a behavior. Behaviors may be described in XML format and stored in a text file. The aGarciaScript tool can test individual scripts. Triangle Script In this example, the robot will move in a triangular path. To make a triangle, the robot will use three move and three pivot primitives. The script will contain behaviors created from these primitives with parameters to make the robot trace an equilateral triangle 0.5 meters on a side. Here is a graphical representation of those behaviors: ![]() The following script defines the behaviors for making the robot follow the triangular path described above. Distance units are in meters. Angle units are in radians. These are the default units for the robot. Note the format of the file. Only a few XML tags are sufficient for describing behaviors. <BEHAVIOR>
<PRIMITIVE> "move" </PRIMITIVE>
<NAME> "out" </NAME>
<PROPERTY>
<NAME> "distance" </NAME>
<VALUE> 0.5 </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "pivot" </PRIMITIVE>
<NAME> "pivot 1" </NAME>
<PROPERTY>
<NAME> "angle" </NAME>
<VALUE> 2.0944 </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "move" </PRIMITIVE>
<NAME> "over" </NAME>
<PROPERTY>
<NAME> "distance" </NAME>
<VALUE> 0.5 </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "pivot" </PRIMITIVE>
<NAME> "pivot 2" </NAME>
<PROPERTY>
<NAME> "angle" </NAME>
<VALUE> 2.0944 </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "move" </PRIMITIVE>
<NAME> "back" </NAME>
<PROPERTY>
<NAME> "distance" </NAME>
<VALUE> 0.5 </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "pivot" </PRIMITIVE>
<NAME> "pivot 3" </NAME>
<PROPERTY>
<NAME> "angle" </NAME>
<VALUE> 2.0944 </VALUE>
</PROPERTY>
</BEHAVIOR>
The robot starts by performing a BEHAVIOR with the unique NAME "out" that uses a move PRIMITIVE . To perform the "out" behavior, the PROPERTY of the move primitive with the NAME "distance" is set to the VALUE of 0.5 meters. Next, the robot will perform a BEHAVIOR with the unique NAME "pivot 1" that uses a pivot PRIMITIVE . To perform the "pivot 1" behavior, the PROPERTY of the pivot primitive with the NAME "angle" is set to the VALUE of 2.0944 radians (120 degrees). The robot continues performing these two behaviors until it arrives back at the starting point. Copy and paste the XML text to a file called "triangle.xml" in your aUser folder. Run the GarciaScript application and hit the Execute button to select and run the script file. The robot will move in a triangular path. As the robot moves, it is also using its monitor programs to check its sensors. Place an object in front of the robot's front sensors and it will stop.
Scripts within Scripts A script itself is a behavior. Note that the triangle script listed above contains two behaviors repeated three times: a move of 0.5 meters followed by a pivot of 120 degrees. The move and pivot may be called as a subscript from another script in order to trace an indentical path. Copy and paste the following XML to a text file called "oneside.xml" in your aUser directory. <BEHAVIOR>
<PRIMITIVE> "move" </PRIMITIVE>
<NAME> "one-side" </NAME>
<PROPERTY>
<NAME> "distance" </NAME>
<VALUE> 0.5 </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "pivot" </PRIMITIVE>
<NAME> "one-turn" </NAME>
<PROPERTY>
<NAME> "angle" </NAME>
<VALUE> 2.0944 </VALUE>
</PROPERTY>
</BEHAVIOR>
Now copy and paste the following XML to a text file called "triangle2.xml" in your aUser directory. <BEHAVIOR>
<PRIMITIVE> "script" </PRIMITIVE>
<NAME> "side 1" </NAME>
<PROPERTY>
<NAME> "filename" </NAME>
<VALUE> "oneside.xml" </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "script" </PRIMITIVE>
<NAME> "side 2" </NAME>
<PROPERTY>
<NAME> "filename" </NAME>
<VALUE> "oneside.xml" </VALUE>
</PROPERTY>
</BEHAVIOR>
<BEHAVIOR>
<PRIMITIVE> "script" </PRIMITIVE>
<NAME> "side 3" </NAME>
<PROPERTY>
<NAME> "filename" </NAME>
<VALUE> "oneside.xml" </VALUE>
</PROPERTY>
</BEHAVIOR>
Try both the "triangle.xml" and "triangle2.xml" scripts and watch them perform the same motions. This particular subscript example does not save a lot of script writing. It is only meant to illustrate the technique of using scripts within scripts. As a user develops more complicated scripts, the subscript technique may be very useful. Going Further This example shows how to write a simple script. It runs on all platforms that include the aGarciaScript tool. Scripts can make use of many of the sophisticated features built into the Garcia such as wall-hugging and object detection. With these features, scripts can perform useful navigation tasks. Scripts may also be called from programs via Garcia API library calls. Our next script tutorial will demonstrate some of these advanced scripting techniques. |
| ||||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2012 Acroname, Inc., Boulder, Colorado. All rights reserved. |