Sunday, 2 September 2012

Review on HRLV-MaxSonar®-EZ™ Sensors (MB1013) )

I have tried three different ultrasonic sensors, one from Devantech (I guess it was SRF05 but not so sure), one was the first series of MaxBotix when they had resolution of 1 inch and recently I tried MB1013 from high resolution series. With no doubt the last one was the best I have seen. I am going to use this sensor for a competition where I have to detect a wall with hight of 10 cm and my sensor is located 5 cm away from the ground and It did a very good job during our tests. I designed few different tests to see how much I can rely on my ultrasonic sensor.
I found a line of best fit for its output to make sure my reading are the best possible.
These are my points and their ADC reading:
Average ADC reading:                     Distance:
76.3929                                           40
126.9655172                                   65
176.0333333                                   90
226.3103448                                   115
256.8125                                         130
296.0714286                                   150

The best line fit:
y =   0.501x + 1.67
distance = 0.501  *  ADC_reading + 1.67

The equation works quite well. The ultrasonic has 3 different types of output:
1) Analog: which I like it, since it is fast, easy but less accurate compare to others but fine for me
2) Pulse width: a bit more complicated since you have to use a timer. I am using Arduino which does not have a lot of timer and for my robot, I will be using most of timers. If you want  very accurate result then go for next option.
3) Serial output: This is the most accurate output. But wasting a UART may not be a good idea. The other issue is that if you use interrupt to read your UART input, you have to turn other interrupts off which may not be suitable for some situation. If you read UART without interrupt it will take some time since the baud rate is 9600. (I may try this in future just for sake of accuracy)

they are two modes of reading the output from sensor:
1) free run:
It has a filter included and I prefer to use this since it has a filter.
2) Real time:
It has no filter and it will do its reading when you send a signal.

Now I start with tests.

Testing different material:
The sensor has the same output for different type of materials. I tried with metal sheet, carton and polystyrene.

Testing different shapes:
It could detect the cylinder without any issue from sides and it showed an accurate output. Flat surfaces are definitely detected and there is no issue with them.

Object with different size:
the size of object is not going to change the output.

Detecting the closest object:
Even if there is a big object at the back and small object in front, sensor output will be the distance to closest one.

Detecting 15 degrees ramp:
It could detect the ramp with acceptable accuracy from 30 cm to 15o cm. The length of the ramp is 60cm.

I used this ultrasonic on my robot and I think you have to consider the following if you are going to use one:
1) In the real time mode you do not get a very reliable reading (I tried it in a parking lot and I was not happy with it)

2) If you are using the free run mode, your readings are impressive, however you cannot move very fast because it takes some time for changes to appear on you reading. (This is what you should expect when you are using ultrasonic, I did some research and I found out that laser range finder can do a better job at much higher. Hopefully I will be making one laser range finder with my friend.)

3) If you are using the sensor very close (5 cm) to a surface which is not supposed to be detected, you have to make sure that the surface is flat. To give you an idea we had to wooden sheet next to each other with a gap around 1mm. The sensor was detecting the edge from 190 cm. It was detecting the edge of the gap (located at 190cm) instead of the wall which was located ~240 cm away.

Conclusion:
A good sensor for application where respond time can have a delay of 1s. Accuracy is good. Sensor has 3 different outputs which make them easier to use. If you want to have a fast robot forget about ultrasonic and go for laser range finder.

Wednesday, 21 March 2012

Vexta DC Brushless Motor Running with PWM

If you live in Malaysia and Cytron is one of your resources, you should have seen all those expensive brush less motors called Vexta. They come with a gearbox and a speed controller.
I looked at the data sheet and I did not see anything about PWM, so I tried to use PWM to control it and I failed. I was using a roughly 60KHz PWM and it did not work. I tried with 16MHz and I am getting a very good result from them. I am using an AVR board which has an Atmega 1280 on it.
I just wrote the following program to make it work.
////////////////////

  int a=0;
      while(1)
      {
      OCR0A=a;
      OCR0B=a;
      a+=10;
      delay_ms(3000);   //delay_us(500)
        if(a>240)
        {
        a=0;
        }
   
      }
//////////////////////
necessary registers are the following:

PORTB=0x00;
DDRB=0x80;



TCCR0A=0x83;
TCCR0B=0x01;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

Keep in mind that I was using a 16MHz clock.


There is something else that I have to share, in the catalog there is a page called connection and operation, in that page all on are indicating gnd and all off the indicate +5 (High). (I don't know why)
So in order to run it with PWM, this is what you do with the speed controller:

PIN 1: not connected
PIN 2: not connected
PIN 3: GND
PIN 4: GND
PIN 5: PWM
PIN 6: not connected
PIN 7: +5V (HIGH)

PIN 8: +5V (HIGH)
PIN 9: GND for clockwise. 1 for counter clockwise
PIN 10: GND
PIN 11: GND

This is the video of the Vexta motor running.

Saturday, 10 March 2012

Review on L6203 Full Bridge Driver

This is an amazing motor driver. It has temperature protector which really works and cut down the current. One of the best thing is that even at high temperature it does not cut the whole current, it will bring down the current. This can be good for the condition where you have to apply force but your motor is stalled for some time.
I have never had any problem using L6203, and honesty it is hard to burn them. To give you an idea, once I connect all pins in opposite order and it did not burnt. The other time I connected the Vs to GND and GND to 36V and it is still working, although it was drawing 3 A. It has even short circuit protector for outputs, which means that even by short circuiting out 1 and 2, nothing bad going to happen. (I have never tried though)
The only thing which I found important is that you can't use Vref as a HIGH for input 1 and input 2. I am not sure why, but I am sure from my real life experience.
You may use Vref for enable but not for inputs.
This is how I use my L6203:
1: Output 2 which is connected to a 15nF cap and one of the wires coming from motor. (the other side cap is connected to boot2)
2: Supply voltage that you want to run motor with it
3: Output 1 which is connected to a 15nF cap and the other wire coming from motor. (the other side cap is connected to boot1)
4: Boot 1. This is connected to the other side of 15nF cap that you have connected to out 1
5: Input 1, just make sure you do not connect Vref as a high for inputs
6: Ground
7: Input 2, just make sure you do not connect Vref as a high for inputs
8: Boot 2. This is connected to the other side of 15nF cap that you have connected to out 2
9: Vref, This is a reference voltage around 12 V. You may use this to apply a high to Enable pin and make the L6203 to always be on.
10: Sense, you can connect this directly to ground, if you don't want to get any feedback from current. If you want to get a feedback from current connect a resistor between this pin and ground. Than read the voltage between this pin and resistor.
11: Enable, by adding high to this pin you will turn on L6203

If you want to get the best out of this component just add a heat sink and a fan, then it works forever with high output current.

This component is much better than L298 and L293. I have used them all and I found L6203 much more reliable, specially if you are going to attend a competitions, you can rely on L6203. I have explode L298 and L293 after using them for long time or drawing high current, but never had any issue with L6203.

If you want to control speed of a motor and its direction, you can simply use one of the inputs as a PWM and connect the other input to any I/O of micro controller which is assigned as output. By changing the value of PWM you will change the speed and by changing the value of I/O from Low to High or High to Low you can change the direction.

Tuesday, 6 March 2012

How To Use Pulse Width Modulation (PWM) To Control Electrical Speed Controller (ESC)?

In this post we will have some specific talk about AVR since I have experience with.
The objective is to make a pulse with period of 10 ms and pulse width less than 2 ms and more than 1 ms. [1ms,2ms].
At first we look at a case where we have an external 16 MHz clock and we are using 16 bits timer.
If you have a 16 MHz clock then the possible clocks for your PWM are the followings:
16/1 = 16 MHz
16/8 = 2 MHz
16/64 = 0.25 MHz = 250kHz
16/256 = 0.0625 MHz = 62.5 kHz
16/1024 = 0.015625 MHz = 15.625 kHz
So now we will find which of the following will gives us 10 ms period.
we start with the one with lowest period which is working at 16 MHz.
1/(16*10^6) * 2^16  = 0.004096 = ~ 4 ms
This is too fast. We need at least 10ms. so we try with 2MHz
1/(2*10^6) * 2^16  = 0.032768 = ~ 33 ms
This means that this timer will give us a period of 33 ms before overflow.
We know that every 1/(2*10^6) timer counts one, therefore our resolution is 1/(2*10^6) = 0.0000005s = 0.5us
10 ms / 0.5 us = 10 ms / 0.0005 ms =  20,000
20,000 indicates that after this number we have to start from zero. (resetting the timer)

1 ms / 0.5 us = 1 ms / 0.0005 ms =  2,000 steps for minimum speed
2 ms / 0.5 us = 2 ms / 0.0005 ms =  4,000 steps for maximum speed

Here I do not want to talk abou PWM I will do it here, so I will just leave the required value of registers in order to achieve what it is explained above:
//defining I/Os as output so later on we will generate the waveform on these pins


// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xE0;


// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 2000.000 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// OC1C output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0xAA;
TCCR1B=0x1A;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x4E;
ICR1L=0x20;
OCR1AH=0x07;
OCR1AL=0xD0;
OCR1BH=0x07;
OCR1BL=0xD0;
OCR1CH=0x07;
OCR1CL=0xD0;

This will make the PWM to work in the way that we want. (This code was tested in real life) It will give three different PWMs.

Now this is the function that will change the pulse width for output A from timer 1.


void motor_x(unsigned int speed )
{
OCR1AH = speed >> 8;
OCR1AL = speed;
}


I guess now you have got the idea, if there was any issue just post your questions in the comments.

How To Use Commercial Electronic Speed Controller (ESC) Without Remote Controller And Receiver?

If you have a remote control and a receiver read here.
I consider that you have a micro controller, ESC and brush-less motor.
This is something for testing so I will talk in general, however some ESCs will give you this information in details in their datasheet. I have just used 4 to 5 different type of ESCs.
Keep in mind that some ESCs are programmable but they are not programmed in same ways but if you are going to program them, full throttle means the maximum speed.
Most ESCs they will capture the maximum and minimum signals before they start running. In order to calibrate your ESC with signals you have; do the following.
1) Turning the ESC on
2) Max signal applied
3) Waiting for some time (4 seconds for my case)
4) Minimum speed
This should be done step by step and you should not delay between steps.

Till now I did not tell you what the signal is. The signal is having period equal to 10ms.
Pulse width is 1ms for minimum speed and 2ms for maximum speed. This is going to work for most ESCs.
This is how your pulse should look like


So as you can see that the red line shows the maximum speed and the orange line shows the minimum speed.
As you may noticed the ESC will understand when it is not connected to anywhere since the minimum speed which means no rotation will occur at 1ms pulse width and if you don't have that 1ms then the ESC conclude that there is no signal connection.
I have explain here how you can make a waveform like the one above.

How To Use Commercial Electronic Speed Controller (ESC) With Remote Controller And Receiver?

If you do not have a remote control and/or receiver, read here.
Well, if you have a remote controller and a receiver you just have to connect the wires, and play around with sticks and you will see that the Brush-less motor will start moving. If it did not work follow the following steps:
* If your problem is bad wires, this will not help you.
1) change the connection between motor and the ESC:
In normal ESCs and Motors the wires should be connected from right to left or left to right. By changing the order between these two, you will change the direction that the motor will rotate. You should connect most left coming out of ESC to the most left going to the motor. I have seen motors which does not work this way, the best is to try all combinations by shifting each wire to tight or left. If this did not work go for the next step.
2) flip the connector which connects the receiver to ESC.
You may be able to flip this in many receivers, if you are not able to do so, that means that your connection is right. Keep in mind that usually the middle pin is 5V and the sides are ground and signal. Red is usually chosen for 5V, black or brown for ground and yellow for signal.
3) If it does not work yet, try another channel and move all the sticks.
4) If you have an oscilloscope (a servo motor will do the same in easier manner if you have one), connect it to signal pin of your receiver. If you had a square wave with period of 10ms or something around that, then your remote control and receiver work. If you are lazy to take an oscilloscope just connect a servo. If the servo works, it means remote control and receiver work.
So, now you have to make sure that the brush-less motor or ESC is working. The only way, I know is using another brush-less motor or ESC. If you know a better way leave it in comments.
If you do not have a remote control and/or receiver, read here.

Saturday, 25 February 2012

What Is Inside Wifi Antenna?

Today, I was working on my quad and I was so curious to know why this is so heavy. I was going to put one on my quad but it was to heavy and it was causing troubles in balancing. So I tried to open it and see what is inside. Well, I was not so successful, because I broke it. Anyway I was so happy from the result. Just look at the picture and you will know why.
Yes, just a very thin and light hard wire. The reason I am using this huge antenna is because my Xbee needs it for longer range.

9 Degrees of Freedom - Razor IMU - AHRS compatible made by Sparkfun

I am going to talk about Sparkfun IMUs. First of all I have tried just one of them, which is this.
I have read the code provided by spark fun for some of them as well.
First and main problem with all spark fun IMUs:
One does not simply gives an output through UART. (9gag)
UART is really slow.
The second issue is that, the output is so long. I have changed my output myself to make it shorter. Seriously, spark fun has used a 8 bit ascii code for each digit in every angle.
Second problem is that you can't be notified if new data is available. Therefore, if you are reading UART using buffer and interrupt, you have to make sure that you are not saving them in buffer when you do not need them. Then, the other bad thing about this is that while your IMU is doing calculation there is no way to read any data, even the old data. Which will help your control loop to run at an almost constant speed.
I changed the program myself, to make the IMU to give me outputs when I want them, but the sparkfun code gives the output regardless of any feedback from user.
The other issue with mine is that it runs at 50Hz which is now really good for UAVs, because one of gyros works at 50Hz but for new models the components except manometer can be used to at higher frequencies but Sparkfun is using a same code so they are running them at 50Hz as well. This is one example that Accelerometer and gyroscope can be used at much higher frequency.
This and the one that I have are the only one which they have a working code provided by sparkfun at this time. For this one, the code is totally wrong.
This things that I mentioned are applied to all IMUs made by sparkfun till now.
The other issue with mine is that the reading at steady condition fluctuate. In the following graph you can see angle measured by IMU in degree and each unit of x-axis represents 20ms.

The other issue with my IMU is that, it gets to much noise when there are some vibration. The filter by right should take care of that but it does not.
If I were in your shoes, I would buy a set of ADXL345 and ITG3200 and I would make them work with complimentary filter. I could be proud that I have made it myself and at the same time it works better and faster than these IMUs and therefore you can achieve a better control loop.
Anyway I have to mention that these IMUs are good for simple usages but for fast response are not good unless you make your own program for them.

Grammar and Spelling Mistakes in My Blog

Dear grammar Nazis and friends who read my blog.
I write and update my blog at midnight and whenever I am out of energy, so you may see many mistakes in the posts. This is not due to my poor English, it is simply because of being so tired. Feel free to mention them in comments if you read them. I think it is most important to transfer the information than making a good written post. Although I will force myself to be more careful.
Thanks.

Friday, 24 February 2012

Damaged Propeller

I noticed something very important just right now.

Propellers are so important, maybe more than you think.
I had two propeller, one was damaged as you see in the picture and the other one was virgin :) (not used)
Then I noticed that one motor is doing much better than the other one and I questioned everything except the propeller then I noticed that the problem is propeller. I swapped the  propeller and I noticed the week motor is changed too. Therefore I conclude that the problem was  propeller.




Earlier this week I glued one  propeller  and it gave me so much vibration, if you really have to glue your  propeller super glue works but it may break easily afterward. If you use other glues like the one I did, it is going to be heavy and it will cause you a heavy vibration and motor shaft will not have fun.

Sunday, 5 February 2012

Weird Experience In Programming 1

I have no idea why, but I found it important to report.

global variable:
long int time=0;
 float ki=0;

void function (void)
{
float delta_error, speed;
speed = delta_error* kd/time;
}

This two should have the same result as far as I know.


global variable:
long int time=0;
 float ki=0;

void function (void)
{
float delta_error, speed;
speed = ((delta_error/time)  * kd );
}

This program is written in C, the important part is that for the first cycle the speed is 2147483647 for the first version. It should be zero. The interesting part is that second version shows the value of speed equal to 0. I have used code vision is my compiler and I ran this on my Atmega 1280. Anyone knows why?

later on I tried with this  delta_error/time * kd and the resualt is as same as second version.
Hint: signed int in my compiler has the range -2147483648 to 2147483647

How to Find PID Constant For Quadrocopter? How to Tune PID For Quadrocopter?

Well, I am not really in to control systems and considering my limited knowledge, I can't say much about it. I have read a lot of sources but I can easily tell you that many of them is not as good as the version, I made. This is totally a practical way of finding and tuning constants. (I wrote this post few days ago and I was thinking that this is not a good post because I did not tell you anything about PID itself and the rest of control loop. Don't worry I will)

What you have to do at first is holding one of the axis and let it rotate over it.

Now make a the following line of code:
Speed = Trust + Kp(error) + Ki(delta_error)*(delta_time)  + Kd *(delta_error)/(delta_time)
so the problem is solved now you have Kp, Ki and Kd. I was just joking now the main part will start.

I would like to suggest you to make a program which lets you change the values of Kp, Kd and Ki in an appropriate resolution while running the PID . I used my computer key bored to increase and decrease each constant.

Set Kp and Ki to zero. Increase Kd to the point that your quad does not rotate in any direction. For testing make trust as high as the speed which gives enough trust to your quad to fly with 4 motors. Keep in mind right now you are just using two motors which are placed in one axis. The other axis is hold. In this situation, you should have something like the structure here.

Now keep increasing Kd till the point that your quad does not rotate. It does not need to stay at flat angle but it should remain in one angle. You should be able to change the direction by adding extra force.

Now, increase Kp to the point that your quad will be able to get to certain angle, if you rotate it has to come back to the same angle. Keep in mind that this angle should not necessarily be zero (flat).

Now increase Ki, to get to the zero angle which is your desired. This always worked for me.

Let me know your result if you tried. Thanks.

Thursday, 2 February 2012

Control Loop For Quadrocopter

In this post I leave important hints about control loop:

* Measure the time that your loop takes for every time that you run it. This measurement does need to be in second, so make your own unit and if you wanted to make it smaller just shift the bits. This takes much shorter than dividing a number to some floating point constant.

*Make sure your loop is running at more than 30 Hz, 30 Hz is not enough. 100Hz works for sure. I could not manage to get 30 Hz work properly.

* Try to decrease the calculation process as least as possible.

*This point is theoretically wrong however I have tried it myself and this may solve your problem.
A university lecturer told me to apply my speed at the same time in every cycle of my control loop, this is actually right and it makes sense. When I was running my quad at 50Hz I faced an oscillation. I used to apply my speed at last 80% of my control loop which is something like 15ms after the start of loop. This was a safe place where in worst situation the data has already been sent from IMU (My IMU is giving me output through UART). In average this would take around 7ms so it was much better to change motors' speed as soon as the reading is ready. So I did not listen to him and I tried and I achieved a much better result. I think for low frequency this is really helpful. This should not be a problem for higher frequencies from what I assume.

*Make sure your loop is running at the speed that you expect. In order to try that, get an oscilloscope and make an square wave by changing a pin value at the end of each cycle. This will make a square wave with half of expected frequency and double of expected period. This test saved my ass. :)

*Guys it is not as hard as you think just keep moving...

I can't thing of anything else now. I will update this as time passes.

Which Xbee to buy?

The first thing is about Xbee which is so important is to consider that:
1) XBEE ZNET 2.5 used to be call " 2  series "
2) 802.15.4 used to be call " 1 series "

Version 2 is better because of following:
1) energy saving
2) range (It is too much difference, I loved my series 2 because of its amazing range)
3) being more complicated and therefore more application on bigger networks

Each of the group mentioned above has two type:
1)Pro
2) normal one

As far as I know the Pro version can support longer distance.

Now, I do recommend you to use Series 1 if you are not familiar with Xbee and I think you are not or else you would not read this :D

Keep in mind that your Xbee's serial communication is at 3.3 volt and not 5. Although mine works with both. The data sheet asks for 3.3 volts.

Xbee comes in different type of antenna and power output, make sure you use the one which meets your needs. I can't give you any opinion how to pick the right one because I have 2 different types of them.

Fact: it is really hard to burn a Xbee, I have tried many different things and I was never successful :D
I finally burnt one. :) It receives data when there is no other Xbee around.

I do recommend you buy a break out with FTDI like this or this
It is good to have something like this too. Although, it does not do much.

If you but series 1 this is how you can simply use them, Here.
If for some reasons you have 2 series, do not worry, just read this.

How to test Xbee Series 2 (s2)?

Well, I assume you have one of your Xbee is connected to the computer using a breakout and FTDI 232. something like this or this. (many other company are making the similar ones) The other one has something like this and Rx and Tx (in the case of sparkfun Din and Dout) are connected to each other/ which means that whatever will be send will be received too.

Make sure you have download X-CTU from digi website.

Run the program and you have to connect the serial port which is connected to FTDI, when I tried the name was "COME XX". Go to the modem configuration tab and click on read, if it asked for reset, just connect Xbee's pin 5 to Xbee's pin 10. Check the DH and DL. Keep the number somewhere.

This is the easiest way I found to test my Xbees 2 series.
1) make one as a coordinator AT (AT and API is well explained in Data sheet provided by Digi)
2) make sure that you use DH and DL of your other Xbee.
3) change packetization time to zero (this will send any data available for sending if you choose any other number it will wait for that period and if they were any other data coming, it will send them in one packet)
4) take the other one and program it as router/end device AT
5)  make sure that you use DH and DL of your other Xbee. 
6)  change packetization time to zero (this will send any data available for sending if you choose any other number it will wait for that period and if they were any other data coming, it will send them in one packet)

now you can go to the terminal tab and see if you get whatever you type in red or not, if you do that means everything is working, if not there is still one hope. Change all possible values in networking and address to the same value in the other one. Read the description about each value, if it could be a reason then change them first and try. If it was not still working read the God damn Data sheet. :D

Hint: do not give up easily, one does not simply burn a Xbee. :)

How to test Xbee series 1 (s1)?

Well, I assume you have one of your Xbee is connected to the computer using a breakout and FTDI 232. something like this or this. (many other company are making the similar ones) The other one has something like this and Rx and Tx (in the case of sparkfun Din and Dout) are connected to each other/ which means that whatever will be send will be received too.

Make sure you have download X-CTU from digi website.
Run the program and you have to connect the serial port which is connected to FTDI, when I tried the name was "COME XX". now you can go to the terminal tab and see if you get whatever you type in red or not, if you do that means everything is working, if you don't then click on modem configuration and click on read. If it asked to reset your Xbee, connect pin 5 of Xbee to pin 10. After that write the original version of your Xbee on it. Try the same thing with the other Xbee. Try again and you should be fine, if not just ask me. I am not that used to Xbee myself yet but I guess now you can be happy that your Xbees work fine. You may go to range test tap and play around with it.

Monday, 16 January 2012

How to read the output from accelerometer?

Your sensor may have any kind of output, the one that I know are either I2C or analog.
In the data sheet of your sensor you can find this variable (g / data_output), using this variable is actually waste of time. If you use the method I explained here, you just need to make sure your readings are in same units. Units will cancel each other.
If you want to show the data on your PC screen and in terms of g then do the calculation on your PC not in micro because that will take time form your PC and not your weaker controller on vehicle.
The only thing, I did missed the first time; I was using it was wasting time for finding the readings in g which is not important and keep in mind that I2C and analog outputs are integer and not float so all future calculation becomes much faster for the controller.
You may want to calibrate your accelerometer, this is not actually hard. all you need to do is to rotate the sensor and see the maximum reading in each axis, then multiply the variable  (g / data_output) to your reading and you have to get something around 1. Do not be so picky if your reading is not exactly one since most of the sensors with cheap price are not that accurate and keep in mind that soldering and environment may  change the accuracy of the sensor or the variable  (g / data_output)  slightly.
here I explained how to test your accelerometer. (http://asafdari.blogspot.com/2012/01/how-to-test-gyroscope-accelerometer-and.html)
There will be one other variable that you will need for using in what I explained here (Using three axis accelerometer with three axis gyroscope). This variable is called gravity.
Gravity is basically g in your sensor measurement, without changing units.
Using Pythagorean theorem we know that:
Acceleration_resultant = sqrt ( Acceleration_x^2   +  Acceleration_y^2  +  Acceleration^2 )
Now, consider the situation where the only acceleration applied on sensor is gravity, then:
 Gravity =  = sqrt ( Acceleration_x^2   +  Acceleration_y^2  +  Acceleration^2 )
Finding gravity is necessary and you don't need to measure it every time you turn on your vehicle, you can measure it once and use it as a constant. But it is good to once in a while you measure it again to make sure that your sensor is not affected by environment and even if it is, then just use the new value. I would calculate Gracity 100 times while my sensor is at rest and I would get its average and use it as a constant. Just one more thing, usually the output will be something more than a few hundred (despondent on your sensor and resolution of our reading)  so ignore the decimal point and just round it and keep it as an integer so it will be faster for controller to do calculation with integers.
Usually the vehicles start from rest, so you may calculate Gravity every time you turn on your vehicle. Just make sure you are not relying on one reading.

How to test gyroscope, accelerometer and filter?

You may rotary index. I took one from university's workshop and it helps a lot. It helps you to see the accuracy of the gyroscope, accelerometer and your filter. I have to say that it does not help with raw data from gyroscope it helps with the angle output base on gyroscope alone. you can use the following formula and test your gyroscope, just make sure that initial value for   previous_angle is equal to zero and then angle change is reading from gyro and it gives you the angle. you have to keep the reading from rotary index and consider it as a zero at the time that you first turn on your sensor. This will even give you the idea that how gyro is drifting. If you rotate it at a faster, it will drift faster too.
angle = previous_angle + angle_change
For accelerometer the reading from sensor should be equal to rotary index.
For filter output, the reading  rotary index should be equal to filter output.

Wednesday, 11 January 2012

All the projects I have done (MIT, please read this) ((there is no technical information in this post))

I have applied to MIT. There was an empty text box for blog address so I decided to fill it up by my blog address. Then I was like let’s explain whatever I did back in high school and afterward. So if they come here, they may read it. I can also make sure if they have checked my blog by a high chance. (My blog is not that famous and I don't have a lot of audience from USA.) Anyway let's get to the point.
The first project that I did comes back to my secondary school time, when I was 14. I made bridges models. At the time I did not know anything about hydrophilic systems. Once I was in our school lab and I notice that glass made syringes are so frictionless that gravity can move their piston. I wanted to make few bridges with moving part, so I thought that I can pump water inside the syringes and then it gives me movement in one direction. Then I did a short research and I used cars water pump (the one for cleaning front glass). We were one of the best projects in the exhibition that year although they did not give us any certificate. We had few bridges with moving parts.
I have done tones of small project with my LEGO RCX and NXT (LEGO MINDSTORMS). I made line follower, automatic car, automatic gear shifting (I made manual gearbox of old LEGO Technics and I made it automatic) and a lot more which I can’t even think of it now.
The other major project I spent a lot of time for it was my junior soccer player robot. I worked on it for few years and happily I have the pictures of my robots. (http://imageshack.us/g/259/cimg0921.jpg/) and ( http://imageshack.us/g/267/cimg2661.jpg/ )
The other project that I did was a system which could produce distilled water, petrochemical and electricity. The inputs of the systems were sunshine, wave energy and ocean water. I chose a place in southern part of my country and I did a lot of calculation to prove that it is possible to bring the project to reality. You can see its pictures here (http://imageshack.us/g/593/cimg1534x.jpg/).
Then there was a gap till the point that I entered Taylor’s University. I started a quad with 8 amazing friends. We have done a lot of research about PID control system, filters and we learned a lot of things. I was in the lab at all the time. They used to say that lab is my first house and sometimes I go to my second house to take shower and personal stuff like that. At first we had some difficulties but after a short while the dean of engineering Associate Professor Dr. Mushtak Al-Atabi and deputy dean Dr. Edwin Chung Chin Yau were supporting us in all ways. Meanwhile we were contacting Prof Dr. Benjamin Koo and he was supporting us and he helped with our trip to China and our preparation for presenting our project in CDIO conference.
It was an amazing experience with all my friends in china and pressure of presenting our project in front of professors from different parts of the world.
After CDIO conference we started working again and we developed the project to this point:
We attended the engineering fair at Taylors university and we won following awards:
1)       1) The Best Research Project Award (Year 1) by Fibertex Personal Care Sdn. Bhd.
2)       2) The Most Needed Project Award (Year 1) by Rhombus Castors Malaysia Sdn. Bhd./ University of Western Australia
3)      3) The Most Technologically Advanced Project Award (Year 1) by National Instrument Malaysia Sdn. Bhd.
4)      4) Joint Winner of The Best CAD/CAM Design Project Award by University of Birmingham
Now, I am working on new quad, and that is the main reason I have this blog. I will post more pictures of my new quad soon.

Thank you for your time. (there is no technical information in this post)