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.
I made this blog to share some of what I experienced.It is mostly about my quad. which you can see in the picture.
Thursday, 2 February 2012
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.
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.
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.
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.
We went to CDIO conference. (http://www.taylors.edu.my/download/dl_thankyou.php?src=newsletter/blue_print/TAYLORS_SOE_Blue_Print_2011_May.zip&title=Blue%20Print%20Newsletter%202011%20May%20Issue)
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)
Subscribe to:
Posts (Atom)
