Return
- The Interactive-C programming language.
The Handy board micro controller can be programmed using Interactive-C (IC for short), a subset of C with basic control structures, local and global variables, arrays, pointers, integer and real numbers and special functions for sensor reading, motor control and multiprocessing. Program size is limited by the 32K memory of the controller. In fact, programs should be smaller that that, since part of the memory is occupied by the runtime routines needed by the Handy board; these runtime units must be uploaded if the Handy board has lost its memory (due, for example, to a weak battery), or if it has not been used before. The procedure of uploading the runtime units is called bootstrapping.On a typical installation, the interactive-C and the bootstrap programs are located in the directory C:\IC.
Bootstrapping. Connect the Handy board to the serial interface. Now, you have to put it in "bootstrap" mode. This is achieved by holding the stop button while the controller is turned on. Once the controller is in bootstrap mode, type:
dl pcode_hb.s19 at the MS-DOS prompt. When finished, turn off and then turn on the controller. A message should appear on the screen. your controller is now ready for programming.Running IC. Here we cover the basic functions of IC. See the Handy board Technical reference for a detailed explanation of C syntax and additional commands.
To start IC, connect the Handy board to the serial port, turn it on and type IC at the command prompt. the IC command line appears on the screen. you can type any valid C expression (including names of functions you have created) at the command line for immediate evaluation. This is a good way of testing sensor readings.
the basic IC utilities are:
- load <fileName>. If fileName is a C file, this command compiles and loads the file. If fileName is a text file containing names of C files, the command loads each of the files listed.
- quit. Exits the IC interpreter.
IC commands.
Motors.Sensors.
- fd(int m) turns motor m in the forward direction at full power (motors are numbered from 0 to 3).
- bk(int m) turns motor m in the backward direction at full power.
- off(int m) turns off motor m.
- alloff(), ao() turn off all motors.
- motor(int m, int p) turns on motor m at power p, p ranges from -100 (full reverse) to 100 (full forward).
Buttons and knob.
- int digital(int p) returns the value of port p as a digital value (1 for true, 0 for false). When p is a digital port digital(p) works as expected. When p is an analog port digital(p) returns 1 if the analog measurement is less than 127, and 0 else.
- int analog(int p) returns the value of port p as an analog value in the range 0 to 255. If p is a digital port, analog(p) returns 0 if the port reads 0 and 255 if the port reads 1.
- int stop_button() returns 1 if the stop button is pressed, 0 else.
- int start_button() returns 1 if the start button is pressed, 0 else.
- void stop_press(), void start_press() wait for the corresponding button to be pressed, then released.
- int knob() returns the position of the knob as a value from 0 to 255.
- Sample programs.
It is a good idea to use constants to assign sensor ports, and then declare functions that specify what the sensor represents. For example, suppose that we design a robot that has two bumpers in the front. The corresponding code for reading this information could be:int LEFT_BUMP=7, RIGHT_BUMP=8; /*return true if left bumper hits something*/ int left_bump() {return digital(LEFT_BUMP); } /*same for right bumper*/ int right_bump() {return digital(RIGHT_BUMP); } /* return true if we have hit a wall */ int bump_on_a_wall() { return left_bump() || right_bump(); }Here is an example for detecting a black line on the floor. For this, we assume our robot has two photo-sensors facing down.int LEFT_LINE=1, RIGHT_LINE=0; int LINE_TRESHOLD = 208; /*treshold for photo sensors*/ /* return true if left sensor is over a black line */ int left_on_line() { return analog(LEFT_LINE) > LINE_TRESHOLD; } /*same for right sensor*/ int right_on_line() { return analog(RIGHT_LINE) > LINE_TRESHOLD; }We can see that when this program was written, sensor reading above 208 indicated a black surface. It is a good idea to define bounds like this as constants, so they can be easily changed if ambient conditions change (e.g., different lighting, use of a different sensor).Here is an example program that uses the functions defined above and also shows the use of motors. This program was tested on a three wheeled robot, with the motors attached to the two front wheels. The robot follows a black line until it hits an obstacle, then it stops:
The line follower program.