QuadCopter Build (My Rambling Thoughts Questions and Comments)
Well, I am going to start an official thread for my QuadCopter build. I have started multiple threads asking questions on different aspects of putting a quad together. In almost all of these threads I try to put together a meaningful title in the hopes someone will be able to search and find them helpful. You guys have been great at answering my questions in these threads, but I have a tendency to get off subject. So I am going to start this thread so I can just babel on about anything any time. Kind of like right now.
I will post videos and pictures of my progress.
Thanks
Shawn
I will post videos and pictures of my progress.
Thanks
Shawn
Comments
I decided that I wanted to start playing with a compass and determined that I was not going to have enough left over time in my flight loop to do this. So I decided to change my flight loop to 100Hz and see if I could get the quad flying well.
After a lot of tweaking I have achieved very good results. I will post a video as soon as possible.
My quick thoughts on tuning a PID loop.
But first a little bit about how my PID is set up.
D stands for Derivative. I am dumping my raw gyro values into this part of my PID loop.
P stands for Proportional. I am taking the actual angle of the quad, from the DCM code and comparing it to a desired angle computed from the inputs from my receiver.
I stands for Integral. This is basically a running total of error from the proportional error.
This is how I tuned my PID loop. This may not be the best way but so far it has worked for me.
1) Set P and I to 0.
2) Increase D until a slight oscillation is noticed and then back off 10%.(Note that if your PID is set up like mine you will have no control over your quads angle of attitude at this point, only its throttle.)
3) Leave I at 0 and increase P until a slight oscillation is noticed and then back off 10%. You should be able to control the quad now. The more P you add, the more responsive the quad will be.
4) Now increase I until a slight oscillation is noticed and back off 10%. The oscillation added by the I term will be kind of slow and lazy(thats the best way I can explain it).
If in any of the steps above, reducing the value by 10% does not remove all of the oscillation, reduce the value more. You do not want any oscillation at the end of any step.
EDIT 8-8-2013
After playing with the steps above some more I think they are more of a ball park for tuning from scratch. I wrote these steps while playing with the quad on a slightly windy day. It seems with less wind I had to back the values off more than 10%.
END EDIT
There are some excellent guides for tuning PID loops on the web, but I think tuning them depends on your particular usage.
One more thought on tuning PID's and I have not fully tested this yet but, I think noise from the ACC will be amplified when you raise your PID values. I think the cleaner you can get your sensor readings the higher you will be able to raise your PID values which I believe will result in a more stable quad.
Shawn
Are you building off of the QuadOpen(attached) from Jason? What is the value of D before reducing 10%?
It's really cool to see someone else working on the same kind of thing as me. Great minds think alike!
I have never actually tried Jason's QuadOpen program on my quad. I have read through the code probably 50 times, in an attempt to understand it. I stripped lots of pieces out of it and then modified them for my uses.
I am not actually using the PID object per say from Jason's code. I converted the PID loop from the object into something I could understand. So I am not sure what value you would want to start with for the D term.
I have been playing with the steps above and they will provide a good hover, but when transitioning from flight to hover the method seems to be flawed. I have been getting oscillation during the transitions. I am beginning to think it is a trial and error thing only.
I am not sure of the actual definition of autonomous, but some day I would like to add heading, altitude, and position hold to the quad. If I ever get that far I suppose it could be programmed to be autonomous. My problem now is my lack of coding skills. I can't seem to get everything done in a timely fashion. I am kind of excited to see the prop II come out, if my existing code could be ported to the prop II the code should really fly.
I am pretty sure that Jason's QuadOpen code uses the gyro only, which can not be used to maintain attitude. I skipped trying to make that code work on my quad and jumped right into adding an accelerometer. I started with a complimentary filter to fuse the gyro and acc code together. I am now using Jason's DCM code to fuse the two together. The complimentary filter works fine for maintaining a hover, however during flight there is a nasty thing that happens. When applying yaw during a pitch or roll maneuver, the complimentary filter cannot maintain an accurate orientation, it gets confused. The DCM(rotation matrix) is by far superior it can deal with these types of maneuvers. The simple complimentary filter is by far easier to understand. To be honest I do not understand the math in the DCM code, thankfully Jason is kind enough to share.
I would strongly recommend starting with Jason's code and then expanding from there. I think in the long run I would have been better off starting with the gyro only code. Start off simple and then add to it as you get more comfortable with all of the different aspects of making your creature fly.
Have Fun with Your Build
Shawn
I did this to Jason's DCM code to make it function at 100Hz instead of 200Hz.
This section converts the gyro range into values that can be placed into the Matrix
Original
Modified
I also had to change this.
Which controls how much the ACC is used to correct error in the matrix.
Original
Modified
There is a slight difference in performance between the 100Hz and 200Hz code but not much. I can see why faster would be better but for proof of concept and adding other sensors to the quad this should be good enough for now.
The compass and barometer can't be read at 200Hz anyways.
I also left my sensor sample rate at 200Hz.
Now if only the wind would go do, I could shoot a video.
Here are a few pictures of a Gimbal and Landing Gear I am putting together for the DJI450 frame I purchased.
There is a lot of play in the gimabal setup but I think it will work to test my gimbal code.
There is not a whole lot left to do on the frame but my time is limited. Along with the frame I have been learning about rotation matrices(DCM) and magnetometers. Also I have been looking into how to use an accelerometer and barometer for altitude hold.
Here are a few more pics.
It was not super cheap, it came with ESC's, Motors, and Props. In order to run a 4 Cell lipo a BEC is required also.
I still do not have the frame completed yet to test and see if it is any good, but I have heard good things about the DJI 450 frames.
The Gimbal and Landing gear in Post 9, did not come with the kit, I bought that separately and I have my doubts on how well I will like them.
The quad in post 9 is a X525 frame. It is the current and only frame I have ever used, it works pretty good. Since the arms are made out of aluminum I want to see if a plastic frame will have less noise from vibrations.
I haven't decided if I think the ELEV-8 is pricey. From everything I have read I think it is a very nice frame. The kit seems to have everything but a battery and controller, it comes with a hoverfly board I believe. I think it is made in the USA also so that should be worth something.
Edit: Yes, I believe the Elev-8 is worth the money, I just can not spring for one right now and I would like to have something to start off with so this might work out well.
The ESC's that came with the kit are designed to run with DJI flight controllers, they can not be programmed. I am hoping I can get them to work with my flight controller, or it will make the kit I bought a waste. You can get just the frame with no motors or esc's for $40.00 I think.
NWCCTV, your Wild Thumper project looks interesting.
BE CAREFULL when playing with RC aircraft!!!
Here is the test flight video.
Here is a short video of the quad taking off at an incline. I need to find a better way to show this. In the video I only applied throttle.
Recently I have been looking into PID loops to try and see what the different approaches are, I have not been finding much, my searching skills on google apparently are not good.
I found one article that talked about using a PID loop in combination with a PI loop. I am not sure what the advantage of using both are, I need to investigate further. Does anyone have any thoughts on this.
I am also excited to follow the progress of the Prop II.
Shawn
Oh, you can follow them. Just make sure you have riot gear and a shot gun handy. Thats what I do.
I can reduce my P term to the point of no wobble but then my controls are very soft and slow. I still get good auto-level though. I think this P term has been a problem for a long time, I have always added to much so I can get the response out of my controls that I wanted.
So I switched my control scheme up a little. The original scheme was to dump the raw gyro value into the D portion of the PID loop. Then for the set point I would scale a desired angle from the input of my controller and allow the PID loop to adjust. For instance if I pushed my pitch stick forward all of the way the program would scale the value to 45.000 degrees and dump this as the set point for my pitch axis PID loop.
Now in addition to the original scheme of dumping the 45.000 into the PID loop I am also taking the scaled angle from my controller input and dividing it by 1000 and adding it to appropriate motors. It kind of gives the PID a kick start when I want to change my angle of attitude.
It was late last night when I got this implemented but I did get one test flight in. It seemed to work but more testing is required. The whole idea of this is to get rid of the lag and laziness in response of my controller input.
I need to get my new frame put together, as I am learning on this project I am pretty sure a lot of my issues could be resolved with a better frame.
It was fun flying the quad at sunset last night, making a little silhouette in the sky, and watching the lights on the control board flash away. I find my depth perception is not real good at night I about hit one of our trees a couple of times.
You might also try boosting your D parameter. That will typically let you use much higher P values, which will also increase your control response. If the gyro readings are too noisy to feed directly in as the D, try putting them through a light low-pass filter to reduce the noise spikes (JUST for the D parameter - leave them raw for everything else). I can't say doing that will be better than what you have, but it might be worth trying just to see if it helps.
I'm using the MPU-9150 (Accelrometer & Gyro), the only problem is if i tilt the sensor forward(Accelrometer) i get a value around 16000 and if i tilt it backwards i get a value just above 0. I haven't figured out how i want to put that into an algorithm...hhmmm
Also I'm stuck on Jayson's PID controller, I sort of understand the general concept but never got a constant response when i tried it one one boom/motor.
MPU-9150 sensor --> https://www.sparkfun.com/products/11486
I am not sure what to say about your Accelrometer readings. What do the 3 axis say when the accelrometer is lying flat on a table and not moving?
I would strongly suggest using Jason's IMU driver until you are comfortable reading the sensors and understanding the meaning of the values you are getting?
As far as the PID controller goes, mine works on the same principle as Jason's. The key is breaking the code down so that you can understand it. The PID loops still have to be scaled so that the output is meaningful to you, and what you want it to accomplish. Do some research on PID loops. Here are a couple of links.
http://www.pc-control.co.uk/feedback_control.htm
http://pcbheaven.com/wikipages/PID_Theory/?p=2
I had my IMU board reading values and figured out, before I jumped into the PID stuff. Break the different aspects of the project down into parts, make each part work and then figure out how to combine them into one functioning program. By different parts I mean, IMU is one section of code, the PID's are another section of code, the receiver is another part, and so on and so forth.
What are you planning on using for orientation, complimentary filter, or DCM, or Kalman filter? Since you asked about the accelerometer I assume you are not just using the gyro.
I am kind of burnt out on my quad right now, I need to get another frame and proto-board put together before I can test anymore, and my motivation is low. I actually have been playing with the spinneret board lately.
As for the code, I would not mind sharing it but I need to clean it up a ton, and that might be awhile before I get to it. I am willing to try and answer any questions you have but my experience is fairly small. There is no way I would have gotten this far without help from Jason. I pretty much put my quad code together from bits and pieces from all of Jason's code.
Shawn
So I have questions about calibrating magnetometers. It looks like there are 2 things that have to be compensated for. The first is Hard Iron Errors and the second is Soft Iron Errors.
The HMC5883L Magnetometer is what is on the 9DOF board I have from sparkfun.
I think I have the Hard Iron compensation figured out. What I did was write a little program that stores the highest and lowest values read from the mag for all three axis. I then rotated the board in every possible orientation I could come up with. Here is the data I came up with.
mXmax = 279
mXmin = -196
mYmax = 180
mYmin = -288
mZmax = 226
mZmin = -195
If I am not mistaken the sum of the min and max number for each axis should be zero, if not an offset needs to be applied.
So for each axis if I summed the 2 numbers and then divided by 2 I get my Hard Iron offsets, which were.....
mXoffset = 41.5 = (279 + -196) / 2
mYoffset = -54 = (180 + -288) / 2
mZoffset = 15.5 = (226 + -195) / 2
So I offset my raw mag readings by these values and rotated the board around in every imaginable way and recorded the min and max values for each axis. The values were within 1 and 2 places of being centered on zero, so I think this calibration is solid.
What do you guys think?
Now for the Soft Iron calibration I am lost. This is what I think I know about the Soft Iron Error.
1) When Soft Iron Error is present, if the mag points are graphed an ellipsoid would show up instead of a perfect circle.
2) To calibrate for Soft Iron Error all three axis need to be normalized.
The normalized part is where I get lost, go figure right. All the equations I have found look like they are getting back into rotation matrices. It almost looks like it could be normalized like the acc data is normalized in Jason's DCM code but I am afraid I do not understand it enough yet to pull this off.
I think the gist of it, is this. The six values I posted above which are the min and max values for all three axis should look like this when the mag has been normalized and the hard iron offsets have been aplied.
mXmax = 238
mXmin = -238
mYmax = 238
mYmin = -238
mZmax = 238
mZmin = -238
I am not sure what the actual values would be, but the max and mins should all be the same for each axis when the board has been rotated in every possible orientation again. Am I in the right ball park even?
Thanks
Shawn
I also put together a very primitive gui that I am going to record during test flights, this way I can go back and see how values look during a live flight. I started the code for the gui about a year ago, I had some great help and advice from forum members but it was always buggy and not reliable. I decided to dive into it again last weekend and I think I have all of the bugs worked out. The bugs by the way were my own fault, it was not from the help I was given by you guys. They were timing issues mainly.
Anyways, here are the latest pictures from my build.