Saturday, June 27, 2015

Sonar Development: Towards Something That Works In Water

Bathymetric survey data from a NOAA ship.

After a few months of distractions to prepare for a new kid, build a quadcopter, and work a bunch, I'm trying to get my sonar project moving forward. As documented in previous articles, I've got a simple digital sonar working in air. It was a simple way to test the echo detection algorithms. I'm convinced if I can figure out a way to use piezo transducers to transmit sound in the water, I can make it work.

Previous installments:

Audible Frequency Chirp Sonar on the Stellaris Launchpad

Initial Experiments - Sonar in air with a conferencing speaker mic and Python

So the next challenge is how to mount the piezo element and efficiently couple the sound to the surrounding water. One way to do this appears to be to pot the transducer in a potting compound that closely matches the density of water.

This article from NOAA on building hydrophones for listening to whales details one way to pot a transducer, and also includes a high gain amplifier circuit. My current plan is to build one, and figure out how to get the ADC on the Launchpad reading the audio. From there, I can make a transmit circuit. The challenges will likely be in acoustic coupling, transducer selection, and getting enough power into the water to travel a reasonable distance.

I considered using piezo disks, but I found that getting any sort of output from them at all requires them being mounted at either their edges or nodal points in a resonant cavity known as a Helmholtz chamber. I don't think I can manufacture one to the precision needed for the small size. I'm going to work first with cylindrical piezo units as used in the hydrophone above.

I intend to try one with a resonant frequency in the audible range - that's not going to result in very good resolution, but should be easier to debug since I can hear it and use PC audio equipment to measure it. Once that works, I'll switch to higher frequencies.

The next step is to build a functioning hydrophone with a piezo element, get it working with the op-amp, and get that feeding into the ADC of the Launchpad. That will complete the receiver side, and test the methods of acoustically coupling the transducer to the water.

Sunday, June 14, 2015

F450 Quadcopter Mods: Walkera G-2D Gimbal and XIaomi Yi Camera

I built my F450 with aerial video in mind. Once I got it flying, it was time to select a camera and gimbal. 

The camera needs to be able to record at high framerates to reduce the "jello" effect of rolling shutter. If you try to strap a cheap keychain camera to the frame of your quad, it is very likely that the result will be a garbled mess of distortion. This is because the CMOS sensors in those cameras scan each frame into memory over a small period of time. Vibration causes the frame to move as it is being captured. 

Additionally, even if you get the vibration under control, the rapid movements in all directions as the quad flies around will make you ill. It's not a lot of fun to watch. 

The solution is a camera that can record at 60 fps and a motorized gimbal to compensate for the motion of the quadcopter and keep the camera level. There are gimbals that use servo motors, but the best use brushless motors, which are quiet and smooth. They nearly instantly compensate for the motion in pitch and roll that occurs from pilot inputs and wind gusts.

I selected the Xiaomi Yi camera. This has the same imaging sensor as a GoPro without some of the frills, and is much less expensive. They are currently available on Amazon Prime for $88. The don't come with a case, or even a lens cap. The Android version of the app is rather untrustworthy looking - it is currently distributed off of a file sharing site I normally associate with pirated software, rather than from the company's website. "Here! Run this random APK from the Internet on your phone! It will be fine!"

Yeah. I dug out an old phone that doesn't have access to any of my important stuff and used that. I used the app to set up the video mode (60 fps at 1080p) and timelapse mode (still frame every 3 seconds). You can toggle between these modes with the camera's button - you really only need the app once.

I also ordered a Walkera G-2D 2-axis gimbal. This only compensates for pitch and roll, but uncommanded yaw motions don't seem to be much of a problem. I am extremely pleased with this gimbal for the money. It has an onboard regulator, so you can run it straight off your 3S lipo pack. I connected it to my main power line on the quad and it fired right up. It supports the use of auxilliary channels on your receiver to aim it in roll and/or pitch, but it doesn't require it - you can set the tilt and roll angle with a couple of trim pots and leave it alone, and it requires no connection to your receiver. It even comes with a small tool to adjust the pots with and the needed Allen keys. It worked right out of the box, and bolted directly onto the lower frame of the F450, aligning nicely with the slots on the lower frame. I secured it with 4 bolts.

One note: the gimbal is not designed for the Xiaomi Yi and the existing mount doesn't fit. I found that the frame could easily be removed, a 1/4" cardboard shim cut to level off the mounting plate, and a large zip tie easily secures the camera to the gimbal. There is probably a more dignified way, but that works just fine.

I am really pleased with this combo. I am still seeing some vibration in the video that I want to eliminate, but it's by far the best video I've gotten from an RC model so far. More to come on the vibration problem as I work it out. (Update on how to fix this below)

Here are a couple of still frames of a local park, shot in timelapse mode.

And some video....

Video Test Flight 3 - Xiaomi Yi and Walkera G-2D Gimbal on F450 from Jason Bowling on Vimeo.

Update on the vibration problem, and a note about the camera:

1) The vibration was improved by changing the vibration dampeners that came with the gimbal with more rigid ones from HobbyKing. The dampeners that it comes with are too soft.

2) Additional improvements were made by inserting soft foam earplugs into all four vibration dampeners.

3) The lens rectification function on the Xiaomi Yi makes the edges of the video very blurry. Once I fixed the vibration, the edges were still bad. I turned the lens rectification off, and it's much better. Here's a test flight with these improvements.

TestFlightNoFisheyeCompensation from Jason Bowling on Vimeo.

Saturday, June 6, 2015

F450 Quadcopter Build and Flight Testing

This is my F450 quadcopter. There are many like it, but this one is mine.

I have a lot of experience with RC airplanes, but I'm new to quadcopters, so I want to document the build in case it is useful to others. I learned on the excellent and incredibly affordable Syma X1, which is serious fun for the money and a perfect trainer when flying indoors. I put a number of flights on an ARDrone, until it went berzerk and parked itself in a very tall tree. At that point. I decided something with a real, proper RC system was in order.

A few abbreviations:

ESC - electronic speed control. Converts control inputs from you (through the flight controller) into a throttle output to one of the motors.

FC - Flight controller - a small microprocessor board with gyros and accelerometers that stabilize your quadcopter in flight. It handles the mechanics of keeping the machine in the air by making small adjustments to the motor power many times a second, and turns your stick input into your desired motion.

BEC - battery eliminator circuit. Steps down the main flight pack's 12.6 volts to the 5V the receiver and flight controller needs. A regulator.

3S - a 3 cell lithium polymer battery.

Here's what I selected for parts:

A combo containing the frame, motors, ESCs, and propellors. 

This contained:

1 x F450 frame kit
1 x F450 Landing gear( 4pcs/set)
4 x Sunnysky X2212 980KV Brushless motor
4 x HP SimonK 30A Speed Controller
2 x 1045(CW+CCW) Black Propeller
2 x 1045(CW+CCW) Red Propeller

Knowing what I do now, I'd not have bought this as a kit. I would have bought the components individually. More on that later - live and learn.

KK2.1 Flight Controller (FC)

FlySky FS-T6 radio system

Turnigy 2200 mah 3S Lipo pack

That covered the obvious stuff. Then as I examined the kit I determined I needed some less obvious stuff.

Heavy silicone wire to connect the quad's power distribution to the battery

XT60 connectors. You need at least one on the end of those nice wires you just bought. The other end gets soldered to the power input on the frame's power distribution system.

A set of 5 male to male JR style servo connectors. These go between the flight controller and the receiver outputs.

A 5V switching regulator, because I don't trust the linear regulators on the ESCs.

A dedicated low voltage alarm. I never got the low voltage cutoff on the flight controller to work right. This one works great. You need one or the other, since quadcopter ESCs don't have a low voltage cutoff like airplanes do. Set to 10.8V, you have 30-60 seconds to get it on the ground before you lose power.

A pack of 3S balancing wires, to connect the battery to the low voltage alarm.

Whew. OK. Once you have the stuff, building it is actually quite easy. You need a higher power soldering tool - I used a soldering gun - since you need to solder heavy wires to the copper traces on the frame. There is an extremely helpful build video from Legend RC here:

Other very useful links if you are new to quadcopters:

Identifying the props and their locations

Connectors and Plugs for Quadcopter Newbies

A great guide to quadcopter wiring. This goes over how to connect the various boards.

Be sure to read the KK2.1 manual section on powering the board carefully. I chose to cut the red wire from all 4 ESCs that connects to the FC motor outputs and power it with a dedicated switching Battery Eliminator Circuit (BEC). The switching regulator runs cooler and more efficiently that the linear regulators on the ESCs.

One of my ESCs was dead on arrival. I didn't find it until the kit was 90% built. I couldn't return the whole kit, and even returning the dead ESC to China would have a been a serious pain. I tracked down the same part on Amazon and bought a replacement, along with a spare. This is a serious drawback to buying the kit.

After very carefully checking propellor rotation direction, as well as making sure the correct prop was on the correct motor, I did a quick test flight, and was surprised to find that it flew fine with stock settings on the KK 2.1. I did make some PID adjustments, but it was quite controllable. 

There were bugs to work out. My KK 2.1's low voltage alarm, set to 10.8V, would howl continuously in flight, and cease on landing. I never figured out why. I turned it off and installed a dedicated low voltage alarm, listed above, and it works superbly. 

On the first few flights, I have trouble with split second instances where the motors would just STOP. All at once, for a fraction of a second. It would fall abruptly, and then recover, unless I happened to be low. I first blamed the linear regulator on my BEC.I tested with a dedicated receiver pack, did a quick test flight, and presto, it was fixed. Victory! I installed a nice dedicated switching BEC, went flying, and SMACK, it fell out of the sky again. It finally dawned on me to range test it. On the ground, with the motors spinning just above idle, I started walking backwards. At 40 feet or so, the receiver light blinked out. A few steps forward, it came back on.

Argh. Radio trouble. Gambled. Ordered new receiver. Got lucky - that fixed the problem. No way to return cheap dead receiver, at least not economically, so into the trash it went and I ate the $15. But it passed a range test and works fine farther than I can see the quadcopter.

ALWAYS RANGE CHECK YOUR MODELS. I have known this for years, and got lazy, and it bit me.

Several more flights, and a new problem cropped up. Propellor blades started randomly separating from the hubs. Once in flight, causing a crash from 30 feet, and once on takeoff, narrowly missing me. Cheap plastic props that came with the kit are absolute garbage - to the point that they are dangerous. Into the trash they went. Ordered some 10x4.5 carbon fiber props, which are absolutely superb. My flight time immediately improved from 7 minutes to 9. I'm not sure if they would fail before the bones in my finger would, so... respect. 

One final note about propellors - they aren't perfectly balanced from the factory. Take the time to balance them - mine flew much more smoothly and quietly than before they were balanced. My video quality dramatically improved too, since it eliminated the jello/rolling shutter artifacts I was getting.

I borrowed a friend's Dubro prop balancer and used scotch tape on the back of the blades to balance them. Went surprisingly quickly. I intend to buy a balancer and add it to the periodic maintenance list. I never bothered with planes, but it matters a lot for multicopters.

I now have perhaps two dozen flights, and the bugs are worked out. It is a reliable machine, climbs well, and has plenty of lifting power. I printed a camera mount for an ancient Canon point and shoot camera and it hauled it around just fine - all 1/2 lb of it. I have since upgraded camera and added a gimbal - more on that soon.

Knowing what I know now, I would not have bought the kit - I would have bought the same components, with decent propellors. That way, if I got a bad speed control, I could return it, rather than the entire kit.  Other than that, I am pretty pleased with it.