GPS altitude hold is good for +-5m, but what if you want more precision than that, closer to the ground. ArduCopter team member Randy Mackay. He explains what it takes (this is also in the manual):
To give it a go do this:1. get yourself one of these Sonars and attach to the bottom of your quadhttp://www.sparkfun.com/products/8504 <-- the cheaper LV ($28)http://www.sparkfun.com/products/9495 <-- the slightly more XL ($50)2. attach it up to AN1 (the Analog2Digital port on the very back
right of the oilpan near the CLI switch. AN5 is the outmost, so count
in from there to AN1).3. comment out this line in ArduCopterNG.pde://#define UseBMP4. make sure this isn't commented out just below in ArduCopterNG.pde#define isRANGEFINDER5. if you're using the LV sonar you will need to change this line in ArduCopterNG.pde:AP_RangeFinder_MaxsonarXL AP_RangeFinder_down;to be like this:AP_RangeFinder_MaxsonarLV AP_RangeFinder_down;6. you'll need to reset your EEPROM values or go into the CLI menu and select 'o' and set your Sonar PIDs to 0.8;0.3;0.7I had to make one change though that affects the existing functionality
... if you're UseBMP (i.e. using baro for altitude hold) it's now
possible to do altitude hold even though you're not doing GPS hold (I.e.
if you don't have a GPS lock). I think this is ok.So the Barometer altitude control and sonar altitude control continue
to be quite separate functionality that can't be used at the same time.
Clearly we need a nice transition from one to the other when you go out
of sonar range. anyway still, thinking about how to do that.
We may be moving the sonar input port to the Pitot port on the IMU board. Note that the ArduPirates are now handling all public releases of the ArduCopter NG code, they'll be implementing this in their own way. There's already a version of that in their code here.
Comments
great! my bad in the first place for not having the wiki + code consistent. Thanks and good luck!
-Randy
Taylor
Be careful about your throttle position at the moment you turn on the altitude hold. The code uses this value as a base value so if you have it too low or two high, no matter how hard the code works, it won't be able to keep the copter from climbing or descending (the code will not modify your throttle more than about 10% above or below this initial value).
I guess you're not using standard ArduCopter frame right? That's fine but you'll need to experiment a bit to get the PID values right. If you're slowly decending, then it seems to me your PID values could be too low. I'd try increasing them all by 10%.....but actually i suspect the issue is with your throttle at the moment you turn on the autopilot as mentioned above.
-Randy
P.S. I've updated the wiki with some of info here so people who follow in your footsteps have an easier go at it.
Well this is my problem as of now. First I flew and then enabled the sonar without having the PID values adjusted and the quad ascended into the air and I had to turn off sonar hold and bring it back down. Then I updated the PID values using the CLI and then when I would switch to sonar hold, my quad copter slowly descended until I take it out of sonar hold mode. So I don't know what to change to fix this.
Oh. And I have already tested the sonar with an arduino and the readings are dead on.
Taylor - no it will just determine how aggressively the throttle is modified to try and maintain the altitude.
the way you control is the same as if you're using Altitude hold with the barometer:
1. get the quad flying at a some what stable altitude
2. flick on the autopilot
it should hold it's altitude now. move the stick up or down to make it ascend/descend. Note that in this mode there is a "deadzone" around where you had the throttle when you flicked on the autopilot (this is on purpose to make it easier to tell it to stay level).
@taylor - thanks, nice catch. I've updated the code to match the wiki and it should be using AN5 (for the moment although I plan to change it to use the Telemetry port in the next couple of days). You can actually change which of the ports at the back it uses (from AN0~AN5), by changing this line in System.pde.
AP_RangeFinder_down.init(AN1);
http://code.google.com/p/arducopter/source/browse/trunk/ArducopterN...
Sorry, I missed your previous comment before about the PID values. If you want to update these:
1. set the APM's CLI switch to the back (CLI switch is the white switch at the back, right of the Oilpan)
2. connect with Arduino's Serial Monitor @115200
3. when the CLI menu appears select "o"
4. when it prompts you for new PIDs, enter in three number separated by semi colons (;). For example the standard PIDs are P=0.8 I=0.3 D=0.7 so you would enter:
0.8;0.3;0.7
These values should work for most people I'd think. but you could try increasing/decreasing P (the first term) if you like.
If you're having problems with the sonar though, I'd first try out the AP_RangeFinder libraries example sketch:
http://code.google.com/p/arducopter/source/browse/trunk/libraries/A...
If you do choose to use the example sketch, you should ensure the code is modified to use the rangefinder you have by uncommenting/commenting out the appropriate line in the code. I.e. the default code in the example pde issing the LV rangefinder.