I've originally meant to write about propeller mounting, tracking, tightening and about my first flight (which ended up with a stripped spinner nut), but since my sonar arrived and, since installation wasn't exactly 100% straightforward, that's today's subject. So, here it is, in the photo above - the Maxbotix LV-EZ4 sonar, freshly taken out of it's zip-lock baggy, along with a 5 pin header. Which is not included. That's from my own header stash. NOBODY TOUCHES MY PRECIOUSES!
Why 5 pins? Because that's the minimum of pins that spans from the GND and +5V/+3.3V on one side of the header and the analogue out on the other. Why pins at all (instead of soldering the cable directly)? Because i want it to be easily replaceable and detachable, in case i want to experiment with it off the ArduCopter. Why EZ4 and not EZ0? Because i thought its beam pattern makes more sense for this particular application:
Narrowest and shortest beam for tiny objects. Longest and widest beam for large, uniform objects (i.e. ground). Why LV and not XL? Because it's cheaper and my Arduino/electronics/RC/'copter budget's running thin at the moment. Otherwise, XL probably would've been a much better choice.
Anyways. I've bought it from jDrones along with their little sonar mounting kit, just because i was too lazy to figure out / improvise my own way to mount it. And because it looked neat. However, first test fit ended up like this...
Mmmyeah. It would appear Maxbotix' tolerances are much looser than the margins jDrones left when designing the mount. The transducer casing isn't quite mounted at the center. Unsoldering it isn't an option, since it's epoxied to the board, so...
... a few seconds of nylon spacer dremeling later (sandpaper works too, but i'm lazy):
Much neater. Now for the header. Here's a simple little trick for soldering headers (and connectors and other components) i've learned from FreakLabs
. First flip the board and add a dab (and i really mean a dab) of solder to one of the holes:
Never ever do this with the GND hole! They're usually connected to a rather biggish ground plane, which can soak up a lot of heat. Doing that might leave you with a plugged hole you'll have a really hard time sucking the solder from. Trust me, i've been there! Okay. Now. Take the header and press it against the holes:
Mind your finger! Don't put it on the pin that's against the soldered-up hole or you might get a burn in the next step. Which is - apply heat to the hole and push the header through simultaneously:
Trim the leads as short as you can - you want the board to be as flat as possible:
Now just solder the rest of the pins (and reflow the first one). Don't be stingy on the solder, after it fills up the hole (through to the other side), it won't accumulate any further and will just remain on the soldering iron. And there we go, nice and flat:
The baggy that comes with the sonar mount kit contains a bit more hardware (can nylon be called hard
ware?) than is needed for the installation. Here's what is needed to install it on the bottom of the ArduCopter:
The sonar PCB is flat... ish... but still not flat, so it's a good idea to use some washers:
... and there we go, nice and neat:
Now. Where to put it? From the hole distance, i'd say it was meant to be put smack dab in the middle of one of the main plate vertices, like this:
... however, if you put it there, there will be no room for the battery and it will have to be mounted off-center, shifting the center of gravity quite a bit. Plus, it looks bad and interferes with access to the battery when you want to take it off / put it back. It turns out there are other two holes that fit the distance perfectly and don't obstruct the battery footprint:
You'll have to unscrew one of the nuts that clamp the arm. If you've got an ESC right above the corresponding bolt (like i did), you'll have to remove it, and mount it back when you're finished. One of the long spacers from the sonar mount kit will serve as the new nut. That also means you'll have to put the nut on the other side of the spacer (instead of a bolt). Here's the end result:
The only thing left now is to fashion a cable to hook the sonar up to the Oilpan pitot tube input. I've again made the same set of make-shift female header connectors as before. The sequence of the pins on the sonar is exactly the same as the sequence on the Oilpan - GND is the leftmost (when facing the front of the APM or the vertex of the sonar PCB with the pin header), then 5V, then analogue out/in.
The only thing left now is to enable the sonar in software. I'm using ArduPirates branch. First, let's check if it works correctly. Navigate to Libraries/AP_RangeFinder/examples/AP_RangeFinder_test and open the AP_RangeFinder_test.pde sketch. There are two lines of interest here:
Now, it would seem logical to comment the first line and uncomment the second if you have an LV model. However, it so turns out that the LV model uses the exact same scaling on the analogue output as the XL, at least in my case. Whether it's something that has recently changed, or something mixed something up, i do not know. I do know that my sonar most definitely is an LV model and that it outputs correct values with the XL routines, NOT
the LV routines. To be sure, leave it like this, run the sketch and check the output on the serial monitor, then change it to the other option and do the same. That should make it absolutely clear which one is the correct one.
The first number is the real distance/altitude, the second is the raw output. For XL (and my LV), both numbers are the same, because the absolute output of the sonar board is scaled so that they're exactly proportionate and equal with a reference voltage of 5V.
After you've verified your sonar works and you've determined the correct sonar reading routines to use, pay a visit to Config.h in the main ArduPirates sketch folder and set the two lines at approx. 251-252 (it's around line 65 for ArduCopterNG code branch) to:
#define UseBMP // Use pressure sensor for altitude hold (default) ?
#define IsSONAR // or are we using a Sonar for altitude hold?
Next up, open ArduPiratesNG.pde, find the following lines at approx. 90-91 (around the line 228 for ArduCopterNG) and uncomment the appropriate one, depending on the result of your test sketch output:
AP_RangeFinder_MaxsonarXL AP_RangeFinder_down; // Default sonar for altitude hold
//AP_RangeFinder_MaxsonarLV AP_RangeFinder_down; // Alternative sonar is AP_RangeFinder_MaxsonarLV
Compile and upload the code, switch to CLI mode and check the sonar PID values by pressing 'o'. According to defaults and the wiki, good values for the stock ArduCopter hardware should be P=0.8, I=0.3, D=0.7.
That's all, folks (for now)!
And a belated happy Easter!