Karel R Tuesday Simulator

To run the Karel R Tuesday Ruby simulator you will need Ruby and Tcl/Tk installed on your machine. You will also probably want an IDE in which to develop programs.

Here we will show how to set up a Windows, Linux (Ubuntu), or Macintosh system using the simulator under Eclipse. There are four steps. All but step 2 are the same for all systems.

 

Step 1.

For both systems: Get Eclipse from Eclipse.org and install it. Get the classic edition or the Java Programmer edition, but NOT the EE edition, as it is too complex. The latest version is not essential, so you may have it already. I've had this work under Helios, Europa, and Juno versions.

Step 2.

Get Ruby and Tck/Tk installed: (The latter is a graphics system, originally built for Perl).

On a Windows system this is a bit easier than the others. You probably don't have either installed, but can get them both together, from http://rubyinstaller.org/downloads/.Get the latest version (1.9.3 or later) packaged in an installer (not the zip version). And execute the downloaded exe file (an installer). Install it to the default location and be sure to check the three options you are given (tk, path, and .rb files). You are done with step 2 but want to test it. Open a command window and type

irb

This is the interactive ruby shell. In the shell type

require "tk"

If you get a respons of "true" you are good to go. Leave irb with exit. Now go to Step 3.

On Linux (Ubuntu, at least). There are many variations of Linux so this may not work for other "similar" systems. There is more complexity here than for windows. You may have Ruby 1.9 and Tcl/tk already installed. Look in /urs/lib/init.tcl. It would be a good indication that you have some version. In a Terminal window type

ruby -v

If you have ruby it will tell you the version. If it shows 1.9 you should be fine. To be sure, open a command window and type

irb

This is the interactive Ruby shell that you should have if you have Ruby. In the shell type

require "tk"

If you get a respons of "true" you are good to go, so leave irb with exit and go to Step 3.

If you need to install anything do this - in this order:

(a) You need the developer tools installed. Use your package manager to get the GNU toolkit if you don't have it already.

(b) Get Tck/Tk from http://www.activestate.com/activetcl/downloads Get the free community edition and install it. The linux version is a tar.gz file. Unzip it and cd to the resulting folder. Give the command

sudo sh install.sh

It will give you an installer dialog. On three screens you need to enter directories. The defaults failed for me. I was successful in using /usr, /usr/demo, and /usr for the three directories. Note that /usr is an important directory, so use caution in writing into it. But it worked for me. Eventually click Finish to complete the install.

(c) Download and install Ruby. Get Ruby 1.9.3 or later from http://www.ruby-lang.org/en/downloads/ Get the source code version (a tar.gz file) and unpack it by double clicking. Open a Terminal window and cd to the ruby source directory you just unpacked. Decide where you want to install the new version. I used the default. Then issue the following command (edit it for a different destination - see the Macintosh version of these instructions for how to do this.):

./configure --enable-pthread --enable-shared

It will take a while. Then (you need an admin password for at least some of the rest) give the command:

make

This will also take a while. Then

sudo make install

It asks for an administrator's password before it will continue. You may also need sudo for the first make command (sudo make instead) but you certainly do for "make install" as it will move things into your final directory, which you probably don't own. This will also take a while.

You should now have ruby and tk installed. If you installed it in a non-standard place you will need to make your PATH point there, but I'll assume you used the default. Test it as above, if you like. Now go to Step 3.

On a Macintosh it is a bit more complex, but similar to Linux. You already have Ruby, but an older version. You don't have tk graphics. You want to download the latest ruby along with Tck/tk and rebuild ruby to take advantage of tk. You probably want to install to a new location, not over the original ruby, so you also need to set your PATH variable so that the new version will be executed. Here are the steps. The following seems to work under both Lion and Snow Leopard. I haven't tried other systems.

(a) Get XCode from the apple store if you don't have it. Install it as per Apple's instructions. If you do have it, it will be in Applications, most likely. You probably don't need the latest version, but might.

(b). Get Tck/Tk from http://www.activestate.com/activetcl/downloads Get the free community edition and install it. It comes with a mac installer.

(c) Get Ruby 1.9.3 or later from http://www.ruby-lang.org/en/downloads/ Get the source code version (a tar.gz file) and unpack it by double clicking. Open a Terminal window and cd to the ruby source directory you just unpacked. Decide where you want to install the new version. I used /opt/local/bin. Then issue the following command (edit it for a different destination):

./configure --prefix=/opt/local --with-arch=x86_64,i386 --enable-pthread --enable-shared

It will take a while. Then (you need an admin password for at least some of the rest) give the command:

make

This will also take a while. Then

sudo make install

It asks for an administrator's password before it will continue. You may also need sudo for the first make command (sudo make instead) but you certainly do for "make install" as it will move things into your final directory, which you probably don't own. This will also take a while.

You should now have ruby and tk installed.

(d) Set your path to point to the new installation: In your terminal window, cd to your home directory (cd #). Type:

ls -a

The resulting file listing includes hidden files. Look for one called .profile (name begins with a period). You may have it or not.

If you do NOT have .profile, give the command below in the terminal window (exactly, but editied to include your install directory if you changed it)

echo export PATH=/opt/local/bin:/opt/local/sbin:$PATH > .profile

Capitalization, spacing, etc is all critical in this command. You should now have a .profile file and if you

cat .profile

it will show you the contents including the path you set and some others.

If you DO have a .profile already do this instead: In the terminal give the command

open -a TextEdit .profile

It will put the contents into TextEdit where you can edit the PATH. You can just add the following line to the bottom of the file if you like:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Save the file and exit. Your path should be set.

To check your path type in the terminal

echo PATH

and you should see the actual path, including the /opt/local/bin... directories at the start. The command

which ruby

should now show

/opt/local/bin/ruby

WHEW. DONE.

Step 3.

Get Aptana Studio3 installed in Eclipse. Go to http://www.aptana.com/products/studio3/download This is a Ruby environment for Eclipse.

Click the Eclipse Plugin radio button, and then Download. It will show you a url like the one below (perhaps a later version).

http://download.aptana.com/studio3/plugin/install

Copy the URL to your clipboard - don't just click it. The same window has instructions to follow, repeated here:

Open Eclipse in some (new) ruby workspace

Choose: menu Help/Install New Software. You will go through a set of dialogs.

In the Work With field, put the url above and click Add
Name it Aptana3 in next dialog.
Click Select All in next dialog, then click Next>
Review what you are about to do in the next dialog, then click Next> again
Acccept the terms and click Finish
It will install, but will take a bit of time
Restart Eclipse

You should now have ruby and tk properly installed in Eclipse.

Step 4.

Get the Karel R Tuesday simulator installed. First, download the zip from the Karel pages. Don't unzip it, but remember where you saved it.

In Eclipse, from the File menu, select Import...

In the dialog, click General, then Existing Projects Into Workspace, click Next
Click Select Archive File (radio button) and then Browse.
Navigate to the book distribution file's zip you downloaded and choose it.

Make sure the project KarelRTuesday is checked (and any others NOT checked) and click Finish

You should have the project in your workspace. If Eclipse offers you a Ruby Perspective, use it, but otherwise, use the Java Perspective (NOT the Web perspective).
Open KarelRTuesday and the default folder
Double click pg13.rb. This is a sample file from near page 13 in the book.

If you don't like the colors (I hate them) select the color wheel at the top of the window and select a new theme (say, Eclipse)

In The Eclipse Prefrences select General/Editors/Text Editors
Click Insert Spaces for Tabs and Show Line Numbers
Click Apply and OK

Right click in the pg13.rb window and select Run As/Ruby Application
It will fail. But that is the easiest way to set up a configuration. Now you have to correct it.
Select Run/Run Configurations. It should open to the configuraton of the file you just tried to run.
Click Arguments (in the right pane). In the Interpreter Arguments section add the following (dash, capital I, quote, ...)
-I "./../karel"

Click Apply and then Run. It should succeed. You should see a robot window and a running robot executing a simple program.

You can now write your own Karel R Tuesday code.

Put your own code into the default directory, or create one at the same level and use that. Every file you want to run should have a suffix of .rb and each will need to have the same interpreter arguments as we show above for pg13.rb (-I "./../karel")

If your monitor screen is small (my Linux box has a 13" screen) you will have a bit of trouble. In Eclipse, select Search/File Search and search for the value 800. Ignore it in any html files, but in ruby files, change it to a smaller value, such as 600, save the files and try to run again. It should look better.

 


Last Updated: July 10, 2012