In a recent post I showed how to get live IMU telemetry from a Flip32 flight controller using an inexpensive Bluesmirf Bluetooth modem from Sparkfun. After getting that to work I figured it was time to branch out to some external sensors.
I played around a bit with PX4Flow and LidarLite but thought that for doing something like altitude hold it would be safest to stick with an inexpensive, high-quality ultrasonic sensor like the MaxBotix MB1240, which MaxBotix suggests for quadcopter applications and other environments with lots of vibration and potential electrical noise. However, based how easy it was to use the Flip32 to read I^2C signals, I wanted an I^2C sensor instead of one that uses TTL, analog voltage, or PWM as the MB1240 does. So I was delighted to find the MB1242, which is the same sensor but with I^2C.
As you can see in the photo below (with the Bluesmirf removed), the same four-wire cable that I used for the Bluesmirf / UART connection was perfect for the I^2C connection, and this time I didn't even have to clip and solder it! (though I did use a Sharpie to color the ground wire black for safety):
Here's a side view showing both the Bluesmirf and I^2C connections:
Having designed and 3D-printed a simple mount for the LidarLite and stuck it firmly to the lower plate with E6000 ("Goop"), I decided to keep that plate attached and print a mate for it to carry the MB1242. Since the MB1242 didn't have enough room for Dee's nuts, I used an additional pair of nylon M3 standoffs to secure the MB1242 to the new mount:
This video shows a test flight of this rig, in the usual "Dronehenge" aerodrome in the Washington and Lee Science Center. As with the IMU hack, I wrote a Python program to display the Bluetooth AGL telemetry in real time. (The Python package I used for the display is on github for anyone who wants to try their hand at this kind of live telemetry visualization.) To support the MB1242 I had to modify the Baseflight firmware to read I^2C from the unit and send it to the UART. This amounted to around 20 lines of C code (send a request byte to the MB1242, then 10 msec later read the two bytes for AGL in cm). On the laptop, our MSPPG compiler made it easy to generate code that parses the new sonar message from the Bluetooth stream.
Of course, my real goal is to modify the firmware to support altitude-hold based on the sonar AGL. To get started on that I used PyQuadSim, our Python-based quadrotor simulator, with a simple PID controller to keep the altitude steady. If I can get that working, I will post a link to the modified firmware for others who want to try it.
Comments