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

Commit 62ff1cf

Browse files
authored
Apriltag example doc(#248)
* add apriltag example * linter * linter again * add optional in apriltag example * forgot to save file
1 parent 802f7dc commit 62ff1cf

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

source/docs/examples/apriltag.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
Using AprilTags for Pose Estimation
22
===================================
33

4-
This is example will show how to use AprilTags for full field robot localization using ``RobotPoseEstimator`` and the WPILib Pose Estimation classes.
4+
The following example is from the PhotonLib example repository (`Java <https://github.com/PhotonVision/photonvision/tree/master/photonlib-java-examples/apriltagExample>`_).
55

6-
Code
7-
----
86

9-
.. tab-set::
7+
Knowledge and Equipment Needed
8+
------------------------------
109

11-
.. tab-item:: Java
10+
- Everything required in :ref:`Aiming at a Target <docs/examples/aimingatatarget:Knowledge and Equipment Needed>`.
11+
- Large space where your robot can move around freely
12+
- An open space with properly mounted 16h5 AprilTags
13+
- PhotonVision running on your laptop or a coprocessor
1214

13-
// Coming soon! (before 2023 season)
15+
This is example will show how to use AprilTags for full field robot localization using ``RobotPoseEstimator``, ``AprilTagFieldLayout``, and the WPILib Pose Estimaton Classes.
1416

15-
.. tab-item:: C++ (Header)
17+
All PhotonVision specific code is in ``PhotonCameraWrapper.java`` and the relevant pose estimation parts are in ``DriveTrain.java.``
1618

17-
// Coming soon! (before 2023 season)
18-
19-
.. tab-item:: C++ (Source)
20-
21-
// Coming soon! (before 2023 season)
19+
Please note that this code does not support simulation in the traditional sense (properly simulating each target that can be detected within sim), but you can still see the pose the camera is returning from the tags using Glass / Field2d when you are running PhotonVision on a robot. Make sure you properly set your ip/hostname in ``Robot.java`` when doing this.

source/docs/getting-started/april-tags.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Getting Started With AprilTags
2828

2929
4. Read the :ref:`PhotonLib documentation<docs/programming/photonlib/getting-target-data:Getting AprilTag Data From A Target>` on how to use AprilTag data in your code.
3030

31-
5. Read the :ref:`example code<docs/examples/apriltag:Code>` on a fully featured example on different ways to use AprilTags.
31+
5. Read the :ref:`example code<docs/examples/apriltag:Knowledge and Equipment Needed>` on a fully featured example on different ways to use AprilTags.

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ Calling ``update()`` on your ``RobotPoseEstimator`` will return a ``Pair<Pose3d,
8787
.. tab-set-code::
8888
.. code-block:: java
8989
90-
public Pair<Pose2d, Double> getEstimatedGlobalPose(Pose3d prevEstimatedRobotPose) {
91-
robotPoseEstimator.setReferencePose(prevEstimatedRobotPose);
92-
var currentTime = Timer.getFPGATimestamp();
93-
var result = robotPoseEstimator.update();
94-
if(result.getFirst() != null){
95-
return new Pair<Pose2d, Double>(result.getFirst().toPose2d(), currentTime - result.getSecond());
96-
} else {
97-
return new Pair<Pose2d, Double>(null, 0.0);
98-
}
99-
}
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+
}
100101
101102
.. code-block:: c++
102103

0 commit comments

Comments
 (0)