micro-ROS / micro_ros_espidf_component

micro-ROS ESP32 IDF component and sample code
Apache License 2.0
247 stars 58 forks source link

Adding custom library of sensors with micro-ROS freertos #172

Closed CasCard closed 1 year ago

CasCard commented 1 year ago

Issue template

I am having Adafruit VL6180X ToF sensor, but it uses a custom library with Adafruit headers. I would like to know how can I include this library when creating the FreeRTOS micro-ros application. My application is to publish the sensor data from ESP32 using micro-ros , which can be subscribed by raspberry pi with ROS2 running. Screenshot from 2023-01-03 23-59-32 This file structure format.

pablogs9 commented 1 year ago

Hello @CasCard, the folder structure you show is not generated by micro_ros_espidf_component. Could you please use micro_ros_espidf_component, so the integration of your library will be as usual in ESP-IDF.

CasCard commented 1 year ago

I was finally able to solve this issue. If someone looking to integrate Arduino libraries into your project here are the steps to follow.

Screenshot from 2023-01-23 18-52-08

If you want to specifically follow the format usually followed for Arduino includes setup and loop format you have to include a library called arduino-esp32 in the components folder as shown in the above image.

Now if you want to include Arduino libraries you can directly clone them into the components folder. Here is an example where I am including the Adafruilt VL6180X library.

Screenshot from 2023-01-23 18-59-55

Now you have to additionally add CMakeLists.txt in the library so that IDF will be able to find them while building.You can keep the header files in the include folder. You might need to add additional supporting libraries for your core libraries. For example Adafruilt VL6180X requires arduino-esp32 and Adafruit_BusIO libraries.

So the CMakeLists.txt of Adafruilt VL6180X library should look like as follows:

idf_component_register(SRCS "Adafruit_VL6180X.cpp" INCLUDE_DIRS "include" REQUIRES arduino Adafruit_BusIO)

Now for writing arduino ide like code you can follow this reference.

Note that if you want to use setup and loop your file should be in .cpp format and changes need to be made in the CMakeLists.txt file as well. In the case of ESP-IDF app format, it should be a .c file. Hope this helps.