Files
PhotonVision/docs/source/docs/examples/aimandrange.md

56 lines
2.2 KiB
Markdown
Raw Normal View History

# Combining Aiming and Getting in Range
2024-06-30 16:10:12 -04:00
The following example is from the PhotonLib example repository ([Java](https://github.com/PhotonVision/photonvision/tree/main/photonlib-java-examples/aimandrange)/[C++](https://github.com/PhotonVision/photonvision/tree/main/photonlib-cpp-examples/aimandrange)/[Python](https://github.com/PhotonVision/photonvision/tree/main/photonlib-python-examples/aimandrange))
2024-06-30 16:10:12 -04:00
## Knowledge and Equipment Needed
2024-06-30 16:10:12 -04:00
2024-09-14 23:10:02 -05:00
- Everything required in {ref}`Aiming at a Target <docs/examples/aimingatatarget:Knowledge and Equipment Needed>`.
2024-06-30 16:10:12 -04:00
## Code
2024-06-30 16:10:12 -04:00
2024-09-14 23:10:02 -05:00
Now that you know how to aim toward the AprilTag, let's also drive the correct distance from the AprilTag.
To do this, we'll use the _pitch_ of the target in the camera image and trigonometry to figure out how far away the robot is from the AprilTag. Then, like before, we'll use the P term of a PID controller to drive the robot to the correct distance.
2024-06-30 16:10:12 -04:00
```{eval-rst}
2024-06-30 16:10:12 -04:00
.. tab-set::
:sync-group: code
2024-06-30 16:10:12 -04:00
.. tab-item:: Java
:sync: java
2024-06-30 16:10:12 -04:00
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-java-examples/aimandrange/src/main/java/frc/robot/Robot.java
2024-06-30 16:10:12 -04:00
:language: java
2024-09-14 23:10:02 -05:00
:lines: 84-131
2024-06-30 16:10:12 -04:00
:linenos:
2024-09-14 23:10:02 -05:00
:lineno-start: 84
2024-06-30 16:10:12 -04:00
.. tab-item:: C++ (Header)
:sync: c++
2024-06-30 16:10:12 -04:00
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-cpp-examples/aimandrange/src/main/include/Robot.h
2024-09-14 23:10:02 -05:00
:language: c++
:lines: 25-63
2024-06-30 16:10:12 -04:00
:linenos:
2024-09-14 23:10:02 -05:00
:lineno-start: 25
2024-06-30 16:10:12 -04:00
.. tab-item:: C++ (Source)
:sync: c++
2024-06-30 16:10:12 -04:00
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-cpp-examples/aimandrange/src/main/cpp/Robot.cpp
2024-09-14 23:10:02 -05:00
:language: c++
:lines: 58-107
2024-06-30 16:10:12 -04:00
:linenos:
2024-09-14 23:10:02 -05:00
:lineno-start: 58
.. tab-item:: Python
:sync: python
2024-09-14 23:10:02 -05:00
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/abe95dfaa055bbe3609f72cfcaaba0f96ee7978c/photonlib-python-examples/aimandrange/robot.py
2024-09-14 23:10:02 -05:00
:language: python
:lines: 52-91
2024-09-14 23:10:02 -05:00
:linenos:
:lineno-start: 52
2024-09-14 23:10:02 -05:00
```