CSC 161 Grinnell College Spring, 2015
 
Imperative Problem Solving and Data Structures
 
 

scribblerlab.c: A first C program using the Scribbler 2 robot

When a C program is used to control a Scribbler 2 robot, processing follows four main steps:

  1. The program references the MyroC library, which contains numerous operations for the Scribbler 2 robot.

  2. The workstation establishes a wireless connection with the robot, using the command: rConnect("/dev/rfcomm0");

  3. Processing with the robot continues, using commands from the MyroC library.
    For consistency in naming, all robot commands start with "r", such as rConnect, rBeep, and rDisconnect

  4. The workstation stops its wireless connect with the robot, using the command: rDisconnect();.

These steps are illustrated in the following program; steps for compiling and running the code follow the program listing.


/* This program illustrates how to connect to the Scribbler robot, beep, and disconnect. 
 */

#include "MyroC.h" // include the library for Scribbler commands

int
main()
{
  rConnect("/dev/rfcomm0"); // connect to Scribbler

  rBeep(1,550); // beep for 1 second at a frequency of 550 Hz.

  rDisconnect(); // disconnect from Scribbler

  return 0; // return, indicating no errors have occurred
} // main

Compiling and Running Programs

When using the gcc compiler directly, one must include information about where to find the relevant libraries for the Scribbler robots. The full command is:

gcc -I/home/walker/Myro/include/MyroC -L/home/walker/Myro/lib -lMyroC -ljpeg -lbluetooth -o scribblerlab scribblerlab.c

Since this line is awkward (with numerous flags: "-I", "-L", and "-l"), the suggested approach for compiling a program depends upon editing your .bashrc file and installing a Makefile, which together supply the relevant library information. From the lab on Linux basics, the following lines should be placed at the bottom of your .bashrc file:

# add the current directory to the search path
   PATH=$PATH:.

# make the libraries known to the execution environment 
LD_LIBRARY_PATH="$LS_LIBRARY_PATH:/home/walker/Myro/lib"

export LD_LIBRARY_PATH

In addition, copy this Makefile to the directory containing your program.

Assuming you have updated your .bashrc file updated, copied the Makefile, and called your program scribblerlab.c, you can compile the program using the following line in your terminal window:

    make scribblerlab

Once the program has been compiled (with compiled name scribblerlab):