The scripting language offers complete control of the robot. For example, you can read sensor data and execute point-to-point motions (in cartesian and joint space).
The following example demonstrates how the custom-built hexapod can swing multiple (max) times from left to right and right to left (ldx millimeters):
Command ListThe following commands are supported:
- var = 10.0;
Creates a numerical variable and assigns 10.0 to it.
- if X then Y else Z endif;
If condition X holds execute Y else Z. The else part is optional.
- while X do Y endwhile;
Do Y while condition X holds.
Print X to screen. X can be numerical or a (simple) string.
- run([X1, .. , XN], Y, Z);
Play motions stored at index X1, X2, .. , XN in motion buffer with pause of Y milliseconds between two frames and interpolation type Z(same as the play command in the console).
- play(X, Y, Z);
Add motion stored at index X in motion buffer to trajectory lists of Limb Z with total execution time Y.
- motion(X, Y);
Execute motion command (same as command m in console).
Stops script processing (motions won't be stopped!) until the user presses the return key.
Stops the robot motion.
Returns value of sensor X. X can be "DISTLEFT", "DISTCENTER", "DISTRIGHT", "LIGHTLEFT", "LIGHTCENTER", "LIGHTRIGHT" or "SOUNDS" (see /main/src/parser.cpp).
Sleeps for X milliseconds.
Returns absolute value of X.
Returns cosine of X.
Returns sine of X.
Returns tangent of X.
- atan(X, Y)
Returns arc tangent of X.
Returns arc cosine of X.
Returns arc sine of X.
Returns current torque of servo X.
Executes script with filename X (subroutines!).
- load(X, Y);
Load motion stored in file Y into motion buffer at index X.
- pos(X, Y)
Returns information for limb X. Y can be "x", "y", "z", "rotx", "roty" or "rotz" (see /main/src/parser.cpp).
- moveto(I, X, Y, Z, A, B, C, T);
Move limb I to position X Y Z with orientation A B C in T milliseconds. The orientation is optional.
Returns true if and only if a collision occured.
Returns current timestamp (in milliseconds).
- sync X endsync;
Locks access to trajectories = Synchronizes robot movement.
Sets target position of all servos to its current position.
Returns current position of servo X.
- set(X, Y, Z);
Moves servo X to position Y in Z milliseconds (overwrites moveto commands).
Add new CommandsThe parser for the scripting language is created with lexx and bison (yacc).
The lexx syntax file is /parser/parser.l.
The yacc syntax file is /parser/parser.y.
You need a version of lexx and bison to compile the parser. Since Win32 version of these program are hard to find they are included in the repository.
Compilation of the parser:
- lexx parser.l
- Rename the result (lex.yy.c) to lex.yy.c
- bison -d parser.y
- Rename the result (parser_tab.c, parser_tab.h) to y.tab.c and y.tab.h
- Copy lex.yy.c and y.tab.c to main/src
- Copy y.tab.h to main/include
- Recompile the main program (/main/)