Building Karel the Robot: Invaluable Learning Experience for Students

by Dave Riske, Networking Technologies Instructor, Western Nevada College (WNC), Carson City

NCLab’s Karel the Robot is a perfect tool to teach students the fundamental ideas of computational logic and structured design, uncluttered by specific programming language requirements. The premise behind the Karel language is to use a simple syntax structure with simple logic as a starting point and then slowly building the complexity of both syntax and logic. Though students were grasping the concepts presented in the activities in Karel, there was still a tangible component missing. WNC already owned several versions of the Lego Mindstorm NXT and EV3 robotic kits. Therefore I decided to try to externalize Karel the Robot from the screen to the tabletop. Initial requirements were simple:

  • The robot must look like Karel the Robot.
  • The robot must respond in a manner consistent with the virtual robot in NCLab.
  • Students should be able to use a command set similar to the commands available in NCLab to control the robot to solve mazes.
  • Building mazes for the robot must be easy and relatively inexpensive.

Physical Robot and Playing Field

The robot and the playing field must mimic the environment available in NCLab. The initial plan for the playing field was to use a 4×8 sheet of plywood as a base. This was gridded out in 8×8 squares yielding a playing field of 6 by 12 squares, which could expand easily with the addition of another board to 12×12. This would require careful consideration of which puzzles and mazes to externalize as many of the mazes are larger than the available physical space.

Ultimately, the playing field is a maze. We are currently investigating using foam core, cut in an interlocking method, that will allow us to build an interior wall that can be ‘seen’ by the robot and provide the means to have the robot respond to the environment of the maze. The foam core will also be used to provide a border wall around the playing field.

Initial searches yielded a robot design that looked similar to Karel the Robot and was modifiable with respect to available components within the Lego kits already owned by WNC. This initial build was also modifiable dependent on needs that became evident as the various programs were designed to control the robot. Further work and development will be done on the physical aspects of the robot to simplify the build to one type of standard kit and its associated expansion kit.

During the rebuild of the physical robot to include a single Lego Kit the robot base size grew by approximately 1.5 inches when the EV3 treads system was used. This made the initial design of the field inadequate to hold the robot. Resizing the squares to 12 inches will further shrink the effective playing field.

From left to right: Karel the Robot model 2.0 (single Lego set) and model 1.0 (two Lego sets).

 

Command Structure

The commands available to control Karel the Robot are Go, Left, Right, Get and Put. These are initially used in sequences and are later combined within decision structures (if-elif-else statement) and loops (repeat, while, for) to enhance both the logic and the syntax of the program as well as provide discussion for the three primary components of programming structure. Our initial intent is to make Karel the Robot as independent as possible with respect to movement, not relying on cues from the maze like line following. Get and Put commands would rely on control of the robot’s screen to display output with respect to number of objects.

Challenges

With the initial trials with respect to turning the robot, we discovered very quickly that there is an inherent lack of accuracy in the Lego parts. Variations in the motors, power applied to the motors, the treads, the maze and even the battery power all made for variations on the turn. Installing the gyroscope sensor on the robot allowed for measurement of the error, +/- 4 degrees on a 90-degree turn. It was evident that a self-correcting program was needed that would measure and seek the desired turn. Searches revealed programs for selecting the direction of the turn (left or right) and for controlling (and measuring) the amount of turn. Combining these two programs yielded a program that allows for precise turns with self-correction. The correction, however did allow the discovery of the inherent error in the gyroscope measurement. Measurement of the turn, when the gyroscope reads 90 degrees is currently at 90.8 degrees. The hope is that this error is consistent and, therefore, able to be programmed out of the turn.

Future Work

Currently students are working on refinement of the turning function, a true 12 inch Go Function and providing the Karel the Robot with the ability to recognize different colored objects which will be used to distinguish object within the mazes. They are also working on the physical aspect of the maze as additional materials are found which can provide for building.

Students are embracing the challenges involved in turning the robot ‘toy’ into a functioning tool. Even if the challenges prove to be insurmountable due to the nature of the Lego system as a toy, the experience for the students in confronting those challenges and discovering the limitations is proving to be invaluable as a learning process.