Skip to content

Commit

Permalink
Add mrcal, libdogleg, and mrcal-java
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Oct 22, 2024
1 parent 6acd803 commit f2b4bdb
Show file tree
Hide file tree
Showing 36 changed files with 20,430 additions and 34 deletions.
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.9
- 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
1 change: 1 addition & 0 deletions .github/workflows/pregen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def main(argv):
args = parser.parse_args(argv)
subprocess.run(["python", f"{REPO_ROOT}/hal/generate_usage_reporting.py"])
subprocess.run(["python", f"{REPO_ROOT}/ntcore/generate_topics.py"])
subprocess.run(["python", f"{REPO_ROOT}/wpical/generate_mrcal.py"])
subprocess.run(["python", f"{REPO_ROOT}/wpimath/generate_numbers.py"])
subprocess.run(
[
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pregenerate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python-version: 3.9
- 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: python ./.github/workflows/pregen_all.py --quickbuf_plugin protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Add untracked files to index so they count as changes
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ include 'fieldImages'
include 'glass'
include 'outlineviewer'
include 'roborioteamnumbersetter'
include 'wpical'
include 'datalogtool'
include 'sysid'
include 'simulation:halsim_ds_socket'
Expand Down
39 changes: 39 additions & 0 deletions upstream_utils/libdogleg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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)

walk_cwd_and_copy_if(
lambda dp, f: f.endswith("dogleg.h"),
os.path.join(wpical, "src/main/native/thirdparty/libdogleg/include"),
)
walk_cwd_and_copy_if(
lambda dp, f: f.endswith("dogleg.c"),
os.path.join(wpical, "src/main/native/thirdparty/libdogleg/src"),
)


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()
49 changes: 49 additions & 0 deletions upstream_utils/mrcal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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)

walk_cwd_and_copy_if(
lambda dp, f: (f.endswith(".h") or f.endswith(".hh"))
and not f.endswith("stereo.h")
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"),
)
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.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"),
)


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()
40 changes: 40 additions & 0 deletions upstream_utils/mrcal_java.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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_java/src",
"src/main/native/thirdparty/mrcal_java/include",
]:
shutil.rmtree(os.path.join(wpical, d), ignore_errors=True)

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


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()
56 changes: 28 additions & 28 deletions wpical/assets/camera calibration.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"avg_reprojection_error": 0.4013144307258122,
"camera_matrix": [
1767.289258236593,
0.0,
989.375282791521,
0.0,
1762.888503314327,
540.8313845443114,
0.0,
0.0,
1.0
],
"distortion_coefficients": [
0.3860266675089004,
-2.563775891333845,
-0.0011477914008921702,
0.0017287037946633974,
5.69767996193624,
0.03549071109208592,
0.11781261237320696,
-0.22713730056480883,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
"avg_reprojection_error": 0.4013144307258122,
"camera_matrix": [
1767.289258236593,
0.0,
989.375282791521,
0.0,
1762.888503314327,
540.8313845443114,
0.0,
0.0,
1.0
],
"distortion_coefficients": [
0.3860266675089004,
-2.563775891333845,
-0.0011477914008921702,
0.0017287037946633974,
5.69767996193624,
0.03549071109208592,
0.11781261237320696,
-0.22713730056480883,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
}
14 changes: 12 additions & 2 deletions wpical/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (project.hasProperty('onlylinuxathena')) {

description = "Field Calibration Tool"

apply plugin: 'c'
apply plugin: 'cpp'
apply plugin: 'visual-studio'
apply plugin: 'edu.wpi.first.NativeUtils'
Expand Down Expand Up @@ -76,11 +77,20 @@ model {
sources {
cpp {
source {
srcDirs 'src/main/native/cpp', "$buildDir/generated/main/cpp"
srcDirs 'src/main/native/cpp','src/main/native/thirdparty/mrcal/src','src/main/native/thirdparty/mrcal_java/src', "$buildDir/generated/main/cpp"
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include'
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/mrcal/include', 'src/main/native/thirdparty/mrcal_java/include'
}
}
c {
source {
srcDirs 'src/main/native/thirdparty/libdogleg/src', 'src/main/native/thirdparty/mrcal/src'
include '**/*.c'
}
exportedHeaders {
srcDirs 'src/main/native/include', 'src/main/native/thirdparty/mrcal/include','src/main/native/thirdparty/mrcal/include/minimath', 'src/main/native/thirdparty/libdogleg/include'
}
}
if (OperatingSystem.current().isWindows()) {
Expand Down
32 changes: 32 additions & 0 deletions wpical/generate_mrcal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
import argparse
import subprocess
import sys
from pathlib import Path


def main(argv):
script_path = Path(__file__).resolve()
dirname = script_path.parent

parser = argparse.ArgumentParser()
parser.add_argument(
"--output_directory",
help="Optional. If set, will output the generated files to this directory, otherwise it will use a path relative to the script",
default=dirname / "src/main/native/thirdparty/mrcal/generated/",
type=Path,
)
args = parser.parse_args(argv)

args.output_directory.mkdir(parents=True, exist_ok=True)
result = subprocess.run(
f"{dirname}/src/main/native/thirdparty/mrcal/src/minimath/minimath_generate.pl",
capture_output=True,
)
(args.output_directory / "minimath_generated.h").write_text(
str(result.stdout, encoding="UTF8")
)


if __name__ == "__main__":
main(sys.argv[1:])
Loading

0 comments on commit f2b4bdb

Please sign in to comment.