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

[draft] switch wpical backend to gtsam #7606

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ if(WITH_DOCS)
endif()

if(WITH_WPICAL)
find_package(Ceres CONFIG REQUIRED)
# find_package(Ceres CONFIG REQUIRED)
find_package (SuiteSparse 5.12 NO_MODULE)
endif()

find_package(LIBSSH CONFIG 0.7.1)
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ wpilibVersioning.releaseMode = project.hasProperty('releaseMode')
allprojects {
repositories {
maven {
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
}
if (project.hasProperty('releaseMode')) {
wpilibRepositories.addAllReleaseRepositories(it)
Expand Down
13 changes: 13 additions & 0 deletions shared/gtsam.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
nativeUtils {
nativeDependencyContainer {
gtsam(getNativeDependencyTypeClass('WPIStaticMavenDependency')) {
groupId = "edu.wpi.first.thirdparty.frc2025.gtsam"
artifactId = "gtsam-cpp"
headerClassifier = "headers"
sourceClassifier = "sources"
ext = "zip"
version = '4.3-2'
targetPlatforms.addAll(nativeUtils.wpi.platforms.desktopPlatforms)
}
}
}
3 changes: 2 additions & 1 deletion upstream_utils/eigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def eigen_inclusions(dp, f):
modules = [
"Cholesky",
"Core",
"Dense",
"Eigenvalues",
"Geometry",
"Householder",
Expand Down Expand Up @@ -86,7 +87,7 @@ def unsupported_inclusions(dp, f):
return False

# Include the MatrixFunctions module
return "MatrixFunctions" in abspath
return "MatrixFunctions" in abspath or "SpecialFunctions" in abspath or "Tensor" in abspath or abspath.endswith("SpecialFunctionsFunctors.h")


def copy_upstream_src(wpilib_root):
Expand Down
35 changes: 32 additions & 3 deletions wpical/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ include(CompileWarnings)
include(GenResources)
include(LinkMacOSGUI)
include(AddTest)
include(FetchContent)

find_package (SuiteSparse 5.12 NO_MODULE)

configure_file(src/main/generate/WPILibVersion.cpp.in WPILibVersion.cpp)
generate_resources(src/main/native/resources generated/main/cpp WPIcal wpical wpical_resources_src)
Expand All @@ -25,6 +28,26 @@ elseif(APPLE)
set_source_files_properties(${APP_ICON_MACOSX} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
endif()

set(GTSAM_COMPILE_OPTIONS_PRIVATE_DEBUG CACHE INTERNAL FORCE)
set(GTSAM_COMPILE_OPTIONS_PRIVATE_RELWITHDEBINFO CACHE INTERNAL FORCE)
set(GTSAM_ENABLE_BOOST_SERIALIZATION OFF)
set(GTSAM_WITH_TBB OFF)
set(GTSAM_USE_BOOST_FEATURES OFF)
set(GTSAM_BUILD_PYTHON OFF)
set(GTSAM_BUILD_EXAMPLES_ALWAYS OFF)
set(GTSAM_BUILD_TESTS OFF)
set(BUILD_SHARED_LIBS OFF)
set(GTSAM_FORCE_SHARED_LIB OFF)
set(GTSAM_FORCE_STATIC_LIB ON)

include(FetchContent)
fetchcontent_declare(
gtsam
GIT_REPOSITORY https://github.com/mcm001/gtsam
GIT_TAG c24ca7951f1db4cfe4e23f368b2eda503de72176
)
fetchcontent_makeavailable(gtsam)

add_executable(
wpical
${wpical_src}
Expand All @@ -38,7 +61,9 @@ wpilib_target_warnings(wpical)
target_include_directories(
wpical
PRIVATE
/usr/local/include/
src/main/native/include
src/main/native/thirdparty/mrcal/generated
src/main/native/thirdparty/libdogleg/include
src/main/native/thirdparty/mrcal/include
src/main/native/thirdparty/mrcal_java/include
Expand Down Expand Up @@ -82,14 +107,16 @@ endif()
target_compile_options(wpical PRIVATE ${compile_flags})

find_package(OpenCV REQUIRED)
find_package(Ceres CONFIG REQUIRED)
target_link_libraries(
wpical
gtsam
apriltag
${OpenCV_LIBS}
wpigui
wpiutil
Ceres::ceres
wpimath
SuiteSparse::CHOLMOD
# Ceres::ceres
)

if(WIN32)
Expand Down Expand Up @@ -119,11 +146,13 @@ if(WITH_TESTS)
)
target_link_libraries(
wpical_test
gtsam
googletest
apriltag
${OpenCV_LIBS}
wpigui
wpiutil
Ceres::ceres
SuiteSparse::CHOLMOD
# Ceres::ceres
)
endif()
14 changes: 13 additions & 1 deletion wpical/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def wpilibVersionFileInput = file("src/main/generate/WPILibVersion.cpp.in")
def wpilibVersionFileOutput = file("$buildDir/generated/main/cpp/WPILibVersion.cpp")

apply from: "${rootDir}/shared/ceres.gradle"
apply from: "${rootDir}/shared/gtsam.gradle"
apply from: "${rootDir}/shared/opencv.gradle"

task generateCppVersion() {
Expand Down Expand Up @@ -156,12 +157,14 @@ model {
it.buildable = false
return
}
lib project: ':wpimath', library: 'wpimath', linkage: 'static'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
lib project: ':wpigui', library: 'wpigui', linkage: 'static'
lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static'
lib project: ':apriltag', library: 'apriltag', linkage: 'static'
nativeUtils.useRequiredLibrary(it, 'ceres')
nativeUtils.useRequiredLibrary(it, 'opencv_static')
nativeUtils.useRequiredLibrary(it, 'gtsam')
nativeUtils.useRequiredLibrary(it, 'ceres')
it.cppCompiler.define 'GLOG_USE_GLOG_EXPORT'
if (it.targetPlatform.operatingSystem.isWindows()) {
it.cppCompiler.define('GLOG_DEPRECATED', '__declspec(deprecated)')
Expand All @@ -175,6 +178,9 @@ model {
} else if (it.targetPlatform.operatingSystem.isMacOsX()) {
it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore' << '-framework' << 'Accelerate'
} else {
it.cppCompiler.args.add("-Wno-deprecated-copy")
it.cppCompiler.args.add("-Wno-redundant-move")
Comment on lines +181 to +182
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably fix these upstream instead


it.linker.args << '-lX11' << "-lgfortran"
if (it.targetPlatform.name.startsWith('linuxarm')) {
it.linker.args << '-lGL'
Expand Down Expand Up @@ -211,10 +217,13 @@ model {
lib project: ':wpigui', library: 'wpigui', linkage: 'static'
lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static'
lib project: ':apriltag', library: 'apriltag', linkage: 'static'
lib project: ':wpimath', library: 'wpimath', linkage: 'static'
nativeUtils.useRequiredLibrary(it, 'ceres')
nativeUtils.useRequiredLibrary(it, 'opencv_static')
nativeUtils.useRequiredLibrary(it, 'gtsam')
it.cppCompiler.define('PROJECT_ROOT_PATH', testResources)
it.cppCompiler.define 'GLOG_USE_GLOG_EXPORT'

if (it.targetPlatform.name == nativeUtils.wpi.platforms.windowsarm64) {
// https://developercommunity.visualstudio.com/t/-imp-std-init-once-complete-unresolved-external-sy/1684365#T-N10041864
it.linker.args << '/alternatename:__imp___std_init_once_complete=__imp_InitOnceComplete'
Expand All @@ -240,6 +249,9 @@ model {
if (it.targetPlatform.name.startsWith('linuxarm')) {
it.linker.args << '-lGL'
}

it.cppCompiler.args.add("-Wno-deprecated-copy")
it.cppCompiler.args.add("-Wno-redundant-move")
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions wpical/src/main/native/cpp/cameracalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ int cameracalibration::calibrate(const std::string& input_video,
cv::Size boardSize(board_width - 1, board_height - 1);
cv::Size imagerSize(imagerWidthPixels, imagerHeightPixels);

int frameIdx = 0;
while (video_capture.grab()) {
std::cout << "Frame index " << frameIdx << std::endl;
frameIdx++;

cv::Mat frame;
video_capture.retrieve(frame);

Expand Down
Loading
Loading