polyhobbyist / wiring_for_ros

This repository contains an implementation of Arduino APIs for CPUs like Jetson or Raspberry Pi for use with ROS2
MIT License
12 stars 2 forks source link

i2c/i2c.h is missing from Include folder #3

Open gipaq1950 opened 1 year ago

gipaq1950 commented 1 year ago

I got error i2c/i2c.h missing when I try to build the ICM 20948 ros node package on jetson nano with ros2 foxy . How to fix it? Thanks

polyhobbyist commented 1 year ago

I think you might be missing libi2c-dev from the host environment. Either that or the dependency hasn't been explicitly declared on the ROS Node.

Here's a repo with a dockerfile which shows how it can be consumed - https://github.com/polyhobbyist/jetbot

gipaq1950 commented 1 year ago

Thank you for quick replay.

I have libi2c-dev installed on Jetson. I added manually i2c.h on the include folder and now I get this error:

colcon build --packages-select ros_qwiic_icm_20948 Starting >>> ros_qwiic_icm_20948 --- stderr: ros_qwiic_icm_20948
make[3]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule.

Finished <<< ros_qwiic_icm_20948 [13.6s]

Summary: 1 package finished [14.6s] 1 package had stderr output: ros_qwiic_icm_20948

polyhobbyist commented 1 year ago

I'll take a look in a couple days - i'm not near my Jetson at the moment. I committed a fix to the icm_20948 which explicitly adds a dependency to libi2c. This should correct the original build error.

The warning manifests on the jetson - I haven't root caused it. However, you can work around it by using --cmake-args -j1 I believe. which forces the build to use a single thread.

gipaq1950 commented 1 year ago

Did you have a look on this issue? Your last suggestion did not solve it. Thanks.

polyhobbyist commented 1 year ago

Thanks for checking in - I'll look at it tonight.

polyhobbyist commented 1 year ago

Working on this now - can you tell me more about how you are using this library? Are you using it in a container or on bare metal?

gipaq1950 commented 1 year ago

I have Ubuntu 20.04 installed on Jetson nano and ros2 foxy.

polyhobbyist commented 1 year ago

Can you post the full build log? (either from the logs folder, or colcon build --event-handlers=console_direct+)

I'm unable to reproduce this.

the i2c/i2c.h comes from an external cmake project:

find_program(MAKE_EXECUTABLE
    NAMES gmake mingw32-make make
    NAMES_PER_DIR
    DOC "GNU Make")
if(NOT MSVC)
include(ExternalProject)
ExternalProject_Add(libi2c
    GIT_REPOSITORY https://github.com/amaork/libi2c.git
    UPDATE_DISCONNECTED true
    BUILD_IN_SOURCE true
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ${MAKE_EXECUTABLE}
    INSTALL_COMMAND ""
)
ExternalProject_Get_property(libi2c SOURCE_DIR)

message (STATUS "*** libi2c installed to ${SOURCE_DIR}")
target_link_libraries(${PROJECT_NAME} ${SOURCE_DIR}/libi2c.so)
add_dependencies(${PROJECT_NAME}  libi2c)
else()
endif()

I suspect that this isn't being included. Maybe because make isn't found? or the network is blocked?

gipaq1950 commented 1 year ago

Logs.zip

polyhobbyist commented 1 year ago

Thanks for the logs. It looks like a build order problem - wiring.cpp is getting built before libi2c is getting built.

un ros_qwiic_icm_20948 do you have the following line in the makefile?

add_dependencies(${PROJECT_NAME}  libi2c) 

which happens after these lines?

message (STATUS "*** libi2c installed to ${SOURCE_DIR}")
target_link_libraries(${PROJECT_NAME} ${SOURCE_DIR}/libi2c.so)
Scanning dependencies of target libi2c
Scanning dependencies of target ros_qwiic_icm_20948
[  6%] Creating directories for 'libi2c'
[ 13%] Performing download step (git clone) for 'libi2c'
[ 26%] Building CXX object CMakeFiles/ros_qwiic_icm_20948.dir/src/wiring_for_ros/Wire.cpp.o
[ 26%] Building CXX object CMakeFiles/ros_qwiic_icm_20948.dir/src/wiring_for_ros/SPI.cpp.o
[ 33%] Building CXX object CMakeFiles/ros_qwiic_icm_20948.dir/src/main.cpp.o
[ 40%] Building CXX object CMakeFiles/ros_qwiic_icm_20948.dir/src/wiring_for_ros/Arduino.cpp.o
Your branch is up to date with 'origin/master'.
[ 53%] Skipping update step for 'libi2c'
[ 53%] No patch step for 'libi2c'
[ 60%] No configure step for 'libi2c'
[ 66%] Performing build step for 'libi2c'
gipaq1950 commented 1 year ago

I added add_dependencies(${PROJECT_NAME} libi2c) to cmakelist.txt file and now I don't have error i2c/i2c.h but now I get error:

jetson@nano:~/dev_ws$ colcon build --packages-select ros_qwiic_icm_20948 [1.369s] WARNING:colcon.colcon_ros.prefix_path.ament:The path '/home/jetson/dev_ws/install/ros_qwiic_icm_20948' in the environment variable AMENT_PREFIX_PATH doesn't exist [1.371s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/jetson/dev_ws/install/ros_qwiic_icm_20948' in the environment variable CMAKE_PREFIX_PATH doesn't exist Starting >>> ros_qwiic_icm_20948 --- stderr: ros_qwiic_icm_20948
Cloning into 'libi2c'... Already on 'master' make[3]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule. make[3]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule.

Finished <<< ros_qwiic_icm_20948 [25.4s]

Summary: 1 package finished [26.7s] 1 package had stderr output: ros_qwiic_icm_20948

gipaq1950 commented 1 year ago

jetson@nano:~/dev_ws$ colcon build --packages-select ros_qwiic_icm_20948 Starting >>> ros_qwiic_icm_20948 --- stderr: ros_qwiic_icm_20948
make[3]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule.

Finished <<< ros_qwiic_icm_20948 [2.80s]

Summary: 1 package finished [3.77s] 1 package had stderr output: ros_qwiic_icm_20948

gipaq1950 commented 1 year ago

jetson@nano:~/dev_ws$ ros2 launch ros_qwiic_icm_20948 qwiic.launch.py [INFO] [launch]: All log files can be found below /home/jetson/.ros/log/2023-05-01-03-04-54-778640-nano-19167 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [ros_qwiic_icm_20948-1]: process started with pid [19169] [ros_qwiic_icm_20948-1] /home/jetson/dev_ws/install/ros_qwiic_icm_20948/lib/ros_qwiic_icm_20948/ros_qwiic_icm_20948: symbol lookup error: /home/jetson/dev_ws/install/ros_qwiic_icm_20948/lib/ros_qwiic_icm_20948/ros_qwiic_icm_20948: undefined symbol: i2c_init_device [ERROR] [ros_qwiic_icm_20948-1]: process has died [pid 19169, exit code 127, cmd '/home/jetson/dev_ws/install/ros_qwiic_icm_20948/lib/ros_qwiic_icm_20948/ros_qwiic_icm_20948 --ros-args -r __node:=ros_qwiic_icm_20948'].

polyhobbyist commented 1 year ago

hmmm... it looks like the --package-select causes the issue. Not quite sure why.