Ultrasonic sensors are really useful for drones as they can be used to compute the altitude of a drone without a GPS signal. This enables us to automate the drone indoors, which would otherwise be impossible, as the flight controller needs the altitude data to be able to maintain the height. Usually, flight controllers have a barometer inbuilt to measure the height based on the air pressure, but these barometers don't usually work as intended indoors. The problem with using ultrasonic sensors made for drones is that they are really expensive. The team over at NXP fixed this problem by adding a JST connecter that supports connection to the HC-SR04 and the HC-SR05 module. They also coded a driver for the HC-SR05 that also happens to work with the HC-SR04. To my knowledge, this is the only PX4 supported FMU that can use the cheaper modules to calculate the altitude. Thanks, NXP!
Step1: Flash the FMUK-66 with the latest release of the PX4 firmware. This does not necessarily need to be the beta release. You can use a stable version also.
Step2: Connect a 4 pin JST-GH to female jumper cable to the pin labeled "USONIC". The leftmost connection will be the +5v pin. Connect it to the VCC of the HC-SR04. The next connection will be the Trigger pin. Connect this to the Trigger pin of the sensor. The next connection will be the Echo pin. Connect this to the Echo pin of the sensor. The final pin will be ground. Connect it to the GND pin of the sensor.
Step3: After connecting the ultrasonic sensor to the FMU, use a USB cable to connect the FMU to the computer, and open the QGroundControl software. Here we are going to go to the parameters tab and search for "SENS_EN_SR". Change the parameter's value from 0 to 1, and reboot the vehicle. Now the ultrasonic sensor is being used for computing the altitude.
Step4: To test it out, go to the mavlink inspector, and select the distance sensor. You should be able to see the value in the current distance. Put an object in front of the sensor, and you should be able to see the distance from the sensor to the object.
Comments