micro_ros_espidf_component icon indicating copy to clipboard operation
micro_ros_espidf_component copied to clipboard

How to use micro_ros_espidf_component as a component in my project?

Open jbmouret opened this issue 3 years ago • 7 comments
trafficstars

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

  • Hardware description: M5Core2
  • Version or commit hash: humble
  • ESP-IDF: 4.4 (from the docker) -- docker run -it --rm -v $PWD:/project -v /dev:/dev --volume="/etc/timezone:/etc/timezone:ro" --privileged --workdir /project espressif/idf:release-v4.4

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!

jbmouret avatar Sep 26 '22 13:09 jbmouret

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

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

pablogs9 avatar Sep 26 '22 13:09 pablogs9

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>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jbmouret avatar Sep 26 '22 14:09 jbmouret

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

pablogs9 avatar Sep 27 '22 12:09 pablogs9

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:

  • docker run -it --rm -v $PWD:/project -v /dev:/dev --volume="/etc/timezone:/etc/timezone:ro" --privileged --workdir /project espressif/idf:release-v4.4
  • pip3 install catkin_pkg lark-parser empy colcon-common-extensions
  • git clone https://github.com/hucebot/ros_m5core.git
  • cd ros_m5core
  • git submodule update --init --recursive --progress (the arduino-esp32 component takes a while! sorry)
  • set CONFIG_FREERTOS_HZ=1000 (instead of 100) in sdkconfig (for arduino)
  • idf.py menuconfig
  • idf.py build -> fails

jbmouret avatar Sep 28 '22 13:09 jbmouret

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?

pablogs9 avatar Sep 28 '22 15:09 pablogs9

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

jbmouret avatar Sep 29 '22 13:09 jbmouret

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

gentijo avatar Oct 16 '22 17:10 gentijo

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.

ManvithRaj avatar Nov 02 '22 10:11 ManvithRaj

@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 avatar Nov 02 '22 10:11 pablogs9

@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

ManvithRaj avatar Nov 11 '22 12:11 ManvithRaj

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

gentijo avatar Dec 04 '22 18:12 gentijo

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).

jbmouret avatar May 25 '23 07:05 jbmouret