Shop OBEX P1 Docs P2 Docs Learn Events
QuadCopter Build (My Rambling Thoughts Questions and Comments) — Parallax Forums

QuadCopter Build (My Rambling Thoughts Questions and Comments)

ShawnaShawna Posts: 508
edited 2014-02-22 11:07 in Robotics
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.:smile:

I will post videos and pictures of my progress.



Thanks
Shawn
«1

Comments

  • ShawnaShawna Posts: 508
    edited 2013-08-08 18:02
    Reserved for Links
  • ShawnaShawna Posts: 508
    edited 2013-08-08 18:02
    Reserved for something else.
  • ShawnaShawna Posts: 508
    edited 2013-08-08 18:03
    What the hell, I am going to reserve one more spot.
  • ShawnaShawna Posts: 508
    edited 2013-08-08 18:46
    I have been playing with Jason Dorie's 15 Bit DCM code for the last couple of weeks. I started out with my flight loop running at 200Hz and got Jason's code running real nice on my Quad X525 frame.
    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
  • teganburnsteganburns Posts: 134
    edited 2013-08-08 23:57
    Wow this is a great thread., doing the same thing but with a Tricopter. (I assume you are making this autonomous?)

    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!
  • ShawnaShawna Posts: 508
    edited 2013-08-09 11:02
    Tegan, a Tricopter sounds like a fun build. Mechanically I think they are more complicated, so that is one reason I went with a quad.

    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
  • ShawnaShawna Posts: 508
    edited 2013-08-09 15:13
    So I burned through probably 5 batteries today trying to perfect the stability of the quad, by adjusting the PID loops. Guess what? My PID values for my 100Hz flight loop ended up pretty much at the same values for my 200Hz flight loop. This so far is baffling me.

    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
    iGz :=   Gx / 5  
    iGx :=  -Gy / 5
    iGy :=  -Gz / 5
    


    Modified
    iGz :=  ( Gx * 10)/25  
    iGx :=  (-Gy * 10)/25
    iGy :=  (-Gz * 10)/25
    
    

    I also had to change this.
    Which controls how much the ACC is used to correct error in the matrix.

    Original
    ErrorAxis[0] ~>= 8   
    ErrorAxis[1] ~>= 8   
    ErrorAxis[2] ~>= 8
    
    
    


    Modified
    ErrorAxis[0] ~>= 10   
    ErrorAxis[1] ~>= 10   
    ErrorAxis[2] ~>= 10
    
    
    

    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.
  • ShawnaShawna Posts: 508
    edited 2013-08-10 11:43
    Here are a couple pictures of my current quad setup.



    DSCN2427.jpg
    DSCN2428.jpg
    DSCN2433.jpg
    DSCN2434.jpg
    DSCN2435.jpg


    Here are a few pictures of a Gimbal and Landing Gear I am putting together for the DJI450 frame I purchased.


    DSCN2437.jpg
    DSCN2438.jpg
    DSCN2440.jpg



    There is a lot of play in the gimabal setup but I think it will work to test my gimbal code.
    1024 x 768 - 311K
    1024 x 768 - 261K
    1024 x 768 - 285K
    1024 x 768 - 318K
    1024 x 768 - 245K
    1024 x 768 - 112K
    1024 x 768 - 123K
    1024 x 768 - 116K
  • ShawnaShawna Posts: 508
    edited 2013-08-14 15:05
    I am in the process of putting together my DJI frame.
    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.

    DSCN2443.jpg
    DSCN2451.jpg
    DSCN2452.jpg
    DSCN2455.jpg
    DSCN2458.jpg
    DSCN2459.jpg
    DSCN2461.jpg
    DSCN2462.jpg
    1024 x 768 - 93K
    1024 x 768 - 101K
    1024 x 768 - 122K
    1024 x 768 - 106K
    1024 x 768 - 110K
    1024 x 768 - 144K
    1024 x 768 - 162K
    1024 x 768 - 149K
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-08-15 20:03
    I'm liking your progress so far. Where did you get the Quad kit? I have been thinking about doing one myself and if I ever get around to it I would like to make sure I get quality parts. I really like the Elev-8 but that is a bit out of my price range right now.
  • ShawnaShawna Posts: 508
    edited 2013-08-17 11:45
    This is where I got the kit for the pics in post 10. It is a DJI 450 Flame Wheel. http://www.uavproducts.com/product.php?id_product=39
    I
    t 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.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-08-17 13:04
    Well, $200.00 is not bad compared to the Elev-8. Do you get the BEC from the same place? I may buy a hubspan first to learn and then I may go this route after my Wild Thumper is completed.

    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.
  • ShawnaShawna Posts: 508
    edited 2013-08-17 18:01
    I got the BEC from HobbyKing. http://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=10313. I was looking for a linear BEC but had no luck. The one in the link is a switching BEC. I am wondering if some of the noise in my sensor readings is coming from the power supply on my proto board, it has a switching regulator on it. The proto board I am going to use for this build has linear regulators on it. So hopefully it will not matter that I am using a Switching BEC to power the board.

    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.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-08-17 22:18
    your Wild Thumper project looks interesting.
    Yea, I had to put it on hold because of a family illness in Montana. Just got back last week and I have some rearranging to do in my Office/Shop space and then will be back on it again. It is a pretty nice setup and I got it when Parallax had their 10 percent off everything which made it worth it. I have tons of sensors and other stuff to put on it. Since it can carry a payload of up to 11 pounds I pretty much can do what I want and will still have room!!! Keep us posted on your project. Like I said, once my WT is completed I have my sites set on some type of Quad or Hex.
  • ShawnaShawna Posts: 508
    edited 2013-08-18 11:15
    I finally got a video of the 100Hz DCM code running. There was a slight breeze but not too bad. I didn't have time to take it to the park so I just shot it in front of my house. I lost control of it for a second in the video and about took out my wife, myself, and the house but some how I managed to recover.

    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.
  • ShawnaShawna Posts: 508
    edited 2013-08-22 18:10
    Well, I think I have burnt myself out on this project. My son started school this year and I am starting a new job in a week and I have a lot to wrap up at work. Not to mention I have been pushing pretty hard on this project for almost a year. I think my time for this project will be spent browsing the internet for information on different aspects of the project.

    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
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-08-23 18:41
    Well, If you are "really" burnt out on it, you could always send it my way until I get to that same point!!!!
  • ShawnaShawna Posts: 508
    edited 2013-08-24 10:09
    NWCCTV, you need to get your Wild Thumper project done, then you can show me how to build a quad.:smile:
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-08-24 17:05
    show me how to build a quad
    Hmm, I was just going to follow YOUR instructions!!!!:smile:
  • ShawnaShawna Posts: 508
    edited 2013-08-24 17:11
    I was just going to follow YOUR instructions!!!!

    Oh, you can follow them. Just make sure you have riot gear and a shot gun handy. Thats what I do.
  • ShawnaShawna Posts: 508
    edited 2013-09-01 07:10
    I got to play with the quad all day yesterday off and on. I have been having this slight wobble or oscillation problem, I think I have pinpointed the problem. I thought the problem was coming from my accelerometer, so I did a number of test and I am going to rule this out. I am pretty sure that my wobble is coming from too much P in my PID loop. The weird part of the wobble is that it is magnified when I apply yaw. I think I now why this is also. Two of the arms on my quad are twisted and now the motors are not pointing straight up, when I yaw these motors either increase or decrease in rpm's . I think this is causing the quad to pitch or roll or both and the PID loop is trying to fight it.

    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.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2013-09-01 15:08
    What you're doing is often referred to as "feedforward" control (the opposite of feedback control). The way your quad was previously set up, you were measuring the difference between your desired angle and your current angle, and responding to changes in that difference. When the user pushes on the control stick, you know you're about to have a measured difference between the two, so in anticipation of that you can start pushing the motors before you even know what the difference will be - It's a pretty common approach to dealing with control lag.

    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.
  • teganburnsteganburns Posts: 134
    edited 2013-09-11 19:12
    @Shawna / what are the sensors you are using? And do you mind posting your code?

    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

  • ShawnaShawna Posts: 508
    edited 2013-09-15 11:50
    @tegan I am using the 6 DOF board from sparkfun, it has a ADXL345 and a ITG3200.

    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
  • ShawnaShawna Posts: 508
    edited 2013-12-14 08:53
    Well, it has been awhile since my last post. Honestly I have not made a whole lot of progress on the quad, but my interest has been peaking lately. I have got my frame finished for the most part, I just need to make an adapting plate to secure my control board to the DJI450 frame. I have finished the control board and I think I have got my program reconfigured to work with the new IMU breakout board. I switched from the Sparkfun 6DOF to the Sparkfun 9DOF(https://www.sparkfun.com/products/10724), which uses the same ACC and GYRO but adds a Magnetometer. I have to go to a training class this next week, so there will be no working on the frame, but I hope to get some coding time in for the magnetometer.


    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
  • ShawnaShawna Posts: 508
    edited 2014-01-21 17:15
    It took me longer to do than I expected, but my new quad frame is finally put together. I still need to secure the battery a little better and tidy some wires, but its pretty much built. I am in the process of cleaning up my code right now and tweaking it slightly.

    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.

    DSCN0028.jpg
    DSCN0059.jpg
    DSCN0055.jpg
    DSCN0052.jpg
    DSCN0045.jpg
    DSCN0041.jpg
    DSCN0037.jpg
    DSCN0033.jpg
    DSCN0030.jpg
    DSCN0060.jpg
    1024 x 768 - 38K
    1024 x 768 - 55K
    1024 x 768 - 70K
    1024 x 768 - 48K
    1024 x 768 - 68K
    1024 x 768 - 66K
    1024 x 768 - 71K
    1024 x 768 - 74K
    1024 x 768 - 95K
    1024 x 768 - 81K
  • ShawnaShawna Posts: 508
    edited 2014-01-21 17:17
    And a few more.
    DSCN0064.jpg
    DSCN0063.jpg
    DSCN0061.jpg
    DSCN0071.jpg
    DSCN0072.jpg
    1024 x 768 - 73K
    1024 x 768 - 93K
    1024 x 768 - 71K
    1024 x 768 - 74K
    1024 x 768 - 61K
  • ShawnaShawna Posts: 508
    edited 2014-01-29 19:37
    I finally got the quad all put together, time to start trimming and tuning it.

    DSCN0091.jpg
    DSCN0092.jpg
    DSCN0094.jpg
    DSCN0093.jpg
    1024 x 768 - 93K
    1024 x 768 - 98K
    1024 x 768 - 91K
    1024 x 768 - 86K
  • teganburnsteganburns Posts: 134
    edited 2014-02-08 17:21
    Looks Great!! What's the flight time with that battery? I was thinking of getting a bigger battery like that.
  • ShawnaShawna Posts: 508
    edited 2014-02-22 11:07
    I am running a 4S 4000maH battery. It will fly for about 10 minutes. I have some more info on the project but I have not had time to post what I have learned recently. I have moved away from this project because of some technical difficulties that I am not sure how to resolve. I would like to get back and post some code and findings, but it is going to be awhile.
Sign In or Register to comment.