This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
basic python docs #332
Merged
Merged
basic python docs #332
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ The ``PhotonCamera`` class has two constructors: one that takes a ``NetworkTable | |
:language: c++ | ||
:lines: 42-43 | ||
|
||
.. code-block:: python | ||
|
||
# Change this to match the name of your camera | ||
self.camera = PhotonCamera("photonvision") | ||
|
||
|
||
.. warning:: Teams must have unique names for all of their cameras regardless of which coprocessor they are attached to. | ||
|
||
Getting the Pipeline Result | ||
|
@@ -44,6 +50,13 @@ Use the ``getLatestResult()``/``GetLatestResult()`` (Java and C++ respectively) | |
:language: c++ | ||
:lines: 35-36 | ||
|
||
.. code-block:: python | ||
|
||
# Query the latest result from PhotonVision | ||
result = self.camera.getLatestResult() | ||
|
||
|
||
|
||
.. note:: Unlike other vision software solutions, using the latest result guarantees that all information is from the same timestamp. This is achievable because the PhotonVision backend sends a byte-packed string of data which is then deserialized by PhotonLib to get target data. For more information, check out the `PhotonLib source code <https://github.com/PhotonVision/photonvision/tree/master/photon-lib>`_. | ||
|
||
|
||
|
@@ -63,7 +76,13 @@ Each pipeline result has a ``hasTargets()``/``HasTargets()`` (Java and C++ respe | |
// Check if the latest result has any targets. | ||
bool hasTargets = result.HasTargets(); | ||
|
||
.. warning:: You must *always* check if the result has a target via ``hasTargets()``/``HasTargets()`` before getting targets or else you may get a null pointer exception. Further, you must use the same result in every subsequent call in that loop. | ||
.. code-block:: python | ||
|
||
// Check if the latest result has any targets. | ||
hasTargets = result.hasTargets() | ||
|
||
.. warning:: In Java/C++, You must *always* check if the result has a target via ``hasTargets()``/``HasTargets()`` before getting targets or else you may get a null pointer exception. Further, you must use the same result in every subsequent call in that loop. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why we never just ended up making this an optional value. Not relevant to the review. Relevant to the review: does this not need to be checked in python? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well python just returns an empty array. so user still has to deal with it but the behavior is better than null pointer. I'm not sure Optional was in a ton of use in FRC at the time the API shape was formed.... but probably worthwhile for a summer thing |
||
|
||
|
||
Getting a List of Targets | ||
------------------------- | ||
|
@@ -86,6 +105,10 @@ You can get a list of tracked targets using the ``getTargets()``/``GetTargets()` | |
// Get a list of currently tracked targets. | ||
wpi::ArrayRef<photonlib::PhotonTrackedTarget> targets = result.GetTargets(); | ||
|
||
.. code-block:: python | ||
|
||
targets = result.getTargets() | ||
|
||
Getting the Best Target | ||
----------------------- | ||
You can get the :ref:`best target <docs/reflectiveAndShape/contour-filtering:Contour Grouping and Sorting>` using ``getBestTarget()``/``GetBestTarget()`` (Java and C++ respectively) method from the pipeline result. | ||
|
@@ -101,6 +124,12 @@ You can get the :ref:`best target <docs/reflectiveAndShape/contour-filtering:Con | |
// Get the current best target. | ||
photonlib::PhotonTrackedTarget target = result.GetBestTarget(); | ||
|
||
|
||
.. code-block:: python | ||
|
||
# TODO - Not currently supported | ||
|
||
|
||
Getting Data From A Target | ||
-------------------------- | ||
* double ``getYaw()``/``GetYaw()``: The yaw of the target in degrees (positive right). | ||
|
@@ -132,6 +161,16 @@ Getting Data From A Target | |
frc::Transform2d pose = target.GetCameraToTarget(); | ||
wpi::SmallVector<std::pair<double, double>, 4> corners = target.GetCorners(); | ||
|
||
.. code-block:: python | ||
|
||
# Get information from target. | ||
yaw = target.getYaw() | ||
pitch = target.getPitch() | ||
area = target.getArea() | ||
skew = target.getSkew() | ||
pose = target.getCameraToTarget() | ||
corners = target.getDetectedCorners() | ||
|
||
Getting AprilTag Data From A Target | ||
----------------------------------- | ||
.. note:: All of the data above (**except skew**) is available when using AprilTags. | ||
|
@@ -158,6 +197,14 @@ Getting AprilTag Data From A Target | |
frc::Transform3d bestCameraToTarget = target.getBestCameraToTarget(); | ||
frc::Transform3d alternateCameraToTarget = target.getAlternateCameraToTarget(); | ||
|
||
.. code-block:: python | ||
|
||
# Get information from target. | ||
targetID = target.getFiducialId() | ||
poseAmbiguity = target.getPoseAmbiguity() | ||
bestCameraToTarget = target.getBestCameraToTarget() | ||
alternateCameraToTarget = target.getAlternateCameraToTarget() | ||
|
||
Saving Pictures to File | ||
----------------------- | ||
A ``PhotonCamera`` can save still images from the input or output video streams to file. This is useful for debugging what a camera is seeing while on the field and confirming targets are being identified properly. | ||
|
@@ -182,4 +229,12 @@ Images are stored within the PhotonVision configuration directory. Running the " | |
// Capture post-process camera stream image | ||
camera.TakeOutputSnapshot(); | ||
|
||
.. code-block:: python | ||
|
||
# Capture pre-process camera stream image | ||
camera.takeInputSnapshot() | ||
|
||
# Capture post-process camera stream image | ||
camera.takeOutputSnapshot() | ||
|
||
.. note:: Saving images to file takes a bit of time and uses up disk space, so doing it frequently is not recommended. In general, the camera will save an image every 500ms. Calling these methods faster will not result in additional images. Consider tying image captures to a button press on the driver controller, or an appropriate point in an autonomous routine. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Work in progress for 4 years and counting 😄