Skip to content

Commit 9e6a066

Browse files
authored
Examples Clean-Up (#1408)
1 parent 596c875 commit 9e6a066

File tree

269 files changed

+9342
-3730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+9342
-3730
lines changed

docs/source/docs/additional-resources/best-practices.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
- Make sure you take advantage of the field calibration time given at the start of the event:
1616
- Bring your robot to the field at the allotted time.
1717
- Turn on your robot and pull up the dashboard on your driver station.
18-
- Point your robot at the target(s) and ensure you get a consistent tracking (you hold one target consistently, the ceiling lights aren't detected, etc.).
19-
- If you have problems with your pipeline, go to the pipeline tuning section and retune the pipeline using the guide there. You want to make your exposure as low as possible with a tight hue value to ensure no extra targets are detected.
20-
- Move the robot close, far, angled, and around the field to ensure no extra targets are found anywhere when looking for a target.
18+
- Point your robot at the AprilTags(s) and ensure you get a consistent tracking (you hold one AprilTag consistently, the ceiling lights aren't detected, etc.).
19+
- If you have problems with your pipeline, go to the pipeline tuning section and retune the pipeline using the guide there.
20+
- Move the robot close, far, angled, and around the field to ensure no extra AprilTags are found.
2121
- Go to a practice match to ensure everything is working correctly.
2222
- After field calibration, use the "Export Settings" button in the "Settings" page to create a backup.
2323
- Do this for each coprocessor on your robot that runs PhotonVision, and name your exports with meaningful names.
@@ -26,4 +26,4 @@
2626
- This effectively works as a snapshot of your PhotonVision data that can be restored at any point.
2727
- Before every match, check the ethernet connection going into your coprocessor and that it is seated fully.
2828
- Ensure that exposure is as low as possible and that you don't have the dashboard up when you don't need it to reduce bandwidth.
29-
- Stream at as low of a resolution as possible while still detecting targets to stay within bandwidth limits.
29+
- Stream at as low of a resolution as possible while still detecting AprilTags to stay within field bandwidth limits.

docs/source/docs/apriltag-pipelines/multitag.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This multi-target pose estimate can be accessed using PhotonLib. We suggest usin
2424
```{eval-rst}
2525
.. tab-set-code::
2626
27-
.. code-block:: java
27+
.. code-block:: Java
2828
2929
var result = camera.getLatestResult();
3030
if (result.getMultiTagResult().estimatedPose.isPresent) {
@@ -38,6 +38,11 @@ This multi-target pose estimate can be accessed using PhotonLib. We suggest usin
3838
if (result.MultiTagResult().result.isPresent) {
3939
frc::Transform3d fieldToCamera = result.MultiTagResult().result.best;
4040
}
41+
42+
.. code-block:: Python
43+
44+
# Coming Soon!
45+
4146
```
4247

4348
:::{note}

docs/source/docs/contributing/building-photon.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,11 @@ The program will wait for the VSCode debugger to attach before proceeding.
243243

244244
### Running examples
245245

246-
You can run one of the many built in examples straight from the command line, too! They contain a fully featured robot project, and some include simulation support. The projects can be found inside the photonlib-java-examples and photonlib-cpp-examples subdirectories, respectively. The projects currently available include:
246+
You can run one of the many built in examples straight from the command line, too! They contain a fully featured robot project, and some include simulation support. The projects can be found inside the photonlib-*-examples subdirectories for each language.
247247

248-
- photonlib-java-examples:
249-
- aimandrange:simulateJava
250-
- aimattarget:simulateJava
251-
- getinrange:simulateJava
252-
- simaimandrange:simulateJava
253-
- simposeest:simulateJava
254-
- photonlib-cpp-examples:
255-
- aimandrange:simulateNative
256-
- getinrange:simulateNative
248+
#### Running C++/Java
257249

258-
To run them, use the commands listed below. PhotonLib must first be published to your local maven repository, then the copy PhotonLib task will copy the generated vendordep json file into each example. After that, the simulateJava/simulateNative task can be used like a normal robot project. Robot simulation with attached debugger is technically possible by using simulateExternalJava and modifying the launch script it exports, though unsupported.
250+
PhotonLib must first be published to your local maven repository, then the copy PhotonLib task will copy the generated vendordep json file into each example. After that, the simulateJava/simulateNative task can be used like a normal robot project. Robot simulation with attached debugger is technically possible by using simulateExternalJava and modifying the launch script it exports, though not yet supported.
259251

260252
```
261253
~/photonvision$ ./gradlew publishToMavenLocal
@@ -268,3 +260,27 @@ To run them, use the commands listed below. PhotonLib must first be published to
268260
~/photonvision/photonlib-cpp-examples$ ./gradlew copyPhotonlib
269261
~/photonvision/photonlib-cpp-examples$ ./gradlew <example-name>:simulateNative
270262
```
263+
264+
#### Running Python
265+
266+
PhotonLibPy must first be built into a wheel.
267+
268+
```
269+
> cd photon-lib/py
270+
> buildAndTest.bat
271+
```
272+
273+
Then, you must enable using the development wheels. robotpy will use pip behind the scenes, and this bat file tells pip about your development artifacts.
274+
275+
Note: This is best done in a virtual environment.
276+
277+
```
278+
> enableUsingDevBuilds.bat
279+
```
280+
281+
Then, run the examples:
282+
283+
```
284+
> cd photonlib-python-examples
285+
> run.bat <example name>
286+
```

docs/source/docs/description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Description
44

55
PhotonVision is a free, fast, and easy-to-use vision processing solution for the *FIRST*Robotics Competition. PhotonVision is designed to get vision working on your robot *quickly*, without the significant cost of other similar solutions.
6-
Using PhotonVision, teams can go from setting up a camera and coprocessor to detecting and tracking targets by simply tuning sliders. With an easy to use interface, comprehensive documentation, and a feature rich vendor dependency, no experience is necessary to use PhotonVision. No matter your resources, using PhotonVision is easy compared to its alternatives.
6+
Using PhotonVision, teams can go from setting up a camera and coprocessor to detecting and tracking AprilTags and other targets by simply tuning sliders. With an easy to use interface, comprehensive documentation, and a feature rich vendor dependency, no experience is necessary to use PhotonVision. No matter your resources, using PhotonVision is easy compared to its alternatives.
77

88
## Advantages
99

docs/source/docs/examples/aimandrange.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,47 @@ The following example is from the PhotonLib example repository ([Java](https://g
44

55
## Knowledge and Equipment Needed
66

7-
- Everything required in {ref}`Aiming at a Target <docs/examples/aimingatatarget:Knowledge and Equipment Needed>` and {ref}`Getting in Range of the Target <docs/examples/gettinginrangeofthetarget:Knowledge and Equipment Needed>`.
7+
- Everything required in {ref}`Aiming at a Target <docs/examples/aimingatatarget:Knowledge and Equipment Needed>`.
88

99
## Code
1010

11-
Now that you know how to both aim and get in range of the target, it is time to combine them both at the same time. This example will take the previous two code examples and make them into one function using the same tools as before. With this example, you now have all the knowledge you need to use PhotonVision on your robot in any game.
11+
Now that you know how to aim toward the AprilTag, let's also drive the correct distance from the AprilTag.
12+
13+
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.
1214

1315
```{eval-rst}
1416
.. tab-set::
1517
1618
.. tab-item:: Java
1719
18-
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/ebef19af3d926cf87292177c9a16d01b71219306/photonlib-java-examples/aimandrange/src/main/java/frc/robot/Robot.java
20+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-java-examples/aimandrange/src/main/java/frc/robot/Robot.java
1921
:language: java
20-
:lines: 42-111
22+
:lines: 84-131
2123
:linenos:
22-
:lineno-start: 42
24+
:lineno-start: 84
2325
2426
.. tab-item:: C++ (Header)
2527
26-
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/ebef19af3d926cf87292177c9a16d01b71219306/photonlib-cpp-examples/aimandrange/src/main/include/Robot.h
27-
:language: cpp
28-
:lines: 27-71
28+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-cpp-examples/aimandrange/src/main/include/Robot.h
29+
:language: c++
30+
:lines: 25-63
2931
:linenos:
30-
:lineno-start: 27
32+
:lineno-start: 25
3133
3234
.. tab-item:: C++ (Source)
3335
34-
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/ebef19af3d926cf87292177c9a16d01b71219306/photonlib-cpp-examples/aimandrange/src/main/cpp/Robot.cpp
35-
:language: cpp
36-
:lines: 25-67
36+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-cpp-examples/aimandrange/src/main/cpp/Robot.cpp
37+
:language: c++
38+
:lines: 58-107
3739
:linenos:
38-
:lineno-start: 25
40+
:lineno-start: 58
41+
42+
.. tab-item:: Python
43+
44+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-python-examples/aimandrange/robot.py
45+
:language: python
46+
:lines: 44-98
47+
:linenos:
48+
:lineno-start: 44
49+
3950
```
Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,55 @@
11
# Aiming at a Target
22

3-
The following example is from the PhotonLib example repository ([Java](https://github.com/PhotonVision/photonvision/tree/master/photonlib-java-examples/aimattarget)/[C++](https://github.com/PhotonVision/photonvision/tree/master/photonlib-cpp-examples/aimattarget)).
3+
The following example is from the PhotonLib example repository ([Java](https://github.com/PhotonVision/photonvision/tree/master/photonlib-java-examples/aimattarget)).
44

55
## Knowledge and Equipment Needed
66

7-
- Robot with a vision system running PhotonVision
8-
- Target
9-
- Ability to track a target by properly tuning a pipeline
7+
- A Robot
8+
- A camera mounted rigidly to the robot's frame, cenetered and pointed forward.
9+
- A coprocessor running PhotonVision with an AprilTag or Aurco 2D Pipeline.
10+
- [A printout of Apriltag 7](https://firstfrc.blob.core.windows.net/frc2024/FieldAssets/Apriltag_Images_and_User_Guide.pdf), mounted on a rigid and flat surface.
1011

1112
## Code
1213

13-
Now that you have properly set up your vision system and have tuned a pipeline, you can now aim your robot/turret at the target using the data from PhotonVision. This data is reported over NetworkTables and includes: latency, whether there is a target detected or not, pitch, yaw, area, skew, and target pose relative to the robot. This data will be used/manipulated by our vendor dependency, PhotonLib. 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?>`.
14+
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.
1415

15-
For this simple example, only yaw is needed.
16+
Yaw is reported to the roboRIO over Network Tables. PhotonLib, our vender 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?>`.
1617

17-
In this example, while the operator holds a button down, the robot will turn towards the goal 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)](https://docs.wpilib.org/en/stable/docs/software/advanced-control/introduction/index.html) and [PID Control in WPILib](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/controllers/pidcontroller.html#pid-control-in-wpilib).
18+
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)](https://docs.wpilib.org/en/stable/docs/software/advanced-control/introduction/index.html) and [PID Control in WPILib](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/controllers/pidcontroller.html#pid-control-in-wpilib).
1819

1920
```{eval-rst}
2021
.. tab-set::
2122
2223
.. tab-item:: Java
2324
24-
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/ebef19af3d926cf87292177c9a16d01b71219306/photonlib-java-examples/aimattarget/src/main/java/frc/robot/Robot.java
25+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-java-examples/aimattarget/src/main/java/frc/robot/Robot.java
2526
:language: java
26-
:lines: 41-98
27+
:lines: 77-117
2728
:linenos:
28-
:lineno-start: 41
29+
:lineno-start: 77
2930
3031
.. tab-item:: C++ (Header)
3132
32-
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/ebef19af3d926cf87292177c9a16d01b71219306/photonlib-cpp-examples/aimattarget/src/main/include/Robot.h
33+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-cpp-examples/aimattarget/src/main/include/Robot.h
3334
:language: c++
34-
:lines: 27-53
35+
:lines: 25-60
3536
:linenos:
36-
:lineno-start: 27
37+
:lineno-start: 25
3738
3839
.. tab-item:: C++ (Source)
3940
40-
.. rli:: https://raw.githubusercontent.com/PhotonVision/photonvision/ebef19af3d926cf87292177c9a16d01b71219306/photonlib-cpp-examples/aimattarget/src/main/cpp/Robot.cpp
41+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-cpp-examples/aimattarget/src/main/cpp/Robot.cpp
4142
:language: c++
42-
:lines: 25-52
43+
:lines: 56-96
4344
:linenos:
44-
:lineno-start: 25
45+
:lineno-start: 56
46+
47+
.. tab-item:: Python
48+
49+
.. rli:: https://raw.githubusercontent.com/gerth2/photonvision/adb3098fbe0cdbc1a378c6d5a41126dd1d6d6955/photonlib-python-examples/aimattarget/robot.py
50+
:language: python
51+
:lines: 46-70
52+
:linenos:
53+
:lineno-start: 46
54+
4555
```

docs/source/docs/examples/gettinginrangeofthetarget.md

Lines changed: 0 additions & 58 deletions
This file was deleted.
24.1 MB
Loading

docs/source/docs/examples/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
:maxdepth: 1
55
66
aimingatatarget
7-
gettinginrangeofthetarget
87
aimandrange
9-
simaimandrange
10-
simposeest
8+
poseest
119
```

0 commit comments

Comments
 (0)