Friday, July 12, 2013

Fun with Engduino 2

As mentioned at an earlier post , I am toying on the idea of a signalling bike helmet that uses the the 16 RGB leds with the accelerometer. This idea is dead simple. Tilt the head to the left, light up the LEDs on the LHS, and vice versa for the tilting to the right.

First thing first. Open the Example->Engduino Examples->Acclerometer Example, just to see how the APIs (Application Programming Interface) are used. From my previous experience with 3DOF, 5DOF, ardu pilot IMUs' (Inertial Measurement Unit, usually made up of an accelerometer and a gyroscope), Enduino's is the easiest to use to date. I can write code straight away without worrying too much. The reason, there is no risk of "frying" the IMUs because of a mal-wiring, loose wiring, bad solder joints etc. If the hardware is reliable, troubleshooting the software is much much less daunting.

From the accelerometer example, compile and upload to engduino. open the serial monitor to observe the output. The keything to do here is to stick to one orientation while observing the outputs. I prefer it to hold it "crown side up" . that is looking straight into engduino, the circumference of the board resembles a crown. Now, move the the board on the "x -axis", that is moving the crown horizontally to the plane and observe the output. repeat for "y-axis", that is moving the crown vertically to the plane and finallymoving the crown closer and further to you relatively to the same x and y axis on the plane. The next actions to try out is the roll, pitch and yaw. You cant help but notice that the values of all 3 axis change accordingly.

One thing you will notice that the X Y Z axis values do not correlate to the orientation of crown side up. Here come the interesting bit. As a programmer, if you have decided on the orientation, wrote the code for this orientation but when it comes to mounting but it has to be the other way round, you cant help but notice that your code start to behave erratically. Moral of the story: understand how is the acclerometer is going to be placed before writing code. Of course some may argue to stick to the "original" x y z axis of the board irregardless of the application and write code that corresponds to this. Both methods are do-able, there are more than one way to skin a cat.

The code/theory to track the changes of the x y z axis values as close as possible can be a little bit to over stretched in this post. Each of the topics such as smoothing technique, PID, 3D kalman filter and etc deserves at the minimum a chapter each in the classic control theory book. Nonetheless, it is just a google away to learn more!

My toy that is held with crown side up, the value of the "y-axis" changes in the range of +- 0.1 when I tilt it left<->right. So I am going to exploit this "behaviour" and tailor my code surrounding it.

Check out the video below to see it in action!

here comes the code

Just in case you wonder what an arduino + IMU + control theory can do, check out my previous toy

No comments: