Files
PhotonVision/docs/source/docs/examples/aimingatatarget.md
Dan Katzuv 7d2c69dbdb Fix "ArUco" and "ChAruCo" spellings (#2184)
## Description
Looks like this is the convention from a quick Google search.
## Meta

Merge checklist:
- [x] Pull Request title is [short, imperative
summary](https://cbea.ms/git-commit/) of proposed changes
- [x] The description documents the _what_ and _why_
- [ ] This PR has been
[linted](https://docs.photonvision.org/en/latest/docs/contributing/linting.html).
- [ ] If this PR changes behavior or adds a feature, user documentation
is updated
- [ ] If this PR touches photon-serde, all messages have been
regenerated and hashes have not changed unexpectedly
- [ ] If this PR touches configuration, this is backwards compatible
with settings back to v2025.3.2
- [ ] If this PR touches pipeline settings or anything related to data
exchange, the frontend typing is updated
- [ ] If this PR addresses a bug, a regression test for it is added
2025-11-13 16:07:33 -05:00

2.9 KiB

Aiming at a Target

The following example is from the PhotonLib example repository (Java).

Knowledge and Equipment Needed

  • A Robot
  • A camera mounted rigidly to the robot's frame, centered and pointed forward.
  • A coprocessor running PhotonVision with an AprilTag or ArUco 2D Pipeline.
  • A printout of AprilTag 7, mounted on a rigid and flat surface.

Code

Now that you have properly set up your vision system and have tuned a pipeline, you can now aim your robot at an AprilTag using the data from PhotonVision. The yaw of the target is the critical piece of data that will be needed first.

Yaw is reported to the roboRIO over Network Tables. PhotonLib, our vendor dependency, is the easiest way to access this data. The documentation for the Network Tables API can be found {ref}here <docs/additional-resources/nt-api:Getting Target Information> and the documentation for PhotonLib {ref}here <docs/programming/photonlib/adding-vendordep:What is PhotonLib?>.

In this example, while the operator holds a button down, the robot will turn towards the AprilTag using the P term of a PID loop. To learn more about how PID loops work, how WPILib implements them, and more, visit Advanced Controls (PID) and PID Control in WPILib.

.. tab-set::
    :sync-group: code

    .. tab-item:: Java
       :sync: java

       .. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-java-examples/aimattarget/src/main/java/frc/robot/Robot.java
         :language: java
         :lines: 77-117
         :linenos:
         :lineno-start: 77

    .. tab-item:: C++ (Header)
       :sync: c++

       .. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-cpp-examples/aimattarget/src/main/include/Robot.h
         :language: c++
         :lines: 25-60
         :linenos:
         :lineno-start: 25

    .. tab-item:: C++ (Source)
       :sync: c++

       .. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-cpp-examples/aimattarget/src/main/cpp/Robot.cpp
         :language: c++
         :lines: 56-96
         :linenos:
         :lineno-start: 56

    .. tab-item:: Python
       :sync: python

       .. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-python-examples/aimattarget/robot.py
         :language: python
         :lines: 46-70
         :linenos:
         :lineno-start: 46