micro-ROS / micro_ros_mbed

micro-ROS mbed sample code
Apache License 2.0
18 stars 7 forks source link

Build fails #16

Closed amilcarlucas closed 2 years ago

amilcarlucas commented 2 years ago

Issue template

Steps to reproduce the issue

On a Clean Ubuntu 20.04 LTS:

sudo apt install python3-pip
sudo apt install ninja-build
sudo apt install arm-none-eabi-g++
git clone https://github.com/Kitware/CMake/; cd CMake
git checkout v3.19.8
./bootstrap && make && sudo make install
cd ..
cd micro_ros_mbed
pip3 install catkin_pkg lark-parser empy colcon-common-extensions
pip3 install prettytable future jinja2 intelhex
pip3 install mbed-tools
mbed-tools deploy
mbed-tools compile -m PORTENTA_H7_M7 -t GCC_ARM -f

Expected behavior

Compiles with no errors

Actual behavior

# mbed-tools -v compile -m PORTENTA_H7_M7 -t GCC_ARM -f   
Configuring project and generating build system...
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/arm-none-eabi-gcc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/arm-none-eabi-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/arm-none-eabi-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter 
-- Checking for Python package prettytable -- found
-- Checking for Python package future -- found
-- Checking for Python package jinja2 -- found
-- Checking for Python package intelhex -- found
micro_ros_mbed
-- Configuring done
-- Generating done
-- Build files have been written to: /micro_ros_mbed/cmake_build/PORTENTA_H7_M7/develop/GCC_ARM
Building Mbed project...
[7/291] Performing build step for 'libmicroros_project'
make: Nothing to be done for 'all'.
[18/291] Building C object CMakeFiles/micro_ros_mbed.dir/mbed-os/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_kernel.c.obj
../../../../mbed-os/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_kernel.c: In function 'svcRtxKernelInitialize':
../../../../mbed-os/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_kernel.c:93:3: warning: 'memset' offset [17, 164] from the object at 'osRtxInfo' is out of the bounds of referenced subobject 'kernel' with type 'struct <anonymous>' at offset 8 [-Warray-bounds]
   93 |   memset(&osRtxInfo.kernel, 0, sizeof(osRtxInfo) - offsetof(osRtxInfo_t, kernel));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[31/291] Building CXX object CMakeFiles/micro_ros_mbed.dir/main.cpp.obj
FAILED: CMakeFiles/micro_ros_mbed.dir/main.cpp.obj
/usr/bin/arm-none-eabi-g++ @CMakeFiles/micro_ros_mbed.dir/main.cpp.obj.rsp -MD -MT CMakeFiles/micro_ros_mbed.dir/main.cpp.obj -MF CMakeFiles/micro_ros_mbed.dir/main.cpp.obj.d -o CMakeFiles/micro_ros_mbed.dir/main.cpp.obj -c ../../../../main.cpp
../../../../main.cpp:3:10: fatal error: rcl/rcl.h: No such file or directory
    3 | #include <rcl/rcl.h>
      |          ^~~~~~~~~~~
compilation terminated.
[40/291] Building CXX object CMakeFiles/micro_ros_mbed.dir/mbed-os/drivers/source/BufferedSerial.cpp.obj
ninja: build stopped: subcommand failed.
ERROR: CMake invocation failed!
pablogs9 commented 2 years ago

I have replicated your use case with correct results, at the end I have the binary: https://asciinema.org/a/ECQ3Is1P9SvgiuWLaZNmX5ViO

Maybe the only difference is this part:

cd micro_ros_mbed
echo https://github.com/ARMmbed/mbed-os/\#mbed-os-6.10.0 > mbed-os.lib
mbed-tools deploy
mbed-tools compile -m DISCO_L475VG_IOT01A -t GCC_ARM

But I guess that this is part of mbed installation process. Let us know if it works and we can update the README.md

amilcarlucas commented 2 years ago

I did the changes you suggested but I get:

CMake Warning (dev) at /opt/ros/galactic/share/rosidl_typesupport_cpp/cmake/rosidl_typesupport_cpp_generate_interfaces.cmake:84 (add_library):
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.
Call Stack (most recent call first):
  /micro_ros_mbed/micro_ros_dev/install/ament_cmake_core/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
  /micro_ros_mbed/micro_ros_src/install/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)
  CMakeLists.txt:16 (rosidl_generate_interfaces)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at /usr/local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
  Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
  (Required is at least version "3.5")
Call Stack (most recent call first):
  /usr/local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-3.19/Modules/FindPythonLibs.cmake:310 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  /opt/ros/galactic/share/python_cmake_module/cmake/Modules/FindPythonExtra.cmake:133 (find_package)
  /opt/ros/galactic/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:23 (find_package)
  /micro_ros_mbed/micro_ros_dev/install/ament_cmake_core/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
  /micro_ros_mbed/micro_ros_src/install/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)
  CMakeLists.txt:16 (rosidl_generate_interfaces)

I do have python3 and python3-dev installed (3.8)

pablogs9 commented 2 years ago

Make sure that your ROS 2 is not sourced. Also, make sure that you are not sourcing your ROS 2 installation in your .bashrc.

amilcarlucas commented 2 years ago

Un-sourcing ROS2 did the trick:

unset ROS_VERSION
unset ROS_PYTHON_VERSION
unset AMENT_PREFIX_PATH
unset PYTHONPATH
unset LD_LIBRARY_PATH
unset ROS_LOCALHOST_ONLY
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
unset ROS_DISTRO

Thanks for the tip.

Can I ignore this error in the end:

[291/291] Linking CXX executable micro_ros_mbed.elf
-- built: /micro_ros_mbed/cmake_build/PORTENTA_H7_M7/develop/GCC_ARM/micro_ros_mbed.bin
-- built: /micro_ros_mbed/cmake_build/PORTENTA_H7_M7/develop/GCC_ARM/micro_ros_mbed.hex
| Module             |         .text |       .data |          .bss |
|--------------------|---------------|-------------|---------------|
| [fill]             |     124(+124) |       7(+7) |       47(+47) |
| [lib]/c.a          |   9880(+9880) | 2116(+2116) |       60(+60) |
| [lib]/gcc.a        |     920(+920) |       0(+0) |         0(+0) |
| [lib]/microros.a   | 44316(+44316) |   160(+160) |   9803(+9803) |
| [lib]/misc         |     248(+248) |       4(+4) |       28(+28) |
| main.cpp.obj       |     396(+396) |       0(+0) |         8(+8) |
| mbed-os/cmsis      |   6998(+6998) |   168(+168) | 22112(+22112) |
| mbed-os/drivers    |   1696(+1696) |       0(+0) |         0(+0) |
| mbed-os/hal        |   1636(+1636) |       8(+8) |     114(+114) |
| mbed-os/platform   |   6302(+6302) |   276(+276) |     464(+464) |
| mbed-os/rtos       |     226(+226) |       0(+0) |         0(+0) |
| mbed-os/targets    | 19408(+19408) |     13(+13) |   1564(+1564) |
| transports.cpp.obj |     462(+462) |       0(+0) |   2208(+2208) |
| Subtotals          | 92612(+92612) | 2752(+2752) | 36408(+36408) |
Total Static RAM memory (data + bss): 39160(+39160) bytes
Total Flash memory (text + data): 95364(+95364) bytes

ERROR: No Mbed enabled devices found.
pablogs9 commented 2 years ago

Well, I guess that ERROR: No Mbed enabled devices found. means that it is not able to flash any device because the device is not recognized or the device is not connected.

amilcarlucas commented 2 years ago

Thanks. This can be closed now

amilcarlucas commented 2 years ago

Two small questions:

pablogs9 commented 2 years ago

Two small questions:

  • is CMake 3.19 really required? It is not available in any stable Ubuntu release.

If I remember well it is a mbed requirement, I should check. But micro-ROS do not need CMake 3.19. Let us know if you give a try.

  • is there a technical reason why Ethernet transport is not supported on the PORTENTA_H7_M7 target? I would like to implement it, but if there is a technical reason why it will not work, then I would like to not waist my time.

No, there is not. We just implement serial transport for simplicity. You can implement networking transport using the mbed networking API. Here you have some info about micro-ROS external transports: https://micro.ros.org/docs/tutorials/advanced/create_custom_transports/ . In this case, you just need to implement a UDP transport in the client side because agent already supports UDP.

It would be super nice if you can contribute this work to this repo so other users can use mbed with micro-ROS network transports. Do not hesitate to open a new issue if you have any problem developing it.

pablogs9 commented 2 years ago

BTW with network transport, you will need to disable the framing interface when setting the transport callbacks.

edit: more info here https://micro-xrce-dds.docs.eprosima.com/en/latest/transport.html