Thursday, November 10, 2011

A Song Of Ice And Fire

Remember all those endless pages with elvish written songs in the Lord of the Rings books? Well I do, and they were as fun as writting an ethics essay in university (for the record: that was not fun at all)... I didn’t think I could go through that again so when half a year ago a friend of mine gave me "The Talk" about the awesomeness of this "new" book saga called A Song of Ice and Fire, I just unplugged my brain and started picturing old simpsons episodes in my head while nodding in approval.

... and by "old simpsons episodes"
I meant half naked girls with dragons.

Casually, a couple of months later my girlfriend downloaded the HBO Series based on the first book “A Game of Thrones" (Viva la Pirateria!). We watched the series 10 episodes in a week (it would had been a couple of days if we hadn’t had to work). By then I was totally determined to read the five available books whatever the cost... Unfortunately $80 bucks for every book was way out the budget I had for "whatever the cost" so I decided to sacrifice 10 years of blessed good sight by reading them all from the screen of my ipod.

Totally worth it

I can say without doubt that I haven’t seen a story so epic since the Bronze Saints fought in Asgard. Not even Goku turning into a goddamn Super Saiyan or Obi-Wan letting Anakin to die in a river of fucking lava were as emotional and exciting as some chapters, specially from the third book ("A Storm of Swords").

This is you understanding the epicness.

I'm not a book reviewer, I don't even consider myself a devote reader, I'm just a consumer and what I expect from a book is to be well and truly entertaining... and damn it was! Treason, sex, violence, wars everywhere, honor dilemmas, “zombies”, lots of winning quotes and even some dragons!... trust me punks this is like The Expendables of fantasy books! 

There are so many things I could say about this saga... but I really should be doing other important stuff right now. *cough* thesis *cough*, also I think it's better for you to find out that stuff for yourselves.  Meanwhile I'll let you with my favorite lines from the books.

"Those are brave men. Let's go kill them." « Tyrion Lannister (A Clash of Kings)
“There is only one god and his name is Death. And there is only one thing we say to Death: “Not today.” « Syrio Forel. (A Game of Thrones)

“I seldom fling children from towers to improve their health. Yes, I meant for him to die.” « Jaime Lannister. (A Clash of Kings)

"Rhaegar fought valiantly, Rhaegar fought nobly, Rhaegar fought honorably. And Rhaegar died." « Ser Jorah Mormont (A Storm of Swords)
"Don't make me rue the day I raped your mother." « Roose Bolton (A Dance with Dragons)

That's all folks, now read it! I command you!

Friday, October 21, 2011

Dōmo arigatō, Mr. Roboto


"Robotics has always fascinated man, because let's face it, it's awesome to play god... We humans are vain fuckers. "
~ Me on Robotics

Robots are awesome, don't let anyone tell you otherwise, from evil science fiction police robots to awesome real robots that rock all day long, robotics is full of winning. I dare you name one lame robot in  history... ok, C3PO sucked ass but hey, even him could speak 6 million languages.

"woo arrrr moo ar gah" (that's "fuck you" in wookie)

Truth is that we were born too soon and we won't live long enough to see robots like C3PO saving any galaxy. However, we have pretty impressive machines right now, like robots that wonder in other planets just like you do in your living room, or creepy robotic hands that cut you open and play with your insides.

"Yep,  straight out of your favorite horror movie"

Sadly, robotics is not all beer and strippers, sometimes robots can be as fun as a handbag full of snakes. For instance: isn't frustrating when yor are at your first robotics class and can't even find a robot's location from a camera point of view?... Well, maybe not, but in case you're reading this, you probably ended up here googling how to resolve that tricky stuff.
 
Let's get started

First, it's very common in robotics to use two or more coordinate frames to solve a problem. Industrial robots for example, use cartesian coordinates (height, width and depth) to move an object across the space.

Now, let's say you have a camera looking to a robot's 3 dimensional workspace from above (there you have the camera axis and the robot's axis) and you want the robot to move to a certain point in the workspace knowing only the point coordinates from the camera's point of view.

Yes, this blog can get serious sometimes.

Of course, you'll need to transform these "camera coordinates" into the coordinates from the point of view of the robot... damn how to do that? Simple, you use a type of transformation matrix called Perspective Matrix.

 

We will need at least 3 known points from both the robot and the camera points of view to be able to resolve the system. Suppose Robot coordinates are (Xr1,Yr1,Zr1), (Xr2,Yr2,Zr2) and (Xr3,Yr3,Zr3) and camera are (Xc1,Yc1), (Xc2,Yc2) and (Xc3,Yc3). We should get  a set of nine equations with nine variables (our perspective matrix).

(a*Xr1) + (b*,Yr1) + (c*Zr1)  = Xc1
(d*Xr1) + (e*,Yr1) + (f*Zr1)  = Yc1
(g*Xr1) + (h*,Yr1) + (i*Zr1)  = 1

(a*Xr2) + (b*,Yr2) + (c*Zr2)  = Xc2
(d*Xr2) + (e*,Yr2) + (f*Zr2)  = Yc2
(g*Xr2) + (h*,Yr2) + (i*Zr2)  = 1

(a*Xr3) + (b*,Yr3) + (c*Zr3)  = Xc3
(d*Xr3) + (e*,Yr3) + (f*Zr3)  = Yc3
(g*Xr3) + (h*,Yr3) + (i*Zr3)  = 1

Resolve this system and there you go... you have your Perspective Matrix

Once obtained the values ​​of the perspective matrix, it is easy to do conversions by multiplying the robot coordinates by the perspective matrix to obtain camera coordinates. Or the camera coordinates for the  the inverse of the perspective matrix to obtain robot coordinates.


I hope this helps some tormented soul someday... cheers.

Hey baby, wanna kill all humans?
To  know more:
      - Introduction to Homogeneous Transformations & Robot Kinematics

Wednesday, September 28, 2011

Rivalries


Lisa, certain differences, rivalries if you will… have come between us. I thought we could talk it over like civilized people but instead I just ripped the head of Mr Hunny Bunny.

Tuesday, August 17, 2010

Op-amps, are they really that cool?

Yes, yes they are! The Operational Amplifiers (op-amps) are among the most widely used electronic devices in consumer, industrial, and scientific electronics. They were originally produced for mathematical operations (hence its name) but in fact they can be used for many many other purposes.

Yes, they are in Terminators too.

You know, back in the day, op-amps were constructed from vacuum tubes, meaning that they were poorly functional power hungry-devices that wouldn’t make it till these days if it wasn’t for one person, so if you ever have to thank anyone for pretty much everything you enjoy of modern day electronics (and probably for robots wiping out mankind) is this man: Robert Widlar

Bob Widlar was an electronic engineer in the 60s, he’s better known for being the designer of the first mass-produced op-amp IC in 1966 (among other cool stuff like the first voltage regulator IC) but also for  his akward pranks and  rabit ass way of life that are remembered in legends, myths and anecdotes, just like this one:

“On one occasion, when National Semiconductor tried to save money by cutting its landscaping expenses, Mr. Widlar brought a goat to work in his car to eat the grass in front of the company headquarters.”

True story boys.

At the age of 33, when he was wealthy enough on company stocks and already a "legendary chip designer", Widlar quit his job, left Sillicon Valley and hide somewhere in Mexico where he lived until his death in 1991.


So... how do they work?

In a very basic way, an op-amp is an electronic device with two inputs and one output

The value of the output is the difference in voltage between the two inputs multiplied for a gain factor, the usual gain (in open loop) is very large, and I mean quite fucking huge (over 9000!)… that means that even a very small difference between the inputs (and I’m talking micro volts here) will result in amplifier saturation.

Amplifier Saturation: If higher voltage is applied to the pin V+, the output will corresponds to the source VS+, however, if the higher voltage is applied to the pin V- , the output will be VS-

“I see what you did there…”

That should do the trick if what you want is a comparator circuit to, let’s say,  “control the direction of a DC motor”. On the other hand, if you plan to build a death laser machine to destroy France you’ll need to control that gain somehow… a feedback into the circuit is the way to go.

Feedback enables the amplifier to keep the inputs at almost the same voltage, avoiding that evil saturation stuff. However, you got to be careful; shit comes in two flavors, positive feedback and negative feedback. Usually, negative feedback is the one you want to hang up with.

“Yeeeeiii”

The previous image shows a non inverting amplifier.There are a lot of resistor/capacitor or  even coil configurations for the op-amps depending on the application you need. If you're interested, you really should give a look to this article. I also recommend you this links if you want to dig deeper on the history and insides of an op-amp.



Wednesday, August 11, 2010

Simpsons Moment




Homer : The sum of the square roots of any two sides of an isosceles triangle is equal to the square root of the remaining side.

Man : That's a right triangle, you idiot!

Homer : D'oh!


Thursday, August 5, 2010

A cup of tea with your processor


A couple of weeks ago I went through one of those cruel technical examinations that every newly graduated engineer has before getting his/her first job. 

It wasn’t that bad, Object Orientation: easy! C Language: bring it on! Circuit Analysis: checked! They even asked Elemental Physics: piece of cake… All was fun and games until Assembly came on the ring.

Ohhh shi…


Note for the new guys: Assembly is a low level language used to program microcontrollers and processors.

It turned out that they really needed an assembly badass for that position, so after leaving in despair, I decided to do a little research on the subject and learn about this so called dark arts of programming, hoping  to never experience that shit again.


The story behind the story.

63 years ago the world's first electronic digital computer was turned on, they called it ENIAC, shit was huge, had more than 800 km of cable inside, weighted about 330 tons and check this out: contained more 17,000 bulbs in its cherry belly (how many vintage guitar amplifiers is that?). This copper monster was capable of doing about 100,000 operations per second (kind of lame right now but fucking awesome in the 40’s). 

Anyway, what was really great about ENIAC was that you could actually program that shit. Yeah, even though they needed to reconfigure every single bulb and rewire more than a few kinky circuits in a process that took several days to several people, a programmable computer was a huge step in the olden days. 

"Yeah baby!"

After a while, scientist and engineers got tired of switching bulbs, and one day a crazy Hungarian dude designed a system that could take a crapload of binary code as a set of instructions to create a program, soon,  the first computer language was born... Machine Language

Still, Machine Language was boring as hell and hard as fuck, it didn’t take long for Assembly to first saw the light of day in the early 50’s. 

Note:  A common mistake is to call it assembler language; actually an assembler is what is used to translate assembly language into machine code. 


Why should you give a fuck about Assembly?

Well… you don’t really have to; you can do pretty much everything in C. It’s true that an assembly program will use the memory in a more efficient way but  the time and effort you may put in it probably won’t be worth it, today’s processors are so fucking awesome that you cannot really tell the difference.

Protip:  However, If you are on the road of electronics many employers will ask you for assembly skills (I learned that the hard way).



Hello World

Before this post gets too long I’m going to try and explain an assembly program in a really basic way so we all get the neck.


First of all, when a line start with a "." it means that we are about to tell something important to our processor. For example, ".model small" is like telling it: “easy boy, we won’t use a lot of memory”

The stack is used to store temporary data, it isn’t used in this program but you still need it, you could say that those are processor manners. (since the purpose of this program is to make an .EXE file, the stack is a must)

.data 
message db "Fucking Magnets, How Do They Work?" ,"$"

It's like: “Hey dude, I’m done with the stack stuff, we’re starting the data segment now, be cool and define some bytes, these bytes should contain the information between the brackets and don’t forget that "message" is how we will identify this byte-string thing”.

As you may have guessed, ".code" means that the code segment is about to start and that the data segment has just ended.

"main proc"is, as in any other programming language, the declaration of a procedure that ends in "main endp", let’s say that here is where you put the shit that you want your processor to do.

And then the tricky part begins, remember how we told it to remember that "message" would be the identifier? Well, "seg message" is the number of the memory segment where "message" is in, we need to know this number in order to know where the fuck is that byte-string thing.

"ax" is a register, and registers are like empty bottles where you put stuff. The instruction mov commands our processor to move "seg message" into our "ax" bottle, then we move what we just put in "ax" into the Data Segment register ("ds").  It has to be this way, "mov dsseg message" is not allowed (processor manners again).

I think you get the idea

"mov ah, 09" means to load the "ah" register with a nine.. shit start making sense right?

Ok, we have the number of the segment where message was in order to locate it, well, we also need the offset within the data segment of the bit-string thing to be able to reach it (kind of a x,y coordinates), we do that with "lea dxmessage", (lea: load effective address).

Don’t stop reading you lazy bastard, we’re almost done.

"int 21h" is an interrupt (I may talk a little bit about interrupts in another post) that tells our processor.. “Do stuff man!”. The first thing the processor does is to check "ah". There is a nine remember? , the nine means that the procedure shall write our bit-string “Fucking Magnets, How Do They Work?” to the screen.

mov ax4c00h
int 21h

Finally, these two instructions are pretty much the same, we load 4c00h in our "ax" register ("ah" contains the higher byte of the "ax" register, that would be 4c) and then the same int goes and checks "ah".  This time it contains 4c, that means “exit program”.

And that's pretty much it... I intend to write several post going deeper on assembly and its nasty secrets,  in the meantime if you want to learn more, I highly recommend this site: