So, you have questions about using a SONAR sensor

10 views
Skip to first unread message

Michael Wimble

unread,
Sep 21, 2025, 9:00:54 PM (10 days ago) Sep 21
to hbrob...@googlegroups.com
Using a SONAR sensor driven by code running on Linux is prone to a lot of problems. Importantly, the time-slicing nature of scheduling in Linux makes it hard to get predictability and accuracy in generating useful messages for use by the Nav2 system in ROS 2. If you don’t also use timers and interrupt handlers, there’s a whole other level of problem with accuracy and repeatability you have to deal with.

I have some code that deals with most of the problems, but it does so by managing sensors on a system which can provide most of the characteristics of a hard-realtime system. Importantly, you can get predictable, repeatable sensing with low jitter, high reporting frame rates, and can easily add in a safety system. But I’m not going to show you how to do all of that. At some point, I will show you, but providing a non-toy level of dealing with sensors in ROS 2 is a long conversation.

But, I can show you a lot of code that you can use to write your own Arduino-based sensor processing for SONAR sensors.

I’ve enclosed a PDF file I wrote (with a bit of help from an AI system so I don’t have to type every word, so any errors are definitely the AI’s, not mine). I’ve also included a bit of technical information that is pretty much never discussed.

So, enjoy the enclosed.

sonar.cpp
sonar.h
sonar1.cpp
HC_SR04_With_Ros2_Example.pdf
Reply all
Reply to author
Forward
0 new messages