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

Commit b805f3f

Browse files
authored
Update docs and Java for pose estimator refactoring (#262)
* Update docs and Java for pose estimator refactoring * Fix types in example * Fix headers * Fix header and use RLI * Add note about one camera per instance
1 parent 190a02d commit b805f3f

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

source/docs/examples/apriltag.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Knowledge and Equipment Needed
1212
- An open space with properly mounted 16h5 AprilTags
1313
- PhotonVision running on your laptop or a coprocessor
1414

15-
This is example will show how to use AprilTags for full field robot localization using ``RobotPoseEstimator``, ``AprilTagFieldLayout``, and the WPILib Pose Estimaton Classes.
15+
This is example will show how to use AprilTags for full field robot localization using ``PhotonPoseEstimator``, ``AprilTagFieldLayout``, and the WPILib Pose Estimaton Classes.
1616

1717
All PhotonVision specific code is in ``PhotonCameraWrapper.java`` and the relevant pose estimation parts are in ``DriveTrain.java.``
1818

source/docs/integration/aprilTagStrategies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ The nature of how AprilTags will be laid out makes it very likely that you will
3939
* A camera seeing one target, and picking a pose most similar to one provided externally (ie, from previous loop's odometry)
4040
* A camera seeing one target, and picking the pose with the lowest ambiguity.
4141

42-
PhotonVision supports all of these different strategies via our ``RobotPoseEstimator`` class (coming soon) that allows you to select one of the strategies above and get the relevant pose estimation.
42+
PhotonVision supports all of these different strategies via our ``PhotonPoseEstimator`` class that allows you to select one of the strategies above and get the relevant pose estimation.
4343

4444
All of these strategies are valid approaches, and we recommend doing independent testing in order to see which one works best for your team / current game.

source/docs/programming/photonlib/robot-pose-estimator.rst

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
AprilTags and RobotPoseEstimator
2-
================================
1+
AprilTags and PhotonPoseEstimator
2+
=================================
33

44
.. note:: For more information on how to methods to get AprilTag data, look :ref:`here <docs/programming/photonlib/getting-target-data:Getting AprilTag Data From A Target>`.
55

6-
PhotonLib includes a ``RobotPoseEstimator`` class, which allows you to combine the pose data from all tags in view in order to get a field relative pose.
6+
PhotonLib includes a ``PhotonPoseEstimator`` class, which allows you to combine the pose data from all tags in view in order to get a field relative pose. The ``PhotonPoseEstimator`` class works with one camera per object instance, but more than one instance may be created.
77

88
Creating an ``AprilTagFieldLayout``
99
-----------------------------------
@@ -29,9 +29,9 @@ The API documentation can be found in here: `Java <https://github.wpilib.org/all
2929
std::shared_ptr<frc::AprilTagFieldLayout> aprilTags =
3030
std::make_shared<frc::AprilTagFieldLayout>(tags, 54_ft, 27_ft);
3131

32-
Creating a ``RobotPoseEstimator``
33-
---------------------------------
34-
The RobotPoseEstimator has a constructor that takes an ``AprilTagFieldLayout`` (see above), ``PoseStrategy``, and ``ArrayList<Pair<PhotonCamera, Transform3d>>``. ``PoseStrategy`` has five possible values:
32+
Creating a ``PhotonPoseEstimator``
33+
----------------------------------
34+
The PhotonPoseEstimator has a constructor that takes an ``AprilTagFieldLayout`` (see above), ``PoseStrategy``, ``PhotonCamera``, and ``Transform3d``. ``PoseStrategy`` has five possible values:
3535

3636
* LOWEST_AMBIGUITY
3737
* Choose the Pose with the lowest ambiguity.
@@ -51,12 +51,8 @@ The RobotPoseEstimator has a constructor that takes an ``AprilTagFieldLayout`` (
5151
cam = new PhotonCamera("testCamera");
5252
Transform3d robotToCam = new Transform3d(new Translation3d(0.5, 0.0, 0.5), new Rotation3d(0,0,0)); //Cam mounted facing forward, half a meter forward of center, half a meter up from center.
5353
54-
// ... Add other cameras here
55-
56-
// Assemble the list of cameras & mount locations
57-
var camList = new ArrayList<Pair<PhotonCamera, Transform3d>>();
58-
camList.add(new Pair<PhotonCamera, Transform3d>(cam, robotToCam));
59-
RobotPoseEstimator robotPoseEstimator = new RobotPoseEstimator(aprilTagFieldLayout, PoseStrategy.CLOSEST_TO_REFERENCE_POSE, camList);
54+
// Construct PhotonPoseEstimator
55+
PhotonPoseEstimator photonPoseEstimator = new PhotonPoseEstimator(aprilTagFieldLayout, PoseStrategy.CLOSEST_TO_REFERENCE_POSE, cam, robotToCam);
6056
6157
.. code-block:: c++
6258

@@ -80,24 +76,14 @@ The RobotPoseEstimator has a constructor that takes an ``AprilTagFieldLayout`` (
8076
photonlib::RobotPoseEstimator estimator(
8177
aprilTags, photonlib::CLOSEST_TO_REFERENCE_POSE, cameras);
8278

83-
Using a ``RobotPoseEstimator``
84-
------------------------------
85-
Calling ``update()`` on your ``RobotPoseEstimator`` will return a ``Pair<Pose3d, Double>``, which includes a ``Pose3d`` of the latest estimated pose (using the selected strategy) along with a ``Double`` of the latency in milliseconds.
79+
Using a ``PhotonPoseEstimator``
80+
-------------------------------
81+
Calling ``update()`` on your ``PhotonPoseEstimator`` will return an ``EstimatedRobotPose``, which includes a ``Pose3d`` of the latest estimated pose (using the selected strategy) along with a ``double`` of the timestamp when the robot pose was estimated. You should be updating your `drivetrain pose estimator <https://docs.wpilib.org/en/latest/docs/software/advanced-controls/state-space/state-space-pose-estimators.html>`_ with the result from the ``PhotonPoseEstimator`` every loop using ``addVisionMeasurement()``. See our `code example <https://github.com/PhotonVision/photonvision/tree/master/photonlib-java-examples/apriltagExample>`_ for more.
8682

8783
.. tab-set-code::
88-
.. code-block:: java
89-
90-
public Pair<Pose2d, Double> getEstimatedGlobalPose(Pose2d prevEstimatedRobotPose) {
91-
robotPoseEstimator.setReferencePose(prevEstimatedRobotPose);
92-
93-
double currentTime = Timer.getFPGATimestamp();
94-
Optional<Pair<Pose3d, Double>> result = robotPoseEstimator.update();
95-
if (result.isPresent()) {
96-
return new Pair<Pose2d, Double>(result.get().getFirst().toPose2d(), currentTime - result.get().getSecond());
97-
} else {
98-
return new Pair<Pose2d, Double>(null, 0.0);
99-
}
100-
}
84+
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/357d8a518a93f7a1f8084a79449249e613b605a7/photonlib-java-examples/apriltagExample/src/main/java/frc/robot/PhotonCameraWrapper.java
85+
:language: java
86+
:lines: 85-88
10187

10288
.. code-block:: c++
10389

@@ -116,8 +102,8 @@ Calling ``update()`` on your ``RobotPoseEstimator`` will return a ``Pair<Pose3d,
116102

117103
You should be updating your `drivetrain pose estimator <https://docs.wpilib.org/en/latest/docs/software/advanced-controls/state-space/state-space-pose-estimators.html>`_ with the result from the ``RobotPoseEstimator`` every loop using ``addVisionMeasurement()``. See our :ref:`code example <docs/examples/apriltag:knowledge and equipment needed>` for more.
118104

119-
Additional ``RobotPoseEstimator`` Methods
120-
-----------------------------------------
105+
Additional ``PhotonPoseEstimator`` Methods
106+
------------------------------------------
121107

122108
``setReferencePose(Pose3d referencePose)``
123109
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)