Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made BMI08x-Sensor-API optional for build #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
12 changes: 11 additions & 1 deletion src/imu/ImuFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <imu/ImuFactory.h>
#include <imu/adis16448.h>
#ifdef MAV_IMU_BUILD_BOSCH
#include <imu/bmi088.h>
#endif
#include <log++.h>
#include <memory>

Expand All @@ -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];
Expand All @@ -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");
Expand Down