Home        Store        Learn        Blog

Ping C++ api basic example and cmake

So I am working on a capstone team that is trying to use the Ping Echosounder for obstacle detection. Our goal is to integrate it into an existing UAV that is running a custom version of MOOS-IvP running on a Beaglebone Black, but initially we just want to write a program that will turn an LED on if it detects an object within a set distance. Since MOOS-IvP uses C++ we have been looking at the “deployment branch” from the ping-cpp github. Unfortunately, our team doesn’t have that much experience in this and although we have used “make” files, we haven’t used cmake before, but we are somewhat familiar with C++.

We have cloned the bluerobotics/ping-cpp repository and switched to the deployment branch. Within this branch there is the src folder, which contains the device folder and message folder. Each of these folders have their own CMakeLists.txt files and I am unsure if I need to build each of these separately or if I need to somehow build them together. We have looked over the Underwater Sonar and Altimeter with Arduino guide since it has more documentation, and would like to create a program similar to “ping1d-simple.ino” but for our Beaglebone Black.

So would I write a similar program to “ping1d-simple.ino” and possibly call it “main.cpp” that relies on the “device” and “message” src? If so how should I go about using cmake since there are two CMakeLists.txt files?

Hi Noah, welcome to the forum! :slight_smile:

The separate CMakeLists.txt files allow you to use those as libraries within your own application. I’d suggest you go through the CMake tutorial to get a better understanding of how CMake works and what you can do with it. Adding libraries is covered in Step 2, which should also help you to structure your project appropriately.

If you run into any issues feel free to ask follow-up questions on the specifics of what you’ve tried and what isn’t working, and we can try to help. If you get your build-process set up and working and feel like there’s a way we could better document the library usage, it’d be great if you could outline what you’d like to see/what would be helpful for someone to get started more easily in future :slight_smile:

Hi @hoan125,

We have just updated documentation the repository README:

Let us know if you need any help, the test-device and test-device-ping1d should be a good example of how to communicate with the sensor using a computer.

1 Like

I think part of @hoan125 initial confusion is that there are cmake files in the deployment branch, but they are only useful in the master branch


It’s also possible to use the cmake files in the deployment branch, sadly the library cmake (in the root folder) was not merged yet but the cmake files both ping-device and ping-messages can be used if desired.