Skip to content

Commit

Permalink
whippyformat and copyright stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gerth2 committed Sep 8, 2024
1 parent 1da3519 commit 9dee7a2
Show file tree
Hide file tree
Showing 34 changed files with 598 additions and 213 deletions.
17 changes: 16 additions & 1 deletion photon-lib/py/photonlibpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# No one here but us chickens
###############################################################################
## Copyright (C) Photon Vision.
###############################################################################
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################

from .packet import Packet # noqa
from .estimatedRobotPose import EstimatedRobotPose # noqa
Expand Down
17 changes: 17 additions & 0 deletions photon-lib/py/photonlibpy/estimatedRobotPose.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
###############################################################################
## Copyright (C) Photon Vision.
###############################################################################
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################

from dataclasses import dataclass
from typing import TYPE_CHECKING

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class MultiTargetPNPResultSerde:

# Message definition md5sum. See photon_packet.adoc for details
MESSAGE_VERSION = "ffc1cb847deb6e796a583a5b1885496b"
MESSAGE_FORMAT = "PnpResult estimatedPose;int16[?] fiducialIDsUsed;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class PhotonPipelineMetadataSerde:

# Message definition md5sum. See photon_packet.adoc for details
MESSAGE_VERSION = "2a7039527bda14d13028a1b9282d40a2"
MESSAGE_FORMAT = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class PhotonPipelineResultSerde:

# Message definition md5sum. See photon_packet.adoc for details
MESSAGE_VERSION = "cb3e1605048ba49325888eb797399fe2"
MESSAGE_FORMAT = "PhotonPipelineMetadata metadata;PhotonTrackedTarget[?] targets;MultiTargetPNPResult? multiTagResult;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class PhotonTrackedTargetSerde:

# Message definition md5sum. See photon_packet.adoc for details
MESSAGE_VERSION = "8fdada56b9162f2e32bd24f0055d7b60"
MESSAGE_FORMAT = "float64 yaw;float64 pitch;float64 area;float64 skew;int32 fiducialId;int32 objDetectId;float32 objDetectConf;Transform3d bestCameraToTarget;Transform3d altCameraToTarget;float64 poseAmbiguity;TargetCorner[?] minAreaRectCorners;TargetCorner[?] detectedCorners;"
Expand Down
1 change: 0 additions & 1 deletion photon-lib/py/photonlibpy/generated/PnpResultSerde.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class PnpResultSerde:

# Message definition md5sum. See photon_packet.adoc for details
MESSAGE_VERSION = "0d1f2546b00f24718e30f38d206d4491"
MESSAGE_FORMAT = "Transform3d best;Transform3d alt;float64 bestReprojErr;float64 altReprojErr;float64 ambiguity;"
Expand Down
1 change: 0 additions & 1 deletion photon-lib/py/photonlibpy/generated/TargetCornerSerde.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class TargetCornerSerde:

# Message definition md5sum. See photon_packet.adoc for details
MESSAGE_VERSION = "22b1ff7551d10215af6fb3672fe4eda8"
MESSAGE_FORMAT = "float64 x;float64 y;"
Expand Down
17 changes: 17 additions & 0 deletions photon-lib/py/photonlibpy/packet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
###############################################################################
## Copyright (C) Photon Vision.
###############################################################################
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################

import struct
from typing import Any, Optional, Type
from wpimath.geometry import Transform3d, Translation3d, Rotation3d, Quaternion
Expand Down
17 changes: 17 additions & 0 deletions photon-lib/py/photonlibpy/photonCamera.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
###############################################################################
## Copyright (C) Photon Vision.
###############################################################################
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################

from enum import Enum
from typing import List
import ntcore
Expand Down
17 changes: 17 additions & 0 deletions photon-lib/py/photonlibpy/photonPoseEstimator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
###############################################################################
## Copyright (C) Photon Vision.
###############################################################################
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################

import enum
from typing import Optional

Expand Down
17 changes: 17 additions & 0 deletions photon-lib/py/test/photonPoseEstimator_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
###############################################################################
## Copyright (C) Photon Vision.
###############################################################################
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################

# from photonlibpy import MultiTargetPNPResult, PnpResult
# from photonlibpy import PhotonPipelineResult
# from photonlibpy import PhotonPoseEstimator, PoseStrategy
Expand Down
18 changes: 17 additions & 1 deletion photon-lib/py/test/photonlibpy_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
###############################################################################
## Copyright (C) Photon Vision.
###############################################################################
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################

from time import sleep
from photonlibpy import PhotonCamera
import ntcore
from photonlibpy.photonCamera import setVersionCheckEnabled


def test_roundTrip():

ntcore.NetworkTableInstance.getDefault().stopServer()
ntcore.NetworkTableInstance.getDefault().setServer("localhost")
ntcore.NetworkTableInstance.getDefault().startClient4("meme")
Expand Down
4 changes: 2 additions & 2 deletions photon-lib/src/main/native/include/photon/PhotonCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class PhotonCamera {
*/
std::vector<PhotonPipelineResult> GetAllUnreadResults();

[[deprecated("Replace with GetAllUnreadResults")]]
PhotonPipelineResult GetLatestResult();
[[deprecated("Replace with GetAllUnreadResults")]] PhotonPipelineResult
GetLatestResult();

/**
* Toggles driver mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ static std::vector<cv::Point2f> GetConvexHull(
return convexPoints;
}

[[maybe_unused]]
static cv::RotatedRect GetMinAreaRect(const std::vector<cv::Point2f>& points) {
[[maybe_unused]] static cv::RotatedRect GetMinAreaRect(
const std::vector<cv::Point2f>& points) {
return cv::minAreaRect(points);
}

Expand Down Expand Up @@ -144,8 +144,7 @@ static std::vector<cv::Point3f> RotationToRVec(
return cv::boundingRect(points);
}

[[maybe_unused]]
static std::vector<cv::Point2f> ProjectPoints(
[[maybe_unused]] static std::vector<cv::Point2f> ProjectPoints(
const Eigen::Matrix<double, 3, 3>& cameraMatrix,
const Eigen::Matrix<double, 8, 1>& distCoeffs,
const RotTrlTransform3d& camRt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
namespace photon {
namespace VisionEstimation {

[[maybe_unused]]
static std::vector<frc::AprilTag> GetVisibleLayoutTags(
[[maybe_unused]] static std::vector<frc::AprilTag> GetVisibleLayoutTags(
const std::vector<PhotonTrackedTarget>& visTags,
const frc::AprilTagFieldLayout& layout) {
std::vector<frc::AprilTag> retVal{};
Expand Down
2 changes: 1 addition & 1 deletion photonlib-python-examples/aimandrange/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ out/
*-window.json
networktables.json

__pycache__
__pycache__
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"teamNumber": 1736}
{"teamNumber": 1736}
96 changes: 65 additions & 31 deletions photonlib-python-examples/aimandrange/drivetrain.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
###################################################################################
# MIT License
#
# Copyright (c) FIRST and other WPILib contributors.
# Open Source Software; you can modify and/or share it under the terms of
# the WPILib BSD license file in the root directory of this project.
# Copyright (c) PhotonVision
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###################################################################################


import math
import wpilib
Expand All @@ -26,10 +45,10 @@ def __init__(self) -> None:
self.backLeftLocation = wpimath.geometry.Translation2d(-0.381, 0.381)
self.backRightLocation = wpimath.geometry.Translation2d(-0.381, -0.381)

self.frontLeft = swervemodule.SwerveModule(1, 2, 0, 1, 2, 3, 1)
self.frontLeft = swervemodule.SwerveModule(1, 2, 0, 1, 2, 3, 1)
self.frontRight = swervemodule.SwerveModule(3, 4, 4, 5, 6, 7, 2)
self.backLeft = swervemodule.SwerveModule(5, 6, 8, 9, 10, 11, 3)
self.backRight = swervemodule.SwerveModule(7, 8, 12, 13, 14, 15, 4)
self.backLeft = swervemodule.SwerveModule(5, 6, 8, 9, 10, 11, 3)
self.backRight = swervemodule.SwerveModule(7, 8, 12, 13, 14, 15, 4)

self.debugField = wpilib.Field2d()
wpilib.SmartDashboard.putData("Drivetrain Debug", self.debugField)
Expand Down Expand Up @@ -97,7 +116,6 @@ def drive(

self.targetChassisSpeeds = self.kinematics.toChassisSpeeds(swerveModuleStates)


def updateOdometry(self) -> None:
"""Updates the field relative position of the robot."""
self.odometry.update(
Expand All @@ -111,29 +129,37 @@ def updateOdometry(self) -> None:
)

def getModuleStates(self) -> list[wpimath.kinematics.SwerveModuleState]:
return [
self.frontLeft.getState(),
self.frontRight.getState(),
self.backLeft.getState(),
self.backRight.getState(),
]
return [
self.frontLeft.getState(),
self.frontRight.getState(),
self.backLeft.getState(),
self.backRight.getState(),
]

def getModulePoses(self) -> list[wpimath.geometry.Pose2d]:
p = self.odometry.getPose()
flTrans = wpimath.geometry.Transform2d(self.frontLeftLocation, self.frontLeft.getAbsoluteHeading())
frTrans = wpimath.geometry.Transform2d(self.frontRightLocation, self.frontRight.getAbsoluteHeading())
blTrans = wpimath.geometry.Transform2d(self.backLeftLocation, self.backLeft.getAbsoluteHeading())
brTrans = wpimath.geometry.Transform2d(self.backRightLocation, self.backRight.getAbsoluteHeading())
return [
p.transformBy(flTrans),
p.transformBy(frTrans),
p.transformBy(blTrans),
p.transformBy(brTrans),
]
flTrans = wpimath.geometry.Transform2d(
self.frontLeftLocation, self.frontLeft.getAbsoluteHeading()
)
frTrans = wpimath.geometry.Transform2d(
self.frontRightLocation, self.frontRight.getAbsoluteHeading()
)
blTrans = wpimath.geometry.Transform2d(
self.backLeftLocation, self.backLeft.getAbsoluteHeading()
)
brTrans = wpimath.geometry.Transform2d(
self.backRightLocation, self.backRight.getAbsoluteHeading()
)
return [
p.transformBy(flTrans),
p.transformBy(frTrans),
p.transformBy(blTrans),
p.transformBy(brTrans),
]

def getChassisSpeeds(self) -> wpimath.kinematics.ChassisSpeeds:
return self.kinematics.toChassisSpeeds(self.getModuleStates())

def log(self):
table = "Drive/"

Expand All @@ -145,12 +171,20 @@ def log(self):
chassisSpeeds = self.getChassisSpeeds()
wpilib.SmartDashboard.putNumber(table + "VX", chassisSpeeds.vx)
wpilib.SmartDashboard.putNumber(table + "VY", chassisSpeeds.vy)
wpilib.SmartDashboard.putNumber(table + "Omega Degrees", chassisSpeeds.omega_dps)
wpilib.SmartDashboard.putNumber(
table + "Omega Degrees", chassisSpeeds.omega_dps
)

wpilib.SmartDashboard.putNumber(
table + "Target VX", self.targetChassisSpeeds.vx
)
wpilib.SmartDashboard.putNumber(
table + "Target VY", self.targetChassisSpeeds.vy
)
wpilib.SmartDashboard.putNumber(
table + "Target Omega Degrees", self.targetChassisSpeeds.omega_dps
)

wpilib.SmartDashboard.putNumber(table + "Target VX", self.targetChassisSpeeds.vx)
wpilib.SmartDashboard.putNumber(table + "Target VY", self.targetChassisSpeeds.vy)
wpilib.SmartDashboard.putNumber(table + "Target Omega Degrees", self.targetChassisSpeeds.omega_dps)

self.frontLeft.log()
self.frontRight.log()
self.backLeft.log()
Expand All @@ -165,4 +199,4 @@ def simulationPeriodic(self):
self.backLeft.simulationPeriodic()
self.backRight.simulationPeriodic()
self.simGyro.setRate(-1.0 * self.getChassisSpeeds().omega_dps)
self.simGyro.setAngle(self.simGyro.getAngle() + self.simGyro.getRate() * 0.02)
self.simGyro.setAngle(self.simGyro.getAngle() + self.simGyro.getRate() * 0.02)
Loading

0 comments on commit 9dee7a2

Please sign in to comment.