Fighting with computers

Computers are not always friendly.

Sunday, March 25, 2007

Vertical Painting device

I've been working for a while on this project but now I've reached something close to a 0.1 version. I just suck at mechanical devices design. The system is copy of a similar project done at Cornell University and at école cantonale d'art de Lausanne but it happened to be more of a challenge that I assessed initially. Now that it is up and running I am using it to ease the process of transfering drawings to a canvas. I still have to discover why I am getting a 12% compression on the y-axis but in the mean time I can easily compensate for that.

I wanted to use a solenoid for the pen up and down control but I did not manage to get a reliable behavior so I am using a third stepper motor I ripped off from a floppy drive (I use two stepper motors for controlling the two hanging strings). I am using coal sticks to draw over the canvas and I've noticed that next version will need to include a compensation of the wear of the coal (as it gets shorter as lines are being drawn) to avoid the system to stop drawing when only half work is done.

My project is entirely controlled by a PC using Visual Basic code.

Update: For those of you so lazy that cannot click thru read on the slides below to get a more detailed explanation of what this thing is about:

Saturday, March 17, 2007

Regular Expressions in ... Visual Basic .NET?

A recent project required me to use Windows while I figure out how to write a driver for a USB-based stepper motor driver I am using. I decided to see how Visual Basic works in this new and glorified .NET version (my last experience was with VB version 6 and it was a pleasant one).

So I downloaded the free version (called Express) of Visual Basic 2005. I am doing so because this way any advice I can give to others may include the usual "you may want to use this software" without having to add "it will cost you so many dollars". Because most of the time I'm giving advice to my students it seems an ok approach to me.

The only "requirement" to use this software for an unlimited amount of time is to give away some personal info to Microsoft. I've found the deal ok this time.

The new version includes a browser window on the user interface that makes the loading time longer and I am sure I will be happier without it (maybe it can be easily disabled).

I was not happy to learn that some old traditions no work like the ancient Open command. And things like Line Input seem to have given way to more Java-like structures like the StreamReader which makes you wonder how many other things have changed on this transition to the .NET framework. My guess is that a lot and I guess that many programmers are not very happy.

However, some changes are good. I was doing a part of a small project where I needed to parse an SVG file. I am familiar with the string handling commands usually available in Basic dialects (Right, Left, Mid, Len, etc). However my current task seemed to be better done with perl and regular expressions. Just in case I googled to see if any support was available and I was pleased to see that VB.NET includes a nice support for such a feature (not yet sure how efficient it is).

Some dark magic is needed first, like adding Imports System.Text.RegularExpressions in your file to get access to the proper class names. The next sample of code shows you how to get the coordinates from lines like this "....M123.456 789.123...."

Dim re As New Regex("M(\d+\.\d+) (\d+\.\d+)")
Dim m As Match
For Each m In re.Matches(line)
lastx = Val(m.Groups(1).Value)
lasty = Val(m.Groups(2).Value)
Console.WriteLine(lastx & " " & lasty)

Nice addition!!

Although I was not aware of it, some support for regular expressions was already available on VB 6.0

Wednesday, March 07, 2007

Timing belts and pulleys

When I started the project of creating my own version of Hektor I thought that the most difficult task would be something related with the software or the stepper motor controller, but I was wrong: The most difficult part has been finding the right hardware parts. More exactly, finding a local supplier.

While getting a USB 3-axis stepper motor controller on eBay was easy, even though it was coming from Australia it didn't take long. Finding the right toothed pulleys and belt it is being a nightmare, as local suppliers do not have "small size" elements nor a fast delivery. Should I have bought everything online I will be done now.

To be honest I was not even aware I would need that type of transmission system. My first impression was that it could be done with just some type of string, but after several failures I had to admit that toothed belts was probably the smart way to go. But then it was kind of late as I had the rest of components laying on my desk. After visiting the shops of several local suppliers (some of them thought I was kind of crazy for asking for open ended belts) I am expecting to visit one that seems to have what I need (but I do have an eBay contact that it will be happy to ship to Spain too).

Once again it is clear that the Devil is in the details.

Sunday, March 04, 2007

Grayscale with ImageMagick

I use command-line ImageMagick's graphics file handling software. It usually rocks and it use to be easy and simple to use, for that I love it. However, I've been fighting now for more than one hour to get it right.

What I wanted was to convert to grayscale a set of JPEG files I had on a folder. There are a couple of annoying things with ImageMagick:

  1. Once you use wildcard as the command source file (i.e. mogrify -resize 1024x768 *.JPG) then it seems to take a long long time to work. The reason seems to be the command reads and stores in RAM all the files BEFORE the magic starts. The result is a poor user response time (and sometimes an almost frozen system if you run out of memory and all the time is used paging). I use to change to use a for loop instead, with some "progress information" (i.e. for i in *.JPG; do mogrify -resize 1024x768 $i; echo $i " done!"; done )
  2. I do not convert to grayscale every week, so I cannot remember how to it. Here is when the trouble starts because the easy way is somehow obscure and several Google searches did not give the right information fast enough. The simple way seems to be mogrify -type Grayscale image.jpg but I was fooled instead to use the -colorspace parameter which produced no visible results but a full-color image file. So you know, next time you want to use this old tool you better write down your "magic" commands before it is too late.