bluerobotics / ping-arduino

Arduino library to interact with the Ping sonar using the Ping Protocol messages.
6 stars 16 forks source link

hitting strange freeze up bugs #25

Open jerabaul29 opened 3 years ago

jerabaul29 commented 3 years ago

I am using this sensor on the Arduino Due together with a relatively complex logger. Without this sensor, everything works fine. Adding this sensor and trying to recover full profiles, I run in weird bugs.

I really cannot figure out what happens and why my program crashes. I wonder if there is a really nasty memory corruption happening at some point. That would explain why I have seemingly incomprehensible bugs.

Do you think / have you experienced / have you any idea of anything that could produce nasty memory bugs in this code? I have identified at least one source of such bugs (that is actually referenced in issue #21 ), and fixed it on my fork that I use now for running the sensor (see https://github.com/jerabaul29/ping-arduino/tree/fix/mem_alloc ).

Any other code that can be used to interface to this sensor? This does not seem to be maintained (for example, the bad malloc is really bad and has not been fixed in a long time).

patrickelectric commented 3 years ago

Hi @jerabaul29, sorry for that, we are working to replace this repository implementation with bluerobotics/ping-cpp , I would recomend to use it if you are facing so many problems with ping-arduino. Also, if you can, please share a minimal code to replicate your problem

jerabaul29 commented 3 years ago

This is the difficulty, I cannot easily come up with a minimal code. Possible I miss something and the error is another place, but if it is well a memory corruption due to this library, I think how it strikes depends on memory layout. I saw there is a bit of malloc and raw memory access, do you have any other library that is statically allocated for MCU use?

Thanks for pointing to the new library. If I understand well this is a general C++ library implementing your protocal, and that can be used for building devices libraries, right? Any way you could update the code on this repo based on the library there? Or provide a working Arduino / MCU example using your new library for this sonar? Static memory allocation would be most welcome :) .

@jvoermans would you be ok making the vibration logger repo public so that @patrickelectric can have a look and see if he can help? :)

jerabaul29 commented 3 years ago

Btw, many thanks for your fast answer @patrickelectric . I have been a great fan of your products for a long time (our lab bought a ROV a couple of years ago and we are very happy using it in the Arctic; see for example https://arxiv.org/pdf/2012.09545.pdf If you want to do some PR with this, let me know :) ), and now @jvoermans is using quite many of your sensors (sonar, temperature in particular) for a new instrument design. If you can help us getting things working with your sensors that would be amazing :) .

jvoermans commented 3 years ago

Hello @jerabaul29 @patrickelectric, I think I just made it public :)

animmosmith commented 3 years ago

I'm encountering a similar freeze-up with even just the ping1d-simple code running on an Adafruit Feather M0 (ATSAMD21G18 ARM Cortex M0 processor). Code adapted to make use of Serial1 compiles fine, but hangs at ping.initialize() when the sonar is connected correctly. When not connected or wired incorrectly, the code correctly identifies this (i.e. ping.initialize() correctly returns FALSE). I've tried with @jerabaul29 's fork also (many thanks for sharing that), but with no change in behaviour. Any further ideas?

animmosmith commented 3 years ago

To save others time... the "pingmessage.ino" example that uses the C++ API appears to work on the Feather M0 with some minor adjustments for using hardware Serial1. Thanks.