diff --git a/CMakeLists.txt b/CMakeLists.txt index 080cee6..21aaedd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,24 +17,38 @@ catkin_package( lpp ) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/lib/BMI08x-Sensor-API) + message(STATUS "BMI08x-Sensor-API found") + SET(MAV_IMU_BUILD_BOSCH ON) + include_directories(lib/BMI08x-Sensor-API) +else() + message(WARNING "BMI08x-Sensor-API not found. Bosch BMI088 will not be supported.") +endif() + include_directories( include - lib/BMI08x-Sensor-API ${catkin_INCLUDE_DIRS}) +if (MAV_IMU_BUILD_BOSCH) + set(MAV_IMU_BOSCH_SRC_FILE src/imu/bmi088.cpp) +endif () + add_library(${PROJECT_NAME} src/spi_driver.cpp src/imu_node.cpp src/imu/adis16448.cpp - src/imu/bmi088.cpp + ${MAV_IMU_BOSCH_SRC_FILE} src/imu/ImuFactory.cpp) +if (MAV_IMU_BUILD_BOSCH) + target_compile_definitions(${PROJECT_NAME} PUBLIC MAV_IMU_BUILD_BOSCH) # Bosch API add_library(${PROJECT_NAME}_BMI08x lib/BMI08x-Sensor-API/bmi08a.c lib/BMI08x-Sensor-API/bmi08g.c lib/BMI08x-Sensor-API/bmi08xa.c) target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_BMI08x) +endif() target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES}) diff --git a/src/imu/ImuFactory.cpp b/src/imu/ImuFactory.cpp index 90e1d00..a49cf92 100644 --- a/src/imu/ImuFactory.cpp +++ b/src/imu/ImuFactory.cpp @@ -4,7 +4,9 @@ #include #include +#ifdef MAV_IMU_BUILD_BOSCH #include +#endif #include #include @@ -24,7 +26,10 @@ ImuInterfacePtr ImuFactory::createImuByName(const std::string &imu_name, if (adis->init() && adis->setBurstCRCEnabled(true)) { return adis; } LOG(E, "Failed to initialize " << imu_name); return nullptr; - } else if (imu_name == "bmi088") { + } + + else if (imu_name == "bmi088") { +#ifdef MAV_IMU_BUILD_BOSCH // Select the second Chip Select for the gyro. // get the last letter of the string char last_letter = spi_path[spi_path.length() - 1]; @@ -45,6 +50,11 @@ ImuInterfacePtr ImuFactory::createImuByName(const std::string &imu_name, if (bmi->init()) { return bmi; } LOG(E, "Failed to initialize " << imu_name); return nullptr; + +#else + LOG(E, "Compiled without Bosch BMI088 support"); + return nullptr; +#endif } LOG(E, "Imu of type " << imu_name << " not supported");