Skip to content
This repository was archived by the owner on Jan 4, 2024. It is now read-only.

Commit 3a31a4c

Browse files
committed
Yeet PhotonCamera from PhotonPoseEstimator
1 parent f9d9cf5 commit 3a31a4c

File tree

5 files changed

+169
-4
lines changed

5 files changed

+169
-4
lines changed

gen/RobotPoseEstimator.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extra_includes:
44

55
enums:
66
PoseStrategy:
7+
ignore: true # duplicated in PhotonPoseEstimator.h
78
classes:
89
RobotPoseEstimator:
910
force_type_casters:

photonvision/src/headers.patch

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
From 16749a065bb5bad6c62764d78a1a2ae1ca4ee6f7 Mon Sep 17 00:00:00 2001
2+
From: David Vo <[email protected]>
3+
Date: Sat, 11 Feb 2023 17:50:54 +1100
4+
Subject: [PATCH] Yeet PhotonCamera from PhotonPoseEstimator
5+
6+
---
7+
photonlib/PhotonPoseEstimator.h | 16 +---------------
8+
1 file changed, 1 insertion(+), 15 deletions(-)
9+
10+
diff --git a/photonlib/PhotonPoseEstimator.h b/photonlib/PhotonPoseEstimator.h
11+
index 10b89f499c0a..5ed0ee53f11d 100644
12+
--- a/photonlib/PhotonPoseEstimator.h
13+
+++ b/photonlib/PhotonPoseEstimator.h
14+
@@ -31,12 +31,10 @@
15+
16+
#include <frc/apriltag/AprilTagFieldLayout.h>
17+
#include <frc/geometry/Pose3d.h>
18+
#include <frc/geometry/Transform3d.h>
19+
20+
-#include "photonlib/PhotonCamera.h"
21+
-
22+
namespace photonlib {
23+
enum PoseStrategy : int {
24+
LOWEST_AMBIGUITY,
25+
CLOSEST_TO_CAMERA_HEIGHT,
26+
CLOSEST_TO_REFERENCE_POSE,
27+
@@ -61,12 +59,10 @@ struct EstimatedRobotPose {
28+
* in field pose, using the strategy set below. Example usage can be found in
29+
* our apriltagExample example project.
30+
*/
31+
class PhotonPoseEstimator {
32+
public:
33+
- using map_value_type =
34+
- std::pair<std::shared_ptr<PhotonCamera>, frc::Transform3d>;
35+
using size_type = std::vector<map_value_type>::size_type;
36+
37+
/**
38+
* Create a new PhotonPoseEstimator.
39+
*
40+
@@ -75,16 +71,15 @@ class PhotonPoseEstimator {
41+
* at (1.0,2.0,3.0) </code> }
42+
*
43+
* @param aprilTags A AprilTagFieldLayout linking AprilTag IDs to Pose3ds with
44+
* respect to the FIRST field.
45+
* @param strategy The strategy it should use to determine the best pose.
46+
- * @param camera PhotonCameras and
47+
* @param robotToCamera Transform3d from the center of the robot to the camera
48+
* mount positions (ie, robot ➔ camera).
49+
*/
50+
explicit PhotonPoseEstimator(frc::AprilTagFieldLayout aprilTags,
51+
- PoseStrategy strategy, PhotonCamera&& camera,
52+
+ PoseStrategy strategy,
53+
frc::Transform3d robotToCamera);
54+
55+
/**
56+
* Get the AprilTagFieldLayout being used by the PositionEstimator.
57+
*
58+
@@ -147,28 +142,19 @@ class PhotonPoseEstimator {
59+
*
60+
* @param lastPose the lastPose to set
61+
*/
62+
inline void SetLastPose(frc::Pose3d lastPose) { this->lastPose = lastPose; }
63+
64+
- /**
65+
- * Update the pose estimator. Internally grabs a new PhotonPipelineResult from
66+
- * the camera and process it.
67+
- */
68+
- std::optional<EstimatedRobotPose> Update();
69+
-
70+
/**
71+
* Update the pose estimator.
72+
*/
73+
std::optional<EstimatedRobotPose> Update(const PhotonPipelineResult& result);
74+
75+
- inline PhotonCamera& GetCamera() { return camera; }
76+
-
77+
private:
78+
frc::AprilTagFieldLayout aprilTags;
79+
PoseStrategy strategy;
80+
81+
- PhotonCamera camera;
82+
frc::Transform3d m_robotToCamera;
83+
84+
frc::Pose3d lastPose;
85+
frc::Pose3d referencePose;
86+
87+
--
88+
2.39.1
89+

photonvision/src/sources.patch

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 16749a065bb5bad6c62764d78a1a2ae1ca4ee6f7 Mon Sep 17 00:00:00 2001
2+
From: David Vo <[email protected]>
3+
Date: Sat, 11 Feb 2023 17:50:54 +1100
4+
Subject: [PATCH] Yeet PhotonCamera from PhotonPoseEstimator
5+
6+
---
7+
photonlib/PhotonPoseEstimator.cpp | 9 +--------
8+
1 file changed, 1 insertion(+), 8 deletions(-)
9+
10+
diff --git a/photonlib/PhotonPoseEstimator.cpp b/photonlib/PhotonPoseEstimator.cpp
11+
index ecdc03eb1b80..81e474c63a63 100644
12+
--- a/photonlib/PhotonPoseEstimator.cpp
13+
+++ b/photonlib/PhotonPoseEstimator.cpp
14+
@@ -36,30 +36,23 @@
15+
#include <frc/geometry/Pose3d.h>
16+
#include <frc/geometry/Rotation3d.h>
17+
#include <frc/geometry/Transform3d.h>
18+
#include <units/time.h>
19+
20+
-#include "photonlib/PhotonCamera.h"
21+
#include "photonlib/PhotonPipelineResult.h"
22+
#include "photonlib/PhotonTrackedTarget.h"
23+
24+
namespace photonlib {
25+
PhotonPoseEstimator::PhotonPoseEstimator(frc::AprilTagFieldLayout tags,
26+
- PoseStrategy strat, PhotonCamera&& cam,
27+
+ PoseStrategy strat,
28+
frc::Transform3d robotToCamera)
29+
: aprilTags(tags),
30+
strategy(strat),
31+
- camera(std::move(cam)),
32+
m_robotToCamera(robotToCamera),
33+
lastPose(frc::Pose3d()),
34+
referencePose(frc::Pose3d()) {}
35+
36+
-std::optional<EstimatedRobotPose> PhotonPoseEstimator::Update() {
37+
- auto result = camera.GetLatestResult();
38+
- return Update(result);
39+
-}
40+
-
41+
std::optional<EstimatedRobotPose> PhotonPoseEstimator::Update(
42+
const PhotonPipelineResult& result) {
43+
if (!result.HasTargets()) {
44+
return std::nullopt;
45+
}
46+
--
47+
2.39.1
48+

pyproject.toml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,31 @@ install_requires = [
2424
[tool.robotpy-build]
2525
base_package = "photonvision"
2626

27-
[tool.robotpy-build.static_libs."photonlib".maven_lib_download]
27+
[tool.robotpy-build.wrappers."photonvision".maven_lib_download]
2828
artifact_id = "PhotonLib-cpp"
2929
group_id = "org.photonvision"
3030
repo_url = "https://maven.photonvision.org/repository/snapshots"
3131
version = "dev-v2023.3.0-6-g0255798d"
3232

33-
libs = ["Photon"]
33+
use_sources = true
34+
sources = [
35+
"photonlib/PhotonCamera.cpp",
36+
"photonlib/PhotonPipelineResult.cpp",
37+
"photonlib/PhotonPoseEstimator.cpp",
38+
"photonlib/PhotonTrackedTarget.cpp",
39+
"photonlib/RobotPoseEstimator.cpp",
40+
]
41+
42+
[[tool.robotpy-build.wrappers."photonvision".maven_lib_download.patches]]
43+
patch = "photonvision/src/sources.patch"
44+
45+
[[tool.robotpy-build.wrappers."photonvision".maven_lib_download.header_patches]]
46+
patch = "photonvision/src/headers.patch"
3447

3548
[tool.robotpy-build.wrappers."photonvision"]
3649
name = "photonvision"
3750

3851
depends = [
39-
"photonlib",
4052
"apriltag",
4153
"wpilibc",
4254
"wpimath_geometry",
@@ -57,7 +69,7 @@ generation_data = "gen"
5769
Packet = "photonlib/Packet.h"
5870
PhotonCamera = "photonlib/PhotonCamera.h"
5971
PhotonPipelineResult = "photonlib/PhotonPipelineResult.h"
60-
#PhotonPoseEstimator = "photonlib/PhotonPoseEstimator.h"
72+
PhotonPoseEstimator = "photonlib/PhotonPoseEstimator.h"
6173
PhotonTargetSortMode = "photonlib/PhotonTargetSortMode.h"
6274
PhotonTrackedTarget = "photonlib/PhotonTrackedTarget.h"
6375
PhotonUtils = "photonlib/PhotonUtils.h"

tests/test_pose_estimator.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import robotpy_apriltag
2+
from wpimath.geometry import Transform3d
3+
4+
import photonvision
5+
6+
7+
def test_photon_pose_estimator_ctor():
8+
estimator = photonvision.PhotonPoseEstimator(
9+
robotpy_apriltag.loadAprilTagLayoutField(
10+
robotpy_apriltag.AprilTagField.k2023ChargedUp
11+
),
12+
photonvision.PoseStrategy.AVERAGE_BEST_TARGETS,
13+
Transform3d(),
14+
)
15+
assert estimator

0 commit comments

Comments
 (0)