diff --git a/ov_core/src/utils/print.cpp b/ov_core/src/utils/print.cpp index 49ab68493..36195e92d 100644 --- a/ov_core/src/utils/print.cpp +++ b/ov_core/src/utils/print.cpp @@ -20,6 +20,13 @@ */ #include "print.h" +#include +#include + +#ifdef __ANDROID__ +#include +#define LOG_TAG "OpenVINS" +#endif using namespace ov_core; @@ -83,6 +90,52 @@ void Printer::debugPrint(PrintLevel level, const char location[], const char lin return; } +#ifdef __ANDROID__ + // Use Android logging on Android + android_LogPriority log_priority; + switch (level) { + case PrintLevel::ALL: + case PrintLevel::DEBUG: + log_priority = ANDROID_LOG_DEBUG; + break; + case PrintLevel::INFO: + log_priority = ANDROID_LOG_INFO; + break; + case PrintLevel::WARNING: + log_priority = ANDROID_LOG_WARN; + break; + case PrintLevel::ERROR: + log_priority = ANDROID_LOG_ERROR; + break; + default: + log_priority = ANDROID_LOG_INFO; + break; + } + + // Build the message with location info if DEBUG level + char location_str[256] = {0}; + if (static_cast(Printer::current_print_level) <= static_cast(Printer::PrintLevel::DEBUG)) { + std::string path(location); + std::string base_filename = path.substr(path.find_last_of("/\\") + 1); + if (base_filename.size() > MAX_FILE_PATH_LEGTH) { + snprintf(location_str, sizeof(location_str), "%s:%s ", + base_filename.substr(base_filename.size() - MAX_FILE_PATH_LEGTH, base_filename.size()).c_str(), line); + } else { + snprintf(location_str, sizeof(location_str), "%s:%s ", base_filename.c_str(), line); + } + } + + // Format the message + va_list args; + va_start(args, format); + char formatted_msg[1024]; + vsnprintf(formatted_msg, sizeof(formatted_msg), format, args); + va_end(args); + + // Log to Android logcat + __android_log_print(log_priority, LOG_TAG, "%s%s", location_str, formatted_msg); +#else + // Use standard printf on non-Android platforms // Print the location info first for our debug output // Truncate the filename to the max size for the filepath if (static_cast(Printer::current_print_level) <= static_cast(Printer::PrintLevel::DEBUG)) { @@ -101,4 +154,14 @@ void Printer::debugPrint(PrintLevel level, const char location[], const char lin va_start(args, format); vprintf(format, args); va_end(args); +#endif +} + +#ifndef __ANDROID__ +// Implementation of custom assert function (only for non-Android platforms) +extern "C" void __assert(const char *msg, const char *file, int line) { + fprintf(stderr, "Assertion failed: %s\n", msg); + fprintf(stderr, " at %s:%d\n", file, line); + std::abort(); } +#endif diff --git a/ov_init/src/init/InertialInitializer.cpp b/ov_init/src/init/InertialInitializer.cpp index 5e08f08a0..5f9efeb53 100644 --- a/ov_init/src/init/InertialInitializer.cpp +++ b/ov_init/src/init/InertialInitializer.cpp @@ -21,7 +21,9 @@ #include "InertialInitializer.h" +#ifndef __ANDROID__ #include "dynamic/DynamicInitializer.h" +#endif #include "static/StaticInitializer.h" #include "feat/FeatureHelper.h" @@ -43,7 +45,11 @@ InertialInitializer::InertialInitializer(InertialInitializerOptions ¶ms_, st // Create initializers init_static = std::make_shared(params, _db, imu_data); +#ifndef __ANDROID__ init_dynamic = std::make_shared(params, _db, imu_data); +#else + init_dynamic = nullptr; +#endif } void InertialInitializer::feed_imu(const ov_core::ImuData &message, double oldest_time) { @@ -133,10 +139,16 @@ bool InertialInitializer::initialize(double ×tamp, Eigen::MatrixXd &covaria PRINT_DEBUG(GREEN "[init]: USING STATIC INITIALIZER METHOD!\n" RESET); return init_static->initialize(timestamp, covariance, order, t_imu, wait_for_jerk); } else if (params.init_dyn_use && !is_still) { +#ifndef __ANDROID__ PRINT_DEBUG(GREEN "[init]: USING DYNAMIC INITIALIZER METHOD!\n" RESET); std::map> _clones_IMU; std::unordered_map> _features_SLAM; - return init_dynamic->initialize(timestamp, covariance, order, t_imu, _clones_IMU, _features_SLAM); + if (init_dynamic) { + return init_dynamic->initialize(timestamp, covariance, order, t_imu, _clones_IMU, _features_SLAM); + } +#else + PRINT_ERROR(RED "[init]: DYNAMIC INITIALIZER not available on Android (Ceres Solver not included)\n" RESET); +#endif } else { std::string msg = (has_jerk) ? "" : "no accel jerk detected"; msg += (has_jerk || is_still) ? "" : ", ";