diff --git a/out.txt b/out.txt deleted file mode 100644 index 6d432d3f64..0000000000 Binary files a/out.txt and /dev/null differ diff --git a/photon-lib/build.gradle b/photon-lib/build.gradle index 8faa751359..4e4a828dcb 100644 --- a/photon-lib/build.gradle +++ b/photon-lib/build.gradle @@ -111,8 +111,13 @@ model { lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared' lib library: nativeName - nativeUtils.useRequiredLibrary(it, "wpilib_shared") } + + nativeUtils.useRequiredLibrary(it, "wpilib_shared") + nativeUtils.useRequiredLibrary(it, "cscore_shared") + nativeUtils.useRequiredLibrary(it, "cameraserver_shared") + nativeUtils.useRequiredLibrary(it, "apriltag_shared") + nativeUtils.useRequiredLibrary(it, "opencv_shared") } } testSuites { @@ -185,7 +190,7 @@ model { binaries { withType(NativeBinarySpec).all { - println "${it.toolChain} -> ${it.component.baseName} -> ${it.toolChain instanceof VisualCpp}" + // println "${it.toolChain} -> ${it.component.baseName} -> ${it.toolChain instanceof VisualCpp}" if((it.component.baseName == "photonlibpy" || it.component.baseName == nativeName)) { if (it.toolChain instanceof VisualCpp) { @@ -267,7 +272,6 @@ task installPhotonlibpyNative(type: Copy) { "opencv_imgcodecs480.dll", "opencv_flann480.dll", "opencv_imgproc480.dll", - "libcameraserver.so", "libcscore.so", "libopencv_core.so.4.8", diff --git a/photon-lib/clang-format.sh b/photon-lib/clang-format.sh deleted file mode 100644 index 0b72f3b51c..0000000000 --- a/photon-lib/clang-format.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -################################################################################ -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -################################################################################ -# -# This script will install the llvm toolchain on the different -# Debian and Ubuntu versions - -set -eux - -# read optional command line argument -LLVM_VERSION=10 -if [ "$#" -eq 1 ]; then - LLVM_VERSION=$1 -fi - -DISTRO=$(lsb_release -is) -VERSION=$(lsb_release -sr) -DIST_VERSION="${DISTRO}_${VERSION}" - -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root!" - exit 1 -fi - -declare -A LLVM_VERSION_PATTERNS -LLVM_VERSION_PATTERNS[9]="-9" -LLVM_VERSION_PATTERNS[10]="-10" -LLVM_VERSION_PATTERNS[11]="" - -if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then - echo "This script does not support LLVM version $LLVM_VERSION" - exit 3 -fi - -LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]} - -# find the right repository name for the distro and version -case "$DIST_VERSION" in - Debian_9* ) REPO_NAME="deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch$LLVM_VERSION_STRING main" ;; - Debian_10* ) REPO_NAME="deb http://apt.llvm.org/buster/ llvm-toolchain-buster$LLVM_VERSION_STRING main" ;; - Debian_unstable ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING main" ;; - Debian_testing ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING main" ;; - Ubuntu_16.04 ) REPO_NAME="deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial$LLVM_VERSION_STRING main" ;; - Ubuntu_18.04 ) REPO_NAME="deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic$LLVM_VERSION_STRING main" ;; - Ubuntu_18.10 ) REPO_NAME="deb http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic$LLVM_VERSION_STRING main" ;; - Ubuntu_19.04 ) REPO_NAME="deb http://apt.llvm.org/disco/ llvm-toolchain-disco$LLVM_VERSION_STRING main" ;; - Ubuntu_19.10 ) REPO_NAME="deb http://apt.llvm.org/eoan/ llvm-toolchain-eoan$LLVM_VERSION_STRING main" ;; - Ubuntu_20.04 ) REPO_NAME="deb http://apt.llvm.org/focal/ llvm-toolchain-focal$LLVM_VERSION_STRING main" ;; - * ) - echo "Distribution '$DISTRO' in version '$VERSION' is not supported by this script (${DIST_VERSION})." - exit 2 -esac - - -# install everything -wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - -add-apt-repository "${REPO_NAME}" -apt-get update -apt-get install -y clang-format-$LLVM_VERSION diff --git a/photon-lib/py/.gitignore b/photon-lib/py/.gitignore index b2f285ac3d..b0a40ce793 100644 --- a/photon-lib/py/.gitignore +++ b/photon-lib/py/.gitignore @@ -6,3 +6,4 @@ photonlibpy/version.py photonlibpy/*.so* photonlibpy/*.dylib* photonlibpy/*.dll* +photonlibpy/*.pyd diff --git a/photon-lib/py/create_photonlib_pyi.py b/photon-lib/py/create_photonlib_pyi.py index 9b06757c21..052e8315c1 100644 --- a/photon-lib/py/create_photonlib_pyi.py +++ b/photon-lib/py/create_photonlib_pyi.py @@ -1,7 +1,7 @@ def write_stubgen(): import os - cwd = os.getcwd() + os.getcwd() # From nanobind==2.1.0 from nanobind.stubgen import StubGen diff --git a/photon-lib/py/photonlibpy/__init__.py b/photon-lib/py/photonlibpy/__init__.py index 417f6f4dfb..be92e35825 100644 --- a/photon-lib/py/photonlibpy/__init__.py +++ b/photon-lib/py/photonlibpy/__init__.py @@ -32,5 +32,6 @@ # and now our extension module import os + os.add_dll_directory(os.path.dirname(os.path.realpath(__file__))) from ._photonlibpy import * diff --git a/photon-lib/py/setup.py b/photon-lib/py/setup.py index c08286db2f..0b5cac2674 100644 --- a/photon-lib/py/setup.py +++ b/photon-lib/py/setup.py @@ -1,5 +1,4 @@ import os -import platform from setuptools import setup, find_packages import subprocess, re diff --git a/photon-lib/src/main/pybindings/cpp/photonlib_nanobind.cpp b/photon-lib/src/main/pybindings/cpp/photonlib_nanobind.cpp index 21b26ab80f..474a504360 100644 --- a/photon-lib/src/main/pybindings/cpp/photonlib_nanobind.cpp +++ b/photon-lib/src/main/pybindings/cpp/photonlib_nanobind.cpp @@ -23,7 +23,11 @@ */ #include + +#include + #include "photon/PhotonCamera.h" +#include "photon/simulation/VisionSystemSim.h" // actual nanobind include #include @@ -31,11 +35,38 @@ #include #include -NB_MODULE(_photonlibpy, m) { - namespace nb = nanobind; +namespace nb = nanobind; +using namespace nb::literals; - m.doc() = "C++ bindings for photonlib"; +// repr helper +template <> struct fmt::formatter : formatter { + auto format(photon::PhotonTrackedTarget const &c, format_context &ctx) const { + return fmt::format_to(ctx.out(), "PhotonTrackedTarget", c.yaw, c.pitch); + } +}; +template <> struct fmt::formatter : formatter { + auto format(photon::PhotonPipelineMetadata const &c, format_context &ctx) const { + return fmt::format_to(ctx.out(), "PhotonPipelineMetadata", c.sequenceID); + } +}; + +frc::Pose3d makePose(double x, double y, double z, double W, double X, double Y, + double Z) { + return frc::Pose3d{frc::Translation3d{units::meter_t{x}, units::meter_t{y}, + units::meter_t{z}}, + frc::Rotation3d{frc::Quaternion{W, X, Y, Z}}}; +} +void wrap_geom(nb::module_ m) { + using namespace frc; + nb::class_(m, "Transform3d").def(nb::init<>()); + nb::class_(m, "Pose3d") + .def(nb::init<>()) + .def(nb::new_(&makePose), + "Create a Pose3d from translation/rotation components"); +} + +void wrap_photon(nb::module_ m) { nb::class_(m, "PhotonPipelineMetadata") .def_ro("sequenceID", &photon::PhotonPipelineMetadata::sequenceID) .def_ro("captureTimestampMicros", @@ -50,20 +81,56 @@ NB_MODULE(_photonlibpy, m) { .def("__repr__", [](const photon::PhotonTrackedTarget& t) { std::string s; fmt::format_to(std::back_inserter(s), - "PhotonTrackedTarget", t.yaw, t.pitch); + "{}>", t); return s; }); nb::class_(m, "MultiTargetPNPResult") - .def_ro("fiducialIDsUsed", &photon::MultiTargetPNPResult::fiducialIDsUsed) - ; + .def_ro("fiducialIDsUsed", + &photon::MultiTargetPNPResult::fiducialIDsUsed); nb::class_(m, "PhotonPipelineResult") .def_ro("metadata", &photon::PhotonPipelineResult::metadata) .def_ro("targets", &photon::PhotonPipelineResult::targets) - .def_ro("multitagResult", &photon::PhotonPipelineResult::multitagResult); + .def_ro("multitagResult", &photon::PhotonPipelineResult::multitagResult) + .def("__repr__", [](const photon::PhotonPipelineResult& t) { + std::string s; + fmt::format_to(std::back_inserter(s), + "PhotonPipelineResult", t.metadata, fmt::join(t.targets, ", ")); + return s; + }); nb::class_(m, "PhotonCamera") .def(nb::init()) .def("GetDriverMode", &photon::PhotonCamera::GetDriverMode) .def("GetLatestResult", &photon::PhotonCamera::GetLatestResult); } + +void wrap_photon_sim(nb::module_ m) { + using namespace photon; + + nb::class_(m, "VisionSystemSim") + .def(nb::init()) + .def("AddCamera", &VisionSystemSim::AddCamera) + .def("AddVisionTargets", + nb::overload_cast&>( + &VisionSystemSim::AddVisionTargets)) + .def("Update", + nb::overload_cast(&VisionSystemSim::Update)); + + nb::class_(m, "PhotonCameraSim") + .def(nb::init()); + + nb::class_(m, "VisionTargetSim") + .def(nb::init(), "pose"_a, "model"_a, "Create a simulated target at a given pose") + .def(nb::init(), "pose"_a, "model"_a, "fiducial_id"_a, "Create a simulated AprilTag at a given pose"); + + nb::class_(m, "TargetModel").def(nb::init()); +} + +NB_MODULE(_photonlibpy, m) { + m.doc() = "C++ bindings for photonlib"; + + wrap_photon(m); + wrap_photon_sim(m); + wrap_geom(m); +} diff --git a/photon-targeting/src/main/native/cpp/photon/targeting/proto/MultiTargetPNPResultProto.cpp b/photon-targeting/src/main/native/cpp/photon/targeting/proto/MultiTargetPNPResultProto.cpp index 0bd08c1cee..cc67ec213f 100644 --- a/photon-targeting/src/main/native/cpp/photon/targeting/proto/MultiTargetPNPResultProto.cpp +++ b/photon-targeting/src/main/native/cpp/photon/targeting/proto/MultiTargetPNPResultProto.cpp @@ -17,6 +17,8 @@ #include "photon/targeting/proto/MultiTargetPNPResultProto.h" +#include + #include "photon.pb.h" #include "photon/targeting/proto/PNPResultProto.h" diff --git a/photon-targeting/src/main/native/include/photon/estimation/VisionEstimation.h b/photon-targeting/src/main/native/include/photon/estimation/VisionEstimation.h index b2dace10a1..2e87f19fa2 100644 --- a/photon-targeting/src/main/native/include/photon/estimation/VisionEstimation.h +++ b/photon-targeting/src/main/native/include/photon/estimation/VisionEstimation.h @@ -48,6 +48,7 @@ namespace VisionEstimation { #include +[[maybe_unused]] static std::optional EstimateCamPosePNP( const Eigen::Matrix& cameraMatrix, const Eigen::Matrix& distCoeffs, diff --git a/photon-targeting/src/test/native/cpp/PacketTest.cpp b/photon-targeting/src/test/native/cpp/PacketTest.cpp index 0fb5697029..5398fae4c1 100644 --- a/photon-targeting/src/test/native/cpp/PacketTest.cpp +++ b/photon-targeting/src/test/native/cpp/PacketTest.cpp @@ -16,6 +16,7 @@ */ #include +#include #include diff --git a/photonlib-python-examples/aimandrange/robot.py b/photonlib-python-examples/aimandrange/robot.py index 617f0ccbad..9afa3b3551 100644 --- a/photonlib-python-examples/aimandrange/robot.py +++ b/photonlib-python-examples/aimandrange/robot.py @@ -25,8 +25,6 @@ import math import wpilib -import wpimath -import wpimath.geometry import drivetrain from photonlibpy import PhotonCamera diff --git a/photonlib-python-examples/aimandrange/tests/pyfrc_test.py b/photonlib-python-examples/aimandrange/tests/pyfrc_test.py index e195147143..235b61fa34 100644 --- a/photonlib-python-examples/aimandrange/tests/pyfrc_test.py +++ b/photonlib-python-examples/aimandrange/tests/pyfrc_test.py @@ -2,5 +2,3 @@ This test module imports tests that come with pyfrc, and can be used to test basic functionality of just about any robot. """ - -from pyfrc.tests import * diff --git a/photonlib-python-examples/aimattarget/tests/pyfrc_test.py b/photonlib-python-examples/aimattarget/tests/pyfrc_test.py index e195147143..235b61fa34 100644 --- a/photonlib-python-examples/aimattarget/tests/pyfrc_test.py +++ b/photonlib-python-examples/aimattarget/tests/pyfrc_test.py @@ -2,5 +2,3 @@ This test module imports tests that come with pyfrc, and can be used to test basic functionality of just about any robot. """ - -from pyfrc.tests import * diff --git a/photonlib-python-examples/poseest/tests/pyfrc_test.py b/photonlib-python-examples/poseest/tests/pyfrc_test.py index e195147143..235b61fa34 100644 --- a/photonlib-python-examples/poseest/tests/pyfrc_test.py +++ b/photonlib-python-examples/poseest/tests/pyfrc_test.py @@ -2,5 +2,3 @@ This test module imports tests that come with pyfrc, and can be used to test basic functionality of just about any robot. """ - -from pyfrc.tests import *