Skip to content
Merged
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
63 changes: 63 additions & 0 deletions ov_core/src/utils/print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
*/

#include "print.h"
#include <cstdio>
#include <cstdlib>

#ifdef __ANDROID__
#include <android/log.h>
#define LOG_TAG "OpenVINS"
#endif

using namespace ov_core;

Expand Down Expand Up @@ -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<int>(Printer::current_print_level) <= static_cast<int>(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<int>(Printer::current_print_level) <= static_cast<int>(Printer::PrintLevel::DEBUG)) {
Expand All @@ -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
14 changes: 13 additions & 1 deletion ov_init/src/init/InertialInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

#include "InertialInitializer.h"

#ifndef __ANDROID__
#include "dynamic/DynamicInitializer.h"
#endif
#include "static/StaticInitializer.h"

#include "feat/FeatureHelper.h"
Expand All @@ -43,7 +45,11 @@ InertialInitializer::InertialInitializer(InertialInitializerOptions &params_, st

// Create initializers
init_static = std::make_shared<StaticInitializer>(params, _db, imu_data);
#ifndef __ANDROID__
init_dynamic = std::make_shared<DynamicInitializer>(params, _db, imu_data);
#else
init_dynamic = nullptr;
#endif
}

void InertialInitializer::feed_imu(const ov_core::ImuData &message, double oldest_time) {
Expand Down Expand Up @@ -133,10 +139,16 @@ bool InertialInitializer::initialize(double &timestamp, 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<double, std::shared_ptr<ov_type::PoseJPL>> _clones_IMU;
std::unordered_map<size_t, std::shared_ptr<ov_type::Landmark>> _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) ? "" : ", ";
Expand Down