Friday, September 25, 2015

Log 6

I think I’ve found a solution to my quaternion problem, but I’m not sure why it worked!

Ok, before you mentally ask: “Wait, what?”, let me explain. During my tests, I’ve noticed that after I rotate the IMU 180º around one of the main axes, the real part of the attitude quaternion should be reduced from 1 to 0, but it was falling only to about 0.8. So obviously something was wrong. Firstly I though that my integration process could be the source of the problem (I have to numerically integrate, in real time, some values received from the gyro sensor), so instead of using the standard Euler integration with fixed step (also called ODE1), I’m now using a trapezoidal integration with variable step. I’m also executing this integration process in a background thread (ok wait, what the fuck is a thread anyway? I’m gonna dedicate the next paragraph for this explanation), so now the integration process is way better. But the problem persisted and I had no other option but to use a POG (the art of creating a functional but fucked up code). To convert the 16 bit signed integer received from gyro sensor, in some point I had to divide this integer by 2^15 (15 because is a 16 bit signed integer, which means that one bit is dedicated to the signal and the other 15 are dedicated to the absolute value of the number). Suddenly I had this idea of dividing the integer by 2^14 instead of 2^15, and guess what?... It worked (yay!), but now I don’t know why! Perhaps it was luck, or perhaps it isn’t working at all, but I’m getting the wrong impression it is. I don’t know, I’m gonna look at it another day.

As promised, here is the thread explanation: A thread is a process that can be executed in parallel to other thread, which is different from parallel processing in the sense that multiple threads aren’t processed in the same time. Let me give an example: suppose that you have an algorithm with 100 code lines. I don’t know how or why, but you are going to split this algorithm into two threads with 50 lines each. When you execute this new splitted algorithm, you are going to realize that it took almost the same time to execute as the original one with 100 sequential code lines. This happens because they are not processed at the same time. The processor core process one line of code at a time, but switching between threads, so in one instant it processes one line from thread 1 and in the next instant it processes one line from thread 2, then go back to thread 1 and etc. Our brain works pretty much the same way, when we are “multi-tasking”.

I know today’s log was boring, so let me finish with a joke:
A Brazilian, an American and an Argentinian were lost in an island. They were found by a cannibal tribe. The tribe challenge them to go inside the forest and bring them one fruit each. Letter that day, the Brazilian met the American in heaven, so he asked the American: “What happened?”, then the American answered: “I came back with a khaki, them they ordered me to stick the fruit in my ass, if I laugh, they would kill me. So I was finishing putting the khaki in my ass when it begins to tickle, so I laughed”. The Brazilian said: “They ordered me the same thing. I was about to stick a strawberry in my ass when the Argentinian arrived with a pineapple”.

No comments:

Post a Comment