Sunday, June 24, 2012

My first steps: Day one

The "package"

This is the package that came from xyzprinters.com. It's so nice and compact. It contains almost everything we'll need to build my printer. Below you can see the plastic parts that Juan gave me. They are of superb quality.
The box :) 
Showing all the stuff
The printed parts

Here comes the first trick

So this is one of the most important things you have to know about printable plastics. You see these plastic cases, they were broken when we put the bearings inside them. Fortunately it's easy to fix this because the plastic is soluble to aceton.

Broken plastic? Don't worry use aceton.
Aceton is a chemical liquid very easy to find. Your girlfriend uses it to clean her nails from polish. But since you are here it seems very unlikely to have a girlfriend, and if you do she probably doesn't have nails and/or hands. This is no time for worries, though, for you can buy it in every supermarket or hardware store. I mean aceton not an able-bodied girlfriend.

Our good friend aceton
You can use a small brush to apply it where you need. The plastic will glue by itself in a few moments, but you'd better give it some time to properly dry.

Good as new
Just give it some time to dry
Finally the bearing inside their cases

The prusa triangles

For the most part of the chassis you can use Gary Hodgson's visual instructions. I use Juan's verbal instructions because there are a few things that have changed in prusa mendel iteration 2 from the original model.
So the best way to begin with is the two main triangles. Be careful with how you place the washers and the nuts cause if you do a mistake the later it sucks to dismantle the whole thing. A nice trick for aligning the two triangles is to use the rest of the rods as guides. Just for reference the nuts are size 13. 

Bottom plastic and threader rods
Use some other rods to help you with the alignment
The two main triangles
Don't tight the nuts too much, you'll need to make adjustments later
Again use some rods to make sure the alignment is ok

Front and back

This is the back and front of the printer. The motor of the y axis goes to the front. Be very careful with the washers and stuf. There is a difference here from iteration one. That extra nut between the big black plastic and the bearing is no longer needed. This also makes the aligning process later, easier.

The motor of the y-axis will be screwed to the black plastic
Another view of the front part
The triangles with the front part added
The back part also added
The upper part is finally added. It will hold the z-axis parts

End of day one

Happy working class people

Thursday, June 14, 2012

Saving and loading functionality to GML Adaboost Matlab Toolbox

adaboost training error on INRIA pedestrian dataset
Adaboost is a great efficient tool. It uses plain flavor decision trees to build a stairway to classifier's heaven. I am using it for human detection, in both the laser and the camera modules and it's behaving very well.
Of course it can be used in conjuction with much more efficient classifiers than decision trees. So the next step is integrating SVM as a weak classiffier to replace the tree nodes currently in use. Another work in progress is to use different criteria for cross validation in libsvm in order to have more control over it's behaviour.

A. Vezhnevets has developed GML Adaboost Toolbox for Matlab. Another seemingly interesting, but not so well known, matlab adaboost toolbox was written by Alister Cordiner. Myself I use GML right now but I was thinking moving to Cordiner's code cause it seems easier to integrate with libsvm.
Anyway GML is ok for now, except it has a small problem. It can't save and load the tree node objects within matlab. To be more precise, when I am trying to load the saved learners and the corresponding weight values it gives me the following error:
Warning: Element(s) of class 'tree_node_w' do not match the current constructor definition.  The element(s) have been converted to structures. 
I don't know if it's universal but this is what happens in my mac. When matlab saves an object belonging to certain class it also saves information about which class it belongs to. Then when you try to load that save file, and for every object of every class, it invokes the appropriate constructor. But in this case the constructor can't be used to load because it doesn't initialize all the properties needed. So what solves the problem is that the class needs two methods, namely saveobj and loadobj, to do the dirty job. That is converting the object to a simple structure when saving and the opposite when loading. Here is the new file. Use it to replace the original file in the @tree_node_w folder.

What have we gained:

  • Some insight to the object oriented aspects of matlab

Labels: ,

Saturday, June 9, 2012

kabamaprusa: Genesis

Ye shall be named kabamaprusa...

So, as foretold by the prophets, I've decided to document the "birth" of my 3D printer, kabamaprusa. There are a lot of good guides and tutorials out there, most of them outdated though, so there is no rationale for another one. This is not going to be an exhaustive how-to or step-by-step guide, but rather a photo album along with some instructions on how to circumvent building difficulties.  I am mainly motivated by two reasons. The first is that I'll need to reassemble the printer when I take it back to Greece. Here, in Spain, the Guru and Spiritual Lead3r Obi Juan is guiding me through the whole process, but given the goldfish memory I possess this is absolutely necessary. The second reason is that I'll try to give some tips & tricks on small problems that occur during the construction, which are unlikely to find in a guide. This troubleshooting, hopefully, could be useful to others too. So let's get going.

Introduction: Dad I want you to meet Printer.

The evolution of 3d printer models is so rapid that most of the guides you'll find on google are refering to the construction of then state-of-the-art but now obsolete printers. Even those one year old. But that doesn't mean that there is not good quality material that one can't refer to. Before commencing anything you should take a look at this site. It is a very good introduction to 3d printer construction. It refers to prusa mendel: iteration 1 (I'm building iter. 2 by the way). Here is a very thorough and downloadable visual guide for building an iter. 1 prusa. I actually use this guide but there are a few deviations from it for it. 2. The ultimate shrine for amateur 3d printers is reprap.com. You can find almost any information you need, no need to explain just go and see for yourself. If you know spanish you can have a look at  Juan's site iearobotics.com which is full of usefull information.

Parts sourcing: Where to get the really good stuff.

Let me start buy telling that you can buy a kit (even preassembled) from any printer you like. From cheap and small printers like makible and printrbot (which was the first kickstarted 3d printer apparently) up to makerbot's replicator. You can also buy a prusa mendel it. 2 from many stores. You can check thereprapkitstore.co.uk for one of them in the best price I've come across, while availabillity can often be an issue.
In flesh and bones
For buying the parts seperately there are a lot of good hardware stores. See this buyer's guide for a comprehensive list. If you live in Europe I would highly recommend xyzprinters.com. It's a Dutch site with high quality products. Their nema stepper motors have the best torque I've seen, in specs at least. They also have very competive prices. Also I have to mention that their customer support is very friendly and helpful - muchas gracias Henriette! The only downside is that they don't sell the printed parts. Generally speaking, having a friend print you the plastic parts will save you a lot of money, and it's not so difficult as you think nowadays.
Well, there is one obvious advantage for buying a kit: no need to worry if you forget something, or if you got the right part etc. The downside is that they usually cost more and they are more often out of stock than not. But since this is a swiftly evovling market you can expect things to have changed when you'll be reading this.

Labels: , ,

Tuesday, June 5, 2012

3D εκτυπώσεις στο σαλόνι σου. Ναι είναι δυνατόν.

Να πω την αλήθεια πριν έρθω Μαδρίτη δεν γνώριζα για του 3D εκτυπωτές. Τις πρώτες μέρες εδώ στο εργαστήριο βρέθηκα μπροστά σε ένα τέτοιο μηχάνημα και μπορώ να πω πως εντυπωσιάστηκα. Οι δυνατότητες που δίνει για κατασκευή πρωτοτύπων (και όχι μόνο) είναι ασύληπτες. Αυτές οι δυνατότητες αυξάνουν κατά πολύ τους βαθμούς ελευθερίας για πειραματισμό, είτε είναι κάποιος ευρευνητής είτε απλά χομπίστας. Μαζί με άλλες τεχνολογίες open source (arduino κλπ) τα όρια για τα homebrew projects επεκτείνονται συνεχώς. Στο παρακάτω ted talk ο εκδότης του περιοδικού make μιλάει, ή μάλλον εμπνέει, για την κοινότητα των ερασιτεχνών εφευρετών:

Ας επιστρέψουμε στο θέμα μας. Για να πάρετε μια ιδέα για τι μιλάω, όσοι δεν γνωρίζετε, δείτε το παρακάτω βίντεο-teaser. Πολύ ενδιαφέρον και αυτό το ted talk.


Η φιλοσοφία της λειτουργίας τους είναι πολύ απλή. Το υλικό που χρησιμοποιείται για την εκτύπωση είναι πλαστικό το οποίο θερμαίνεται και λειώνει στην κεφαλή του εκτυπωτή. Κινητήρες ακριβείας (step motors) φροντίζουν για την κίνηση της κεφαλής και του υπωστρώματος εκτύπωσης (print bed).
Η τεχνολογία των 3d εκτυπωτών είναι διαθέσιμη εδώ και δεκαετίες. Γιατί τόσο μεγάλη άνθηση τα τελευταία 2-3 χρόνια; Κυρίως γιατί η τιμές των υλικών που απαιτούνται για να φτιάξεις έναν έχουν μειωθεί κατά πολύ, ενώ η διαθεσιμότητα τους έχει ακολουθήσει την ακριβώς αντίθετη οδό. Σε συνδυασμό με την αντίστοιχη ανάπτυξη σε open source πλατφόρμες λογισμικού, όπως το arduino, δημιουργήθηκε μια κοινότητα με κρίσιμη μάζα που οδηγεί τις εξελίξεις με απίστευτο ρυθμό. Από τους ελάχιστους και πανάκριβους που υπήρχαν παλιότερα σήμερα είναι σχετικά εύκολο και οικονομικό να φτιάξεις τον δικό σου τρισδιάστατο εκτυπωτή.
Prussa Mendel
 Ο εκτυπωτής του βίντεο είναι εμπορικός και κοστίζει περίπου 1800$. Αρκετά φυσικά. Όμως πέρα από την υψηλή τιμή το άλλο μεγάλο του μειονέκτημα είναι ότι δεν είναι αυτοαναπαραγούμενος (self-replicating). Σήμερα η κοινότητα των ερασιτεχνών έχει εστιάσει στην δημιουργία μοντέλων 3d εκτυπωτών οι οποίοι μπορούν να αυτο-αναπαραχθούν. Να τυπώσουν μόνοι τους, δηλαδή, όλα τα πλαστικά μέρη που χρειάζονται για την κατασκευή τους. Φυσικά ένας εκτυπωτής χρειάζεται ακόμη πολλά μεταλλικά και ηλεκτρονικά μέρη αλλά η ιδέα είναι απλή. Αν έχεις έναν RepRap εκτυπωτή (το πρώτο ερασιτεχνικό μοντέλο που διαδόθηκε ευρέως) μπορείς να φτιάξεις τα κομμάτια για τους φίλους σου κ.ο.κ. Αυτό φυσικά ώθησε στην τεράστια εξάπλωση τους. Ας αναφέρω εδώ ότι κάποιοι ήδη οραματίζονται πλήρως αυτοαναπαραγούμενες μηχανές, που θα φτιάχνουν και τα ηλεκτρονικά τους μόνες τους, αλλά αυτό μας πάει πολύ μακριά.
Παράλληλα υπάρχει και εξέλιξη στο σχεδιασμό καθότι από τη γενιά 0 του RepRap περάσαμε στην πρώτη (αξιόπιστη) του Mendel και τη δεύτερη του Prussa Mendel ενώ σιγά σιγά κάνουν την εμφάνιση τους και πιο καινοτόμες κατασκευές . Με μια απλή αναζήτηση βρίσκεις πολλά ακόμη ερασιτεχνικά σχέδια για κατασκευή 3d εκτυπωτών βασισμένα στα ανωτέρω μοντέλα. Το κόστος κατασκευής ενός Prussa Mendel κυμαίνεται μεταξύ 400 - 500 ευρώ και βαίνει συνεχώς μειούμενο. Η κατασκευή δεν είναι και το πιο εύκολο πράγμα, καθότι απαιτεί πολύ υπομονή. Ευτυχώς υπάρχει αρκετό υλικό στο διαδίκτυο, κυρίως στα αγγλικά.
Ο σχεδιασμός των αντικειμένων γίνεται με προγράμματα 3d επεξεργασίας όπως openscad ή autodesk inventor. Πριν εκτυπωθούν είναι αναγκαία η αποθήκευση τους στη μορφή που "καταλαβαίνει" ο εκτυπωτής (stl). Αν δεν είσαι πολύ καλός στο σχεδιασμό, μπορείς να τυπώσεις πράγματα που έχουν φτιάξει άλλοι χρήστες, απλά κατεβάζοντας το αρχείο απ'το ίντερνετ. Τι πράγματα μπορεις να τυπώσεις; Δεν φαντάζεσαι.
Κάπως έτσι αποφάσισα και γω να φτιάξω των δικό μου εκτυπωτή 3d με τη βοήθεια του γκουρού και φίλου μου Juan. Το μοντέλο που θα φτιάξω είναι το prussa mendel. Στην αγορά υπάρχουν και μικρότερα/φθηνότερα μοντέλα αλλά έκανα αυτή την επιλογή πρώτον επειδή ο συγκρεκριμένος είναι ένας πολύ αξιόπιστος/δοκιμασμένος/τεκμηριωμένος  εκτυπωτής και κατά δεύτερον γιατί μέσω της διαδικασίας κατασκευής θα μάθω και δυό τρία πραγματάκια. Ο φίλος μου ο Juan μου εκτύπωσε τα πλαστικά μέρη του εκτυπωτή μου σε άψογη ποιότητα, να ναι καλά. Του πήρε 20+ ώρες, ξέχασα να αναφέρω ότι η εκτύπωση είναι πολύ αργή. Σήμερα ήρθαν και τα υπόλοιπα πράγματα και ξεκίνησα την κατασκευή. Αποφάσισα επίσης να καταγράψω την διαδικασία για δύο λόγους. Πρώτον γιατί  δεν έχει γίνει κάτι αντίστοιχο στα ελληνικά, ελπίζοντας να παρακινήσω και άλλους. Δεύτερον γιατί ο σκοπός μου είναι να δώσω tips σε προβλήματα που ανακύπτουν και όχι να παρουσιάσω έναν πλήρη οδηγό.. Hasta luego!
Τελετή παραλαβής - παράδοσης. Mil gracias Juan.

Labels: , ,

Sunday, June 3, 2012

how to use a firefly mv camera with matlab on macos x

I am developing an algorithm for pedestrian detection using a laser range finder and a camera sensors. Well for the laser I'm limited to the currently available Hokuyo-URG04LX. But since there are quite a lot of cameras available in the lab it's more difficult to choose. The last few days I am messing with a Firefly MV FMVU-03MTM monochrome camera. It has two advantages:
  1. It's very rigid and can be screwed to a base. This is great since we want the camera to be in a fixed position in respect with the laser.
  2. It has a much much bigger sensor, which mean less noise, and better lense than any other available webcams I've tried. UPDATE: beware that lense comes with a noticable distortion
For the development I'm using matlab but the final implementation will be on opencv and ROS. So I had to see if it works well with these tools. There are a few tutorials already on how to make a Firefly camera work under ubuntu, ros, opencv. If you're interested in this you can have a look here. There is also a matlab mex wrapper for the dc1394 library from barryk, here. The problem is that the latter didn't work on my mac.
The libdc1394 examples work great but the wrapper doesn't seem to work. I tried downgrading to version 2.0.1 of libddc1394 but this didn't solve the problem either. So after two days of debugging I decided it's time to write my own wrapper of libdc1394 for matlab.

UPDATE: It was too difficult to abandon barryk's wrapper, since it's a great piece of code plus I'm too lazy. So I was using it along with some examples from libdc1394 to understand how I should proceed. After some more (and more and more...) debugging I realized what seem profound from the beginning: the guid of the camera is TOO big to fit into a uint32_t variable. So I changed some declarations and casts, within the camera initiation function, to uint64 and now it works.
To compile the whole think I've used the source files from libdc1394 directly, because using the library led matlab to crash. Also I had to make some changes to the filenames to avoid compiler misinterpretations. Here is the compiling command that I've used.
/Applications/MATLAB_R2011b.app/bin/mex -g dc1394mex.c bayer.c capture_gen.c control_gen.c conversions.c enumeration.c format7.c internal.c iso.c log.c register.c utils.c  -lIOKit -L/opt/local/lib /opt/local/lib/libusb-1.0.dylib -lm  -I/opt/local/include/libusb-1.0/ usb/capture_usb.c usb/control_usb.c macosx/control_mac.c macosx/capture_mac.c vendor/avt.c LDFLAGS='$LDFLAGS -framework Carbon -framework CoreFoundation -framework CoreServices' CFLAGS='$CFLAGS -Wall' -o dc1394
You can ommit the -g parameter. The renames are obvious if you compare them to the original libdc1394 source file/directory structure. This file contains all the source files from libdc1394 you'll need, renamed, plus the dc1394mex with the aforementioned modifications. God speed.
UPDATE: I've corrected the function that sets the feature mode and written a new one for setting manual values to them. I've also added support for gamma. I did all this because I had noticed a very strange flickering. At first I thought it might come from auto or semi-auto settings not being calibrated very well so I needed to manually set the features. Nevertheless the problem was caused by the room lighting, see here a related article from ptgrey. And here are the new files.

Things I've learned along this way:
  • writing matlab mex files  
  • debuging matlab mex files
  • steping into external libraries while debuging
  • using mac's ioregistryexplorer
My setup is: Macbook Unibody Late 2008 with intel core 2 duo, MacOS X Lion 10.7.3, Matlab R2011b
Libraries: libdc1394-2.2.0, libusb-1.0.8

Labels: , , , ,