WiiScheme

Friday, May 9, 2008

New Instructions!

We received new instructions from Sinan last week on Monday. Since there's been no posting here for a while I decided to post about the progress of our research.

On monday, during a regular “poking session” with Sinan about preparing the official papers to buy some Wii Remote for the department, he told me they were almost ready and we should start preparing a dummy teachpack. He also told that it was not as easy as it looks and we should do some research about them first. I've been going through some MzScheme manuals and Help Files on my free times and found out that there are two ways of extending DrScheme: Teachpacks and Tools. Tools are designed for extensions on DrScheme's functionality, like a debugger, syntax checker, or buttons for some other stuff, so we won't be needing them in our project. What we actually need are:

Teachpacks

Teachpacks are sets of procedures which place themselves into a language in DrScheme. They are basically libraries, providing the coders to use previously defined functions for them to use when needed. As an example, the world.ss teachpack is a library and the Big-Bang is a defined function within the library, which we can use if we add the teachpack to the programming language in DrScheme. That and the other functions in the teachpack are basically defined functions, like the ones we do in our projects, but built into a single file in a stack for use.

Why use Teachpacks?

There are three main opportunities teachpacks provide us;

1- The academic use of DrScheme may require students to implement codes they won't be able to.

Let's say a teacher wants his first year students to prepare a project in DrScheme every week. Think of how boring it would be to design and implement functions which only calculate some stuff and return values based on the input. Anyone could easily get bored within 3 weeks maximum and I can bet on that everyone will start to lose motivation rapidly. Because everyone still knows only the basics of Scheme, no one is able to implement some code which provides visual output, or use mouse movements, clicks or keyboard events as input to prepare a project which's fun in the end. Right here come teachpacks into the scene; They provide the functions necessary to do all those fun stuff so the students can focus on their work and have fun at the same time. They even can create simple games (such as breakout) using only their knowledge and the teachpacks with the necessary codes built in.

2- The most commonly used functions can be implemented into and called from teachpacks.(Or “Abstraction” if you like to use no more then one word)

In our projects, we always try to implement generalised functions to be able to use them in our later projects. If we, let's say, create multiple teachpacks for each kind of theme (such as list processing, drawing, playing sounds ect.), we'd just need to add the teachpack to DrScheme and use the functions whenever we need them, without having to design and implement them over and over again. This is a commonly used thing during the development process of any kind of software. I am building libraries of the things I do a lot when I'm programming as well, and I'm using them on other projects when I need.

3- The more powerful implementations of Scheme may be used within the less powerful ones

Well, the title says it all. You can prepare a teachpack with the advanced student language in DrScheme with keywords, which don't exist in the beginning student language. Let's say we want to draw a circle to the screen using the beginning student language. Because the beginning student language doesn't have the “circle” function defined within, we can't do that without using a teachpack which was written in a more powerful teachpack which provides us the function needed. (Think or world.ss: It needs lots of imperative functions to be able to run, but when you add world.ss into Dr.Scheme, you don't even have to know what “imperative” means when you're designing and implementing an animation.)

Why do we need to prepare a teachpack?

Our ultimate goal is providing a way to use the WiiMote on the DrScheme environment to be able to do stuff like these, which should be as simple as a first year student's regular project. Well, that's not possible without the use of a library. It's a pretty big and complex job to do that, and to simplify it, we're going to use the help of teachpacks. Just like we use world.ss for mouse and keyboard inputs, we want the students to be able to use the input from WiiMote as well. Without teachpacks, they would have to design and implement complex functions to “listen to what WiiMote says”. We will also have to use a more powerful language to access the input the computer receives from WiiMote to do that.

Alright, we're going to prepare a teachpack, but how?

It's not that much different from everything we did in class this year. First we should build a module, in which we will place everything else. Just like this:

(module dummy mzscheme

...)

The “module” function is the main function of the teachpack; everything in the teachpack must be in that function, otherwise it wouldn't work. The first parameter the function receives is the name of the teachpack, and it should be the same with the name of the teachpa

ck file we are going to create: “dummy.ss”. The second paramether is the language of the teachpack we are going to use. I chose mzscheme for the example teachpack. Note that the language you are using during the implementation of the code should be mzscheme also. Now let's keep going:

(module dummy mzscheme

(require (lib "defmacro.ss" "mzlib"))

...)

The “require” function adds the requested library to the code, just like adding a teachpack into a project. The “defmacro.ss” library is required for defining macros. The “lib” function just calls the file in the folder in DrScheme's “collects” folder. In our example, it calls “.../PLT/collects/mzlib/defmacro.ss” file and lets us use it. Let's define a function now:

(module dummy mzscheme

(require (lib "defmacro.ss" "mzlib"))

(provide addfive addthree)

(define-macro (addfive n)

(+ 5 n))

(define (addthree n)

(+ 3 n))

(define (addtwo n)

(+ 2 n))

)

With the “provide” function we're telling the program that we're going to define “addfive” and “addthree” functions for external use (external use as in the user will be able to call those functions). Just below that, we define a macro and some functions. Defining a macro is not necessary actually, I defined one just so you can see the benefits of the library we added. After doing that, we can now save our file with the .ss extension and use it as a teachpack. Note that the addtwo function cannot be used because it was not provided to the user.

We, of course, are not limited to defining functions. We can define variables and keywords for use as well.

(module dummy mzscheme

(require (lib "defmacro.ss" "mzlib"))

(provide addfive addthree helloworld)

(define-macro (addfive n)

(+ 5 n))

(define (addthree n)

(+ 3 n))

(define (addtwo n)

(+ 2 n))

(define helloworld "Hello World!")

)

Here's what happens when we call the functions built into the teachpack we've just prepared:









As you can see above, we can call the addfive function, addthree function and helloworld variable without any problem. But addtwo does not work, because it was not provided to the user.


The teachpack for the use of WiiMote will not be this simple of course, it will require a way more complex type of coding. But the main idea is the same. The next step in our project is hopefully getting our hands on a WiiMote, and find a way to receive input into DrScheme from it.

Tuesday, April 15, 2008

Progress Report No:2

Finally our studies are finished about the exact road plan about the project and it's components.

Considering the limited capabilties of the drscheme environment Ali is studying alternate ways to complete the project in case anything goes unexpected. That means we have an 'incomplete' backup plan.

Current assignments for the time being is as the following:
Aytaç: Manipulating world-bilgi.ss teachpack so that it can read inputs from the linux wiiremote driver.
Fırat: Connecting the Arduino board to drscheme in a linux environment.
Gökhan: Studying the architecture of the arduino board and doing the assembling work.
He did a damn good job about the IR-pens.

Aytaç Kanacı

Friday, April 11, 2008

board marker to IR-pen

This is the second type of IR-pen that I made

CAUTION: Be careful while using soldering iron and hot wax gun. Accidentally touching the hot parts may cause serious burns.

-Find a board marker (you can steal one from your teachers :) ) and disassemble it. - Ready the parts that you will use: IR-led, a 22 ohm resistor, a button, a spring and some cable. - Cut the back of the board marker and put the cable soldered spring from the back. You may prefer to not to cut the back and put the spring from the front but its a bit difficult.

-Use some hot wax to fix the back end and the spring.- Mount the button on the body of board marker. You can use the soldering iron to melt the body but it will smell bad. If you use soldering iron to melt the body, don't forget to clean the tip of soldering iron. Also solder the resistor to any leg of the IR-led. (I prefered "+")


-Solder the cable from the spring to button. Also solder a small metal string(i used the part that i cut from the IR led) to the other leg of the button.

-Insert the IR-led and the resistor trom the tip of the board marker. Leave one leg of the IR led out. Use some glue and conductor foil(I used cigarette paper but aluminium foil is more suitable) to wrap the leg that you left out.

-Re-assemble your board marker. You may also want to use some insulation tape for the make-up.

Labels:

How to make a simple IR-pen

We needed a few IR-pens to use with wiimote. So after a few reading I made some samples.

If you don't want to work with a soldering iron and a hot wax gun, you can always use a simple lighter with a LED lamp instead of an IR pen. If you prefer this just change the LED with an IR diode.

CAUTION: Be careful while using soldering iron and hot wax gun. Accidentally touching the hot parts may cause serious burns.

-Buy a simple flash light and dismount it.













-Use soldering iron to heat the metal part of the lamp and detach the glass part from the metal part.




















-Mount the IR-led to the place where you detached the glass part and solder it. Be careful about the poles of the IR-led. In standard leds, long leg is connected to the anode(+) of the battery.














-Cut the parts that you don't need. need.












-Just re-assemble it and your first IR-pen is ready.




Note that most of the flash lights use switches. If possible change the switch with a button.

Labels: