SlideServe
Menu
Préférences
© SlideServe · v2026

Crash Course in Robot Programming: C Language Traps and Pitfalls

xannon avatar
12 diapositives · 235 Views · Oct 05, 2014

Explore the nuances and challenges of C programming for robots with code samples, Eyebot programming tips, and essential C references. Learn how to avoid lexical, syntactic, semantic, and portability pitfalls in the C language.

Crash Course in Robot Programming: C Language Traps and Pitfalls - slide 1
01 / 12Crash Course in Robot Programming: C Language Traps and Pitfalls
1 / 17

Télécharger la présentation

Crash Course in Robot Programming: C Language Traps and Pitfalls
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. C Crash course in robot programming 20.02.2007 Sizarta Sarshar

  2. Next two hours • C Programming • The C reference • Traps and pitfalls • Eyebot Programming • RoBios software • Eyebot library • Code samples • Tigergutt

  3. The C Programming Language • The C reference guide • web link • The operator precedence • web link

  4. 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

  5. Traps and Pitfalls • The faults are grouped in: • Lexical • Syntactic • Semantic pitfalls • Portability pitfalls • Linkage • Library functions • The preprocessor

  6. 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: . . .

  7. 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();

  8. 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); }

  9. 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

  10. 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.

  11. Tigergutt Web link

  12. The End