120 likes | 214 Views
C. Crash course in robot programming 20.02.2007 Sizarta Sarshar. Next two hours. C Programming The C reference Traps and pitfalls Eyebot Programming RoBios software Eyebot library Code samples Tigergutt. The C Programming Language. The C reference guide web link
E N D
C Crash course in robot programming 20.02.2007 Sizarta Sarshar
Next two hours • C Programming • The C reference • Traps and pitfalls • Eyebot Programming • RoBios software • Eyebot library • Code samples • Tigergutt
The C Programming Language • The C reference guide • web link • The operator precedence • web link
Traps and Pitfalls “C makes it easy to shoot yourself in the foot” - B. Stroustrup “The C language is like a carving knife: simple, sharp, and extremely useful in skilled hands. Like any sharp tool, C can injure people who do not know how to handle it” - A. Koenig
Traps and Pitfalls • The faults are grouped in: • Lexical • Syntactic • Semantic pitfalls • Portability pitfalls • Linkage • Library functions • The preprocessor
Lexical and syntactic faults y = x/*p /* p points at the divisor */; a=-1; a = -1; while (c=getc(in) != EOF) while ((c=getc(in)) != EOF) putc(c,out); putc(c,out); switch (color) { case 1: printf ("red"); case 2: printf ("yellow"); case 3: printf ("blue"); } case SUBTRACT: opnd2 = -opnd2; /* no break */ case ADD: . . .
Semantic pitfalls i = 0; while (i < n) // There is no guarantee that the adress of y[i] y[i] = x[i++]; // will be evaluated before i is incremented i = 0; while (i < n) { y[i] = x[i]; i++; } double s; double s, sqrt(); s = sqrt (2); s = sqrt(2.0); printf ("%g\n", s); printf ("%g\n", s); if (a + b < 0) if ((int) ((unsigned) a + (unsigned) b) < 0) complain(); complain();
Library functions #include <stdio.h> main() { char c; while ((c = getchar()) != EOF) putchar (c); } #include <stdio.h> main() { int c; char buf[BUFSIZ]; setbuf (stdout, buf); while ((c = getchar()) != EOF) putchar (c); }
Eyebot Programming • RoBios software • Download and install • Compiler • Use the shell script gcc68 for compiling a C program. It is accessed from the RoBios console. Compiling only: • gcc68 −c filename.c • Compiling and generating an output file for download to the Eyebot controller: • gcc68 filename.c • The result is stored in a file named a.out. In order to use custom output names you may use the following: • gcc68 filename.c −o filename.out • If the code makes use of the math library, add the extension -lm. • gcc68 filename.c −o filename.out −lm
Eyebot Programming • Send the file from the host (PC) using RoBios console transhex: • transhex filename.out • In order to start up a program automatically at startup, call your downloaded program startup.hex and save it in a ROM slot.
Tigergutt Web link