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.
I made this blog to share some of what I experienced.It is mostly about my quad. which you can see in the picture.
Saturday, 25 February 2012
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.
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.
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.
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
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.
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.
* 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.
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. :)
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.
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.
Subscribe to:
Posts (Atom)