Send Arduino ESP32 command directly to a cpp library

Hi,
The AS5048A Angle sensor has its libraries included in my Arduino ESP32 program.
I found out that the AS5048A.cpp lib file has a delay function which I wish to be able to control from my program, (void AS5048A::setDelay()) but that command is not available in the AS5048A.h file, thus I need to directly modify the common cpp file or to modify the .h file which I refrain from doing (bad practice).
How can I run the cpp setDelay() function (or any other function / command) directly from my Arduino ESP32 code without modifying the libraries?

I'm only guessing which library it is you are referring to, since you didn't see fit to include a link to it in your message. But if I have found the correct one, why would you need to call a private method (and you might think about the word "private" and ponder) that is already called from the class' begin method?

Hi van der decken,
The library in question is AS5048A/src/AS5048A.cpp at master · eborghi10/AS5048A · GitHub
I found out that for unknown reason (to me) it has a built-in 50mSec delay for ESP32.
When it comes to 2 sensors, it becomes a 100 mSec delay.
I need to PID control a BLDC motor and can not tolerate that delay in my control loop.
I tested the program by removing the delay directly in the cpp file (for testing) and did not find any problem, but changing a library is wrong practice, so I thought I could directly command the lib to modify the delay (or cancel it).

That's news to me.

There's nothing magical or sacred about code in a library. It's just code. Use it as you see fit.

Make a local copy of the library. Call it, I don't know, "MY_AS5048A". Make whatever modifications you like. Use that library.

Or don't use a library at all. Copy the class' .cpp and .h files into your project. Make whatever modifications you like. Use your local class.

Or make a derived class. Override the methods in the original library you don't like. Use your derived class.

You aren't bound by any restraints to use code exactly as it exists. None that exist outside of your own mind, that is.

1 Like

I looked up the datasheet of the AS5048A Sensor

This sensor has a PWM-output a I2C and SPI-interface.
So which interface does the library use?

What will be the max rpm of your BLDC-motor?
How long does it take to read out the angle from the sensor?

Since that library was specifically created to add the esp32 to an existing avr library with no delay, I would be asking myself why the author thought they needed to do that.

Thanks, I certainly understand I can make my own libraries or eliminate the libs by including the code in my code (main file or added one), so what's the whole idea with libs?
(Occasionally, I do eliminate libs if the lib is an overkill to my humble need and can be replaced with a few lines in the main).
I still think modifying an Arduino public library is wrong practice. It means actually that a program cannot be distributed or shared by others without attaching the libs. Furthermore, unexperienced or beginners programmers are not expected to deal with modified libs. It is a major source of errors.

The only limitations you face are the ones you impose upon yourself. Good-bye.

To cattledog:
Yes, I wonder myself why would the author add that delay. I therefore modified the cpp file and totally removed the delay and thouroughly tested my program and did not find any problem so far.
I wish the writer (eborghi10, Emiliano Borghi) will tell us the reason as there is nothing in the code to justify it.

Our profesional and social life are built on top of endless limitations we willingly impose upon ourselves.

And one more thing: As stefanL38 noted, the AS5048A Sensor is a 14 bit angle sensor. With 50mSec delay for each measurement it can hardly measure any rotating object.
Adding the delay totally killed the sensors performance.
As I did not need the 14 bits resolution, I reduced it to 10 bits (by >> 4) but still, with 50mSec (100mSec for the two I use) it is impossible to implement any reasonable PID control at 1 RPM even with 10 bits.

Sorry, I mean 1 rev per second which I use.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.