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

Commit dba1e17

Browse files
committed
Yeet PhotonCamera from PhotonPoseEstimator
1 parent 3d82de0 commit dba1e17

File tree

5 files changed

+155
-4
lines changed

5 files changed

+155
-4
lines changed

gen/RobotPoseEstimator.yml

+1
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

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
From a4d022e535b47989d0ac0710966644e49046267a 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 | 13 +------------
8+
1 file changed, 1 insertion(+), 12 deletions(-)
9+
10+
diff --git a/photonlib/PhotonPoseEstimator.h b/photonlib/PhotonPoseEstimator.h
11+
index 367043d73b20..a878e887ae5a 100644
12+
--- a/photonlib/PhotonPoseEstimator.h
13+
+++ b/photonlib/PhotonPoseEstimator.h
14+
@@ -28,11 +28,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+
#include "photonlib/PhotonPipelineResult.h"
22+
23+
namespace photonlib {
24+
enum PoseStrategy : int {
25+
LOWEST_AMBIGUITY,
26+
@@ -69,16 +68,15 @@ class PhotonPoseEstimator {
27+
* at (1.0,2.0,3.0) </code> }
28+
*
29+
* @param aprilTags A AprilTagFieldLayout linking AprilTag IDs to Pose3ds with
30+
* respect to the FIRST field.
31+
* @param strategy The strategy it should use to determine the best pose.
32+
- * @param camera PhotonCameras and
33+
* @param robotToCamera Transform3d from the center of the robot to the camera
34+
* mount positions (ie, robot ➔ camera).
35+
*/
36+
explicit PhotonPoseEstimator(frc::AprilTagFieldLayout aprilTags,
37+
- PoseStrategy strategy, PhotonCamera&& camera,
38+
+ PoseStrategy strategy,
39+
frc::Transform3d robotToCamera);
40+
41+
/**
42+
* Get the AprilTagFieldLayout being used by the PositionEstimator.
43+
*
44+
@@ -141,28 +139,19 @@ class PhotonPoseEstimator {
45+
*
46+
* @param lastPose the lastPose to set
47+
*/
48+
inline void SetLastPose(frc::Pose3d lastPose) { this->lastPose = lastPose; }
49+
50+
- /**
51+
- * Update the pose estimator. Internally grabs a new PhotonPipelineResult from
52+
- * the camera and process it.
53+
- */
54+
- std::optional<EstimatedRobotPose> Update();
55+
-
56+
/**
57+
* Update the pose estimator.
58+
*/
59+
std::optional<EstimatedRobotPose> Update(const PhotonPipelineResult& result);
60+
61+
- inline PhotonCamera& GetCamera() { return camera; }
62+
-
63+
private:
64+
frc::AprilTagFieldLayout aprilTags;
65+
PoseStrategy strategy;
66+
67+
- PhotonCamera camera;
68+
frc::Transform3d m_robotToCamera;
69+
70+
frc::Pose3d lastPose;
71+
frc::Pose3d referencePose;
72+
73+
--
74+
2.39.1
75+

photonvision/src/sources.patch

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From a4d022e535b47989d0ac0710966644e49046267a 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 16ef7661112c..cf052f5847a4 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

+16-4
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-8-g3edc8750"
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

+15
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)