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

WPIcal: Field Calibration Tool #6915

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0575cce
Update 10/20/2024.
ElliotScher Oct 21, 2024
f37c4a5
Remove unused dependencies.
ElliotScher Oct 21, 2024
a835dd7
Remove unused dependencies from CMakeLists.txt.
ElliotScher Oct 21, 2024
6acd803
Merge branch 'wpilibsuite:main' into main
ElliotScher Oct 21, 2024
106b174
Resolve final dependency errors.
ElliotScher Oct 22, 2024
c4666c3
Add mrcal, libdogleg, and mrcal-java
Gold856 Oct 22, 2024
d6381e9
Add ceres
Gold856 Oct 22, 2024
2ffe672
Merge pull request #2 from Gold856/mrcal
ElliotScher Oct 22, 2024
a9e1bf9
Update shared/ceres.gradle
ElliotScher Oct 22, 2024
9478a7d
Update shared/ceres.gradle
ElliotScher Oct 22, 2024
b8b0bcf
Update wpical/build.gradle
ElliotScher Oct 22, 2024
5092322
Merge branch 'wpilibsuite:main' into main
ElliotScher Oct 22, 2024
83d2c08
Format and lint.
ElliotScher Oct 22, 2024
8436c65
Link opencv.
ElliotScher Oct 22, 2024
7235462
Merge branch 'wpilibsuite:main' into main
ElliotScher Oct 23, 2024
955c3fb
C code compiles.
ElliotScher Oct 25, 2024
19403e0
Revert "Link opencv."
ElliotScher Oct 25, 2024
3035a17
Merge branch 'wpilibsuite:main' into main
ElliotScher Oct 25, 2024
8c8bcb5
Remove wpimath dependency.
ElliotScher Oct 25, 2024
e08f44e
Add stereo and remove const points array.
ElliotScher Oct 25, 2024
39efbba
Merge branch 'wpilibsuite:main' into main
ElliotScher Oct 26, 2024
130ab65
Merge branch 'wpilibsuite:main' into main
ElliotScher Oct 27, 2024
09919a4
Update to ceres 2.2-2
ElliotScher Oct 28, 2024
314d6c8
Add compiler suppressions.
ElliotScher Oct 28, 2024
18b3d15
Add Glog error suppression.
ElliotScher Oct 28, 2024
1cf076b
Fix GLOG_NO_EXPORT.
ElliotScher Oct 28, 2024
69f9ed1
Fix cholmod.h header path
ElliotScher Oct 28, 2024
4a4f742
Fix thirdparty upstream utils.
ElliotScher Oct 28, 2024
ac6c17c
Fix mrcal warnings.
ElliotScher Oct 28, 2024
3cc2b12
Add c/cpp compiler suppressions.
ElliotScher Oct 28, 2024
fb2c8b1
add deprecated declarations suppression.
ElliotScher Oct 29, 2024
16349be
Merge branch 'main' into main
ElliotScher Oct 29, 2024
b29e4c1
Fix glog errors.
ElliotScher Nov 1, 2024
a9aa0a1
Merge branch 'wpilibsuite:main' into main
ElliotScher Nov 5, 2024
7111eb2
Fix mrcal build errors.
ElliotScher Nov 6, 2024
b9e57b9
Merge branch 'wpilibsuite:main' into main
ElliotScher Nov 6, 2024
8ff3856
Update opencv.
ElliotScher Nov 7, 2024
2ef720a
Merge branch 'wpilibsuite:main' into main
ElliotScher Nov 7, 2024
138e592
Merge branch 'main' into main
ElliotScher Nov 11, 2024
f260ef5
fix opencv version.
ElliotScher Nov 11, 2024
a937a06
Update shared/config.gradle
ElliotScher Nov 11, 2024
f158766
Update shared/opencv.gradle
ElliotScher Nov 11, 2024
053ce55
Fix cameracalibration aruco includes.
ElliotScher Nov 11, 2024
ef8c59e
Add maybe-uninitialized suppression.
ElliotScher Nov 11, 2024
cd1959e
Merge branch 'wpilibsuite:main' into main
ElliotScher Nov 16, 2024
1b55089
More MSVC fixes
Gold856 Nov 11, 2024
f0ff201
Merge pull request #4 from Gold856/wpical
ElliotScher Nov 16, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/comment-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
python-version: '3.12'
- name: Install jinja
run: python -m pip install jinja2
- name: Install protobuf dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler && wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf-1.3.3-linux-x86_64.exe && chmod +x protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Install protobuf and perl dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler liblist-moreutils-perl && wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf-1.3.3-linux-x86_64.exe && chmod +x protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Regenerate all
run: ./.github/workflows/pregen_all.py --quickbuf_plugin=protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Commit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pregenerate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
with:
name: pregenerated-files-fixes
path: pregenerated-files-fixes.patch
if: ${{ failure() }}
if: ${{ failure() }}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ include 'epilogue-processor'
include 'epilogue-runtime'
include 'thirdparty:googletest'
include 'thirdparty:imgui_suite'
include 'wpical'

buildCache {
def cred = {
Expand Down
13 changes: 13 additions & 0 deletions shared/ceres.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
nativeUtils {
nativeDependencyContainer {
ceres(getNativeDependencyTypeClass('WPIStaticMavenDependency')) {
groupId = "edu.wpi.first.thirdparty.frc2024.ceres"
artifactId = "ceres-cpp"
headerClassifier = "headers"
sourceClassifier = "sources"
ext = "zip"
version = '2.2-2'
targetPlatforms.addAll(nativeUtils.wpi.platforms.desktopPlatforms)
}
}
}
2 changes: 1 addition & 1 deletion shared/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ nativeUtils {
configureDependencies {
opencvYear = "frc2024"
niLibVersion = "2025.0.0"
opencvVersion = "4.8.0-4"
opencvVersion = "4.8.0-5"
ElliotScher marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion shared/opencv.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def opencvVersion = '4.8.0-4'
def opencvVersion = '4.8.0-5'

ElliotScher marked this conversation as resolved.
Show resolved Hide resolved
if (project.hasProperty('useCpp') && project.useCpp) {
model {
Expand Down
57 changes: 57 additions & 0 deletions upstream_utils/libdogleg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3

import os
import shutil

from upstream_utils import Lib, walk_cwd_and_copy_if


def copy_upstream_src(wpilib_root):
wpical = os.path.join(wpilib_root, "wpical")

# Delete old install
for d in [
"src/main/native/thirdparty/libdogleg/src",
"src/main/native/thirdparty/libdogleg/include",
]:
shutil.rmtree(os.path.join(wpical, d), ignore_errors=True)

files = walk_cwd_and_copy_if(
lambda dp, f: f.endswith("dogleg.h"),
os.path.join(wpical, "src/main/native/thirdparty/libdogleg/include"),
)
for f in files:
with open(f) as file:
content = file.read()
content = content.replace(
"#include <cholmod.h>", "#include <suitesparse/cholmod.h>"
)
with open(f, "w") as file:
file.write(content)

files = walk_cwd_and_copy_if(
lambda dp, f: f.endswith("dogleg.c"),
os.path.join(wpical, "src/main/native/thirdparty/libdogleg/src"),
)
for f in files:
with open(f) as file:
content = file.read()
content = content.replace("#warning", "// #warning")
content = content.replace(
"#include <cholmod_function.h>", "#include <suitesparse/cholmod_function.h>"
)
with open(f, "w") as file:
file.write(content)


def main():
name = "libdogleg"
url = "https://github.com/dkogan/libdogleg"
tag = "c971ea43088d286a3683c1039b9a85f761f7df15"

libdogleg = Lib(name, url, tag, copy_upstream_src)
libdogleg.main()


if __name__ == "__main__":
main()
53 changes: 53 additions & 0 deletions upstream_utils/mrcal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import os
import shutil

from upstream_utils import Lib, walk_cwd_and_copy_if


def copy_upstream_src(wpilib_root):
wpical = os.path.join(wpilib_root, "wpical")

# Delete old install
for d in [
"src/main/native/thirdparty/mrcal/src",
"src/main/native/thirdparty/mrcal/include",
]:
shutil.rmtree(os.path.join(wpical, d), ignore_errors=True)

files = walk_cwd_and_copy_if(
lambda dp, f: (f.endswith(".h") or f.endswith(".hh"))
and not f.endswith("stereo-matching-libelas.h")
and not dp.startswith(os.path.join(".", "test")),
os.path.join(wpical, "src/main/native/thirdparty/mrcal/include"),
)
files = walk_cwd_and_copy_if(
lambda dp, f: (f.endswith(".c") or f.endswith(".cc") or f.endswith(".pl"))
and not f.endswith("mrcal-pywrap.c")
and not f.endswith("image.c")
and not f.endswith("stereo-matching-libelas.cc")
and not f.endswith("uncertainty.c")
and not dp.startswith(os.path.join(".", "doc"))
and not dp.startswith(os.path.join(".", "test")),
os.path.join(wpical, "src/main/native/thirdparty/mrcal/src"),
)

for f in files:
with open(f) as file:
content = file.read()
content = content.replace("#warning", "// #warning")
with open(f, "w") as file:
file.write(content)

def main():
name = "mrcal"
url = "https://github.com/dkogan/mrcal"
tag = "71c89c4e9f268a0f4fb950325e7d551986a281ec"

mrcal = Lib(name, url, tag, copy_upstream_src)
mrcal.main()


if __name__ == "__main__":
main()
71 changes: 71 additions & 0 deletions upstream_utils/mrcal_java.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3

import os
import shutil

from upstream_utils import Lib, walk_cwd_and_copy_if

def delete_lines_by_range(file_path, start_line, end_line):
# Read all lines from the file
with open(file_path, 'r') as file:
lines = file.readlines()

# Filter out lines that are within the specified range
filtered_lines = [line for i, line in enumerate(lines, start=1) if not (start_line <= i <= end_line)]

# Write the remaining lines back to the file
with open(file_path, 'w') as file:
file.writelines(filtered_lines)

def copy_upstream_src(wpilib_root):
wpical = os.path.join(wpilib_root, "wpical")

# Delete old install
for d in [
"src/main/native/thirdparty/mrcal_java/src",
"src/main/native/thirdparty/mrcal_java/include",
]:
shutil.rmtree(os.path.join(wpical, d), ignore_errors=True)

os.chdir("src")
files = walk_cwd_and_copy_if(
lambda dp, f: f.endswith("mrcal_wrapper.h"),
os.path.join(wpical, "src/main/native/thirdparty/mrcal_java/include"),
)

for f in files:
delete_lines_by_range(f, 24, 29)

files = walk_cwd_and_copy_if(
lambda dp, f: f.endswith("mrcal_wrapper.cpp"),
os.path.join(wpical, "src/main/native/thirdparty/mrcal_java/src"),
)

for f in files:
delete_lines_by_range(f, 30, 41)

for f in files:
with open(f) as file:
content = file.read()
content = content.replace("// mrcal_point3_t *c_observations_point_pool = observations_point;", "mrcal_point3_t *c_observations_point_pool = observations_point;")
content = content.replace("// mrcal_observation_point_triangulated_t *observations_point_triangulated =", "mrcal_observation_point_triangulated_t *observations_point_triangulated = NULL;")
content = content.replace("// observations_point_triangulated,", "observations_point_triangulated,")
content = content.replace("// 0, // hard-coded to 0", "0, // hard-coded to 0")
content = content.replace("// observations_point_triangulated, -1,", "observations_point_triangulated, -1,")
content = content.replace("c_observations_board_pool, &mrcal_lensmodel, c_imagersizes,", "c_observations_board_pool, c_observations_point_pool, &mrcal_lensmodel, c_imagersizes,")
content = content.replace("calobject_warp, stats.Noutliers);", "calobject_warp, stats.Noutliers_board);")
with open(f, "w") as file:
file.write(content)


def main():
name = "mrcal-java"
url = "https://github.com/PhotonVision/mrcal-java"
tag = "d05b8ff0df95eafaf4321b5242882b28aaf23061"

mrcal_java = Lib(name, url, tag, copy_upstream_src)
mrcal_java.main()


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions wpical/.styleguide
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cppHeaderFileInclude {
\.h$
\.inc$
\.inl$
}

cppSrcFileInclude {
\.cpp$
}

generatedFileExclude {
src/main/native/resources/
src/main/native/thirdparty/
src/main/native/win/wpical.ico
src/main/native/mac/wpical.icns
}

repoRootNameOverride {
wpical
}

includeOtherLibs {
^GLFW
^ceres/
^fmt/
^frc/
^gtest/
^imgui
^implot\.h$
^mrcal_wrapper\.h$
^opencv2\.h$
^portable-file-dialogs\.h$
^tagpose\.h$
^wpi/
^wpigui
}
45 changes: 45 additions & 0 deletions wpical/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
project(wpical)

include(CompileWarnings)
include(GenResources)
include(LinkMacOSGUI)
include(AddTest)

configure_file(src/main/generate/WPILibVersion.cpp.in WPILibVersion.cpp)
generate_resources(src/main/native/resources generated/main/cpp WPIcal wpical wpical_resources_src)

file(GLOB wpical_src src/main/native/cpp/*.cpp ${CMAKE_CURRENT_BINARY_DIR}/WPILibVersion.cpp)

if(WIN32)
set(wpical_rc src/main/native/win/wpical.rc)
elseif(APPLE)
set(MACOSX_BUNDLE_ICON_FILE wpical.icns)
set(APP_ICON_MACOSX src/main/native/mac/wpical.icns)
set_source_files_properties(${APP_ICON_MACOSX} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
endif()

add_executable(wpical ${wpical_src} ${wpical_resources_src} ${wpical_rc} ${APP_ICON_MACOSX})
wpilib_link_macos_gui(wpical)
wpilib_target_warnings(wpical)
target_include_directories(wpical PRIVATE src/main/native/include)

find_package(OpenCV REQUIRED)
target_link_libraries(wpical apriltaglib ${OpenCV_LIBS})

if(WIN32)
set_target_properties(wpical PROPERTIES WIN32_EXECUTABLE YES)
elseif(APPLE)
set_target_properties(wpical PROPERTIES MACOSX_BUNDLE YES OUTPUT_NAME "wpical")
endif()

if(WITH_TESTS)
wpilib_add_test(wpical src/test/native/cpp)
wpilib_link_macos_gui(wpical_test)
target_sources(wpical_test PRIVATE ${sysid_src})
target_compile_definitions(wpical_test PRIVATE RUNNING_WPICAL_TEST)
if(MSVC)
target_compile_options(wpical_test PRIVATE /utf-8)
endif()
target_include_directories(wpical_test PRIVATE src/main/native/cpp src/main/native/include)
target_link_libraries(wpical_test googletest)
endif()
32 changes: 32 additions & 0 deletions wpical/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>WPIcal</string>
<key>CFBundleExecutable</key>
<string>wpical</string>
<key>CFBundleDisplayName</key>
<string>WPIcal</string>
<key>CFBundleIdentifier</key>
<string>edu.wpi.first.tools.WPIcal</string>
<key>CFBundleIconFile</key>
<string>ov.icns</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>2021</string>
<key>CFBundleVersion</key>
<string>2021</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
Loading
Loading