micro-ROS / micro_ros_espidf_component

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

How to use micro_ros_espidf_component as a component in my project? #161

Closed jbmouret closed 1 year ago

jbmouret commented 2 years ago

Hello

Thank you for your efforts with micro-ROS. This is a very promising project!

I am trying to get my M5Core2 working with micro-ros + the standard (Arduino-based) M5Core2 library (to access the screen, sensors, etc.).

PROBLEM: I can compile the micro-ROS examples but I do not find how to use micro-ros as a component in my project.

Details

Steps to reproduce the issue

I created a project based on the esp-idf template. Here is the directory structure:

|-- CMakeLists.txt
|-- Makefile
|-- README.md
|-- build
|  ...
|-- components
|   |-- M5Core2
|   |-- arduino-esp32
|   `-- micro_ros_espidf_component
|-- dependencies.lock
|-- main
|   |-- CMakeLists.txt
|   |-- component.mk
|   |-- main.cpp
| - sdkconfig

In a few words, I added micro_ros_espidf_component in the component folder of my project.

When I do a menuconfig, I can configure the middleware and the WIFI credentials (but nothing more)[I selected embeddedRTPS].

In the root CmakeLists.txt, I have:

cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(main)

And for the CMakeLists.txt in the main directory:

idf_component_register(SRCS "main.cpp"
                    INCLUDE_DIRS "."
                    REQUIRES micro_ros_espidf_component M5Core2 arduino-esp32)

My main.cpp is a copy of examples/int32_publisher_embeddedrtps/main/main.cpp.

Expected behavior

I expect this to compile when I do idf.py build

Actual behavior

Defines are not found:

/project/eurobin_iot/main/main.cpp: In function 'void setup()':
/project/eurobin_iot/main/main.cpp:132:17: error: 'CONFIG_MICRO_ROS_APP_STACK' was not declared in this scope
                 CONFIG_MICRO_ROS_APP_STACK,
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
/project/eurobin_iot/main/main.cpp:132:17: note: suggested alternative: 'CONFIG_MICRO_ROS_ESP_NETIF_WLAN'
                 CONFIG_MICRO_ROS_APP_STACK,
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
                 CONFIG_MICRO_ROS_ESP_NETIF_WLAN
/project/eurobin_iot/main/main.cpp:134:17: error: 'CONFIG_MICRO_ROS_APP_TASK_PRIO' was not declared in this scope
                 CONFIG_MICRO_ROS_APP_TASK_PRIO,
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/project/eurobin_iot/main/main.cpp:134:17: note: suggested alternative: 'CONFIG_MB_SERIAL_TASK_PRIO'
                 CONFIG_MICRO_ROS_APP_TASK_PRIO,
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                 CONFIG_MB_SERIAL_TASK_PRIO

I guess I am doing something wrong with idf.py or micro-ros because these defines should be defined during the make.

Thanks!

pablogs9 commented 2 years ago

Hello @jbmouret, if you choose XRCE-DDS as middleware, can you compile?

If yes, I will check the menuconfig for Embedded RTPS.

jbmouret commented 2 years ago

Thank you for your answer.

If I use the XRCE-DDS (and use the int32_publisher example), I get another compilation error (with the embeddedRTPS middleware, no issue with the includes):

/project/eurobin_iot/main/main.cpp:18:10: fatal error: rmw_microros/rmw_microros.h: No such file or directory
 #include <rmw_microros/rmw_microros.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pablogs9 commented 2 years ago

Clean the whole environment before rebuilding, this error is related to the files generated in the micro-ROS module.

jbmouret commented 2 years ago

Thank you. I cleaned and switched to XRCE-DDS. I now get the same compilation error as before (undefined CONFIG_MICRO_ROS_APP_STACK etc.).

If you have time to test / look at, I've put everything online here: https://github.com/hucebot/ros_m5core

I've put the Arduino and m5stack components in the repository but I don't think this is causing the issue.

I used the expressif docker:

pablogs9 commented 2 years ago

One more thing before taking a look (we are quite busy this weeks). If you define #define CONFIG_MICRO_ROS_APP_STACK 4000 in your main.c does this compiles and work?

jbmouret commented 2 years ago

Yes, it does work if I define the 2 constants manually.

gentijo commented 2 years ago

To add more context, I am also having an issue using the esp idf component architecture, I was able to work around this issue by manually including my module cpp files in my CMakeLists.txt. See current main branch of my code.

Here is a thread I started on Answeres, https://answers.ros.org/question/405631/esp32-microros-component-linker-error/

here is a branch that illustrates the problem. https://github.com/gentijo/MaqueenBattleBots/tree/component-link-fail

ManvithRaj commented 1 year ago

Hello @pablogs9 and others to add to this i am also facing the similar issue .

I have cloned micro_ros_idf_component into esp-idf components folder and tried building example int32_publisher with RTPS Enabled. i installed dependencies also as said with below commands mentioned . $IDF_PATH/export.sh pip3 install catkin_pkg lark-parser empy colcon-common-extensions

After that i have given command esp-idf set-target esp32 which is trying to build micro_ros_idf_component and generated two extra folders in it ie. 1. micro_ros_src 2. micro_ros_dev somehow the build process not generating all the required files. I could see below messages with error.

error

i could see only 3 folders in install directory of micro ros component

error2

After above step if i proceed with esp-idf set-target esp32 and esp-idf menuconfig still i could able to do these configurations.

But during idf.py build i am getting issues in following order

rcl/rcl.h include issue ---->Found this file in esp_idf_microros_component install/include folder I have added this path manually in cmakelist.txt of esp_idf_microros_component rmw/init.h include issue ---> found this file also. Added this also Similarly like this many .h file issues came I have added those path manually in cmakelist.txt

Finally . msgs/int32.h issue -----> this file was not found as the build generation for component not happened as I said early.

Could you please help us on what might be missing since i am new to this i might be not aware much about micro-ROS and why we are unable to build like video you shared at link https://asciinema.org/a/G39IxQZkzipXSxrnbqepXh6iF.

pablogs9 commented 1 year ago

@ManvithRaj sorry but we do not have the bandwidth for taking a look at that. If you find a solution please open a PR.

ManvithRaj commented 1 year ago

@ManvithRaj sorry but we do not have the bandwidth for taking a look at that. If you find a solution please open a PR.

@pablogs9 i am able to fix this issue and build is successful. the problem is here freeRTOS Components path are not properly configured in one of the cmake.in files.

I did that and also I did clean installation of ESP-IDF which has solved the issue. Now the issue is during testing subscriber not receiving data in this RTPS Mode i have raised a new issue here... [https://github.com/micro-ROS/micro_ros_espidf_component/issues/164] could you please help in this i think it wont take much time of you just have a look. since you are owner of this source code it might be easy for you to detect missing things

gentijo commented 1 year ago

Working on a different problem trying to move directories around, I found this https://answers.ros.org/question/409614/help-with-micro-ros-cmakefiles-and-directory-configuration/?answer=410141#post-id-410141

I think the fact that the ROS Build system is using the CMakeLists.txt file found as a sibling as the EXTRA_COMPONENT_DIR to compile the ROS code, it may not be processing the extra components correctly.

This is just a guess. -John

jbmouret commented 1 year ago

Using

#define CONFIG_MICRO_ROS_APP_STACK 4000
#define CONFIG_MICRO_ROS_APP_TASK_PRIO 5

in my code works. This is still a hack, but this is OK.

For the errors from the others, usually this comes from running a first make without having colcon etc. installed. This "breaks" future builds. Do not forget to do a idf.py clean-microros + idf.py fullclean (+ potentially remove the build folder).