Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Java Simulation Examples #913

Merged
merged 53 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4c2aa16
optional pnp results, pnp method simplification
amquake Jun 20, 2023
209e184
solvepnp docs clarification
amquake Jun 20, 2023
b4a0c90
spotless
amquake Jun 20, 2023
1511b2a
fix local tag image loading
amquake Jun 27, 2023
5be4557
solvepnp square NaN retry
amquake Jul 1, 2023
c9d2f1e
spotless
amquake Jul 1, 2023
2ea3453
Merge branch 'master' into 742-robustness
mcm001 Jul 3, 2023
c7cc564
Merge branch 'master' into 742-robustness
amquake Jul 23, 2023
6b22823
use condition in result instead of Optional
amquake Jul 23, 2023
4364ac2
publish sim intrinsics/distortion to camera
amquake Jul 23, 2023
1f03b96
spotless
amquake Jul 23, 2023
ca49c23
Merge branch 'master' of https://github.com/PhotonVision/photonvision…
amquake Aug 13, 2023
2e851a0
remember to commit, me
amquake Aug 13, 2023
a6eec79
spotless
amquake Aug 13, 2023
c270828
fix tests using target yaw/pitch
amquake Aug 13, 2023
423712b
spotless
amquake Aug 13, 2023
c15f784
fix culled polygons joining, video sim tweaks
amquake Aug 14, 2023
61b037d
dont do SQPNP on non-tag targets
amquake Aug 14, 2023
e8a0820
non-square target points bugfix
amquake Aug 14, 2023
08bc306
cuboid target model
amquake Aug 15, 2023
bb1b8a4
standardize image operations on Point class
amquake Aug 15, 2023
a084abc
spotless
amquake Aug 15, 2023
8885514
draw minarearect
amquake Aug 15, 2023
24bf9ff
update apriltag example
amquake Aug 15, 2023
76eb0f3
oops
amquake Aug 15, 2023
74f1582
fix calculated center pt
amquake Aug 19, 2023
4c99b78
revert docs note
amquake Aug 19, 2023
8f1eb32
update wireframe dimensions
amquake Aug 22, 2023
dc5d12c
Merge branch 'master' into sim-draw-targets
amquake Sep 9, 2023
c9a3a67
init
amquake Sep 9, 2023
b266946
swervedriveposeestsim
amquake Sep 19, 2023
d0578f5
Update build.gradle
amquake Sep 19, 2023
675baca
dont use java17 random
amquake Sep 19, 2023
a3a3cbf
remove apriltagExample and simposeest
amquake Sep 19, 2023
5c96577
remove unused stubs
amquake Sep 19, 2023
599a6d9
Update simaimandrange
amquake Sep 19, 2023
c33e806
swervedriveposeestsim keyboard control
amquake Sep 19, 2023
02318be
Merge branch 'PhotonVision:master' into update-sim-examples
amquake Sep 19, 2023
d0f02ec
Create java-examples README.md
amquake Sep 19, 2023
e243cfe
hide keyboard settings
amquake Sep 19, 2023
c57370e
Revert "hide keyboard settings"
amquake Sep 19, 2023
5b41657
avoid sticky field objects
amquake Sep 19, 2023
fcdf6f2
dont display target estimations with empty transforms
amquake Sep 19, 2023
dd37fe7
Update examples.txt
amquake Sep 19, 2023
aa521d3
spotless
amquake Sep 19, 2023
3a3624a
wpiformat
amquake Sep 19, 2023
2a6fa1b
Merge branch 'master' into update-sim-examples
amquake Sep 20, 2023
ed6aa15
Switch example build to search for folder names lol
mcm001 Sep 23, 2023
31e32b6
Merge branch 'master' into update-sim-examples
mcm001 Sep 23, 2023
fb081ef
Probably fix examples CI
mcm001 Sep 24, 2023
c8f6f5b
Run wpiformat
mcm001 Sep 24, 2023
1eb5b37
link example build instructions
amquake Sep 24, 2023
3bc624c
example backlinks to index readme
amquake Sep 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class VisionSystemSim {

private final Field2d dbgField;

private final Transform3d kEmptyTrf = new Transform3d();

/**
* A simulated vision system involving a camera(s) and coprocessor(s) mounted on a mobile robot
* running PhotonVision, detecting targets placed on the field. {@link VisionTargetSim}s added to
Expand Down Expand Up @@ -337,7 +339,7 @@ public Field2d getDebugField() {
* Periodic update. Ensure this is called repeatedly-- camera performance is used to automatically
* determine if a new frame should be submitted.
*
* @param robotPoseMeters The current robot pose in meters
* @param robotPoseMeters The simulated robot pose in meters
*/
public void update(Pose2d robotPoseMeters) {
update(new Pose3d(robotPoseMeters));
Expand All @@ -347,7 +349,7 @@ public void update(Pose2d robotPoseMeters) {
* Periodic update. Ensure this is called repeatedly-- camera performance is used to automatically
* determine if a new frame should be submitted.
*
* @param robotPoseMeters The current robot pose in meters
* @param robotPoseMeters The simulated robot pose in meters
*/
public void update(Pose3d robotPoseMeters) {
var targetTypes = targetSets.entrySet();
Expand All @@ -370,13 +372,15 @@ public void update(Pose3d robotPoseMeters) {

var allTargets = new ArrayList<VisionTargetSim>();
targetTypes.forEach((entry) -> allTargets.addAll(entry.getValue()));
var visibleTargets = new ArrayList<Pose3d>();
var cameraPose2ds = new ArrayList<Pose2d>();
var visTgtPoses2d = new ArrayList<Pose2d>();
var cameraPoses2d = new ArrayList<Pose2d>();
boolean processed = false;
// process each camera
for (var camSim : camSimMap.values()) {
// check if this camera is ready to process and get latency
var optTimestamp = camSim.consumeNextEntryTime();
if (optTimestamp.isEmpty()) continue;
else processed = true;
// when this result "was" read by NT
long timestampNT = optTimestamp.get();
// this result's processing latency in milliseconds
Expand All @@ -387,22 +391,20 @@ public void update(Pose3d robotPoseMeters) {
// use camera pose from the image capture timestamp
Pose3d lateRobotPose = getRobotPose(timestampCapture);
Pose3d lateCameraPose = lateRobotPose.plus(getRobotToCamera(camSim, timestampCapture).get());
cameraPose2ds.add(lateCameraPose.toPose2d());
cameraPoses2d.add(lateCameraPose.toPose2d());

// process a PhotonPipelineResult with visible targets
var camResult = camSim.process(latencyMillis, lateCameraPose, allTargets);
// publish this info to NT at estimated timestamp of receive
camSim.submitProcessedFrame(camResult, timestampNT);
// display debug results
for (var target : camResult.getTargets()) {
visibleTargets.add(lateCameraPose.transformBy(target.getBestCameraToTarget()));
var trf = target.getBestCameraToTarget();
if (trf.equals(kEmptyTrf)) continue;
visTgtPoses2d.add(lateCameraPose.transformBy(trf).toPose2d());
}
}
if (visibleTargets.size() != 0) {
dbgField
.getObject("visibleTargetPoses")
.setPoses(visibleTargets.stream().map(Pose3d::toPose2d).collect(Collectors.toList()));
}
if (cameraPose2ds.size() != 0) dbgField.getObject("cameras").setPoses(cameraPose2ds);
if (processed) dbgField.getObject("visibleTargetPoses").setPoses(visTgtPoses2d);
if (cameraPoses2d.size() != 0) dbgField.getObject("cameras").setPoses(cameraPoses2d);
}
}
7 changes: 7 additions & 0 deletions photonlib-cpp-examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## PhotonLib C++ Examples

### Running examples

For instructions on how to run these examples locally, see [Running Examples](https://docs.photonvision.org/en/latest/docs/contributing/photonvision/build-instructions.html#running-examples).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For docs PR: this list will need to be updated
image


---
4 changes: 3 additions & 1 deletion photonlib-cpp-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ spotless {
}
}

apply from: "examples.gradle"

// Task that depends on the build task for every example
task buildAllExamples { task ->
new File('examples.txt').eachLine { line ->
exampleFolderNames.each { line ->
task.dependsOn(line + ":build")
}
}
14 changes: 14 additions & 0 deletions photonlib-cpp-examples/examples.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// These should be the only 2 non-project subdirectories in the examples folder
// I could check for (it)/build.gradle to exist, but w/e
def EXCLUDED_DIRS = ["bin", "build"]

// List all non-hidden directories not in EXCUDED_DIRS
ext.exampleFolderNames = file("${rootDir}")
.listFiles()
.findAll {
return (it.isDirectory()
&& !it.isHidden()
&& !(it.name in EXCLUDED_DIRS) && !it.name.startsWith(".")
&& it.toPath().resolve("build.gradle").toFile().exists())
}
.collect { it.name }
4 changes: 0 additions & 4 deletions photonlib-cpp-examples/examples.txt

This file was deleted.

4 changes: 3 additions & 1 deletion photonlib-cpp-examples/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
new File('examples.txt').eachLine { line -> include line }
apply from: "examples.gradle"

exampleFolderNames.each { line -> include line }
53 changes: 53 additions & 0 deletions photonlib-java-examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## PhotonLib Java Examples

### Running examples

For instructions on how to run these examples locally, see [Running Examples](https://docs.photonvision.org/en/latest/docs/contributing/photonvision/build-instructions.html#running-examples).

---

### [**`aimattarget`**](aimattarget)

A simple demonstration of using PhotonVision's 2d target yaw to align a differential drivetrain with a target.

---

### [**`getinrange`**](getinrange)

A simple demonstration of using PhotonVision's 2d target pitch to bring a differential drivetrain to a specific distance from a target.

---

### [**`aimandrange`**](aimandrange)

A combination of the previous `aimattarget` and `getinrange` examples to simultaneously aim and get in range of a target.

---

### [**`simaimandrange`**](simaimandrange)

The above `aimandrange` example with simulation support.

<img src="https://github-production-user-asset-6210df.s3.amazonaws.com/7953350/268856085-432a54b9-f596-4e30-8b57-a8f38f88f985.png" width=60% height=60%>

**Keyboard controls:**
- Drive forward/backward: W/S
- Turn left/right: A/D
- Perform vision alignment: Z

---

### [**`swervedriveposeestsim`**](swervedriveposeestsim)

A minimal swerve drive example demonstrating the usage of PhotonVision for AprilTag vision estimation with a swerve drive pose estimator.

The example also has simulation support with an approximation of swerve drive dynamics.

<img src="https://github-production-user-asset-6210df.s3.amazonaws.com/7953350/268862944-3392e69a-7705-4dbc-9eb8-0d03a6e27b9e.png" width=60% height=60%>

<img src="https://github-production-user-asset-6210df.s3.amazonaws.com/7953350/268857280-bae145b8-356e-4afb-b842-597dbea60df6.png" width=60% height=60%>

**Keyboard controls:**
- Translate field-relative: WASD
- Rotate counter/clockwise: Q/E
- Offset pose estimate: X
3 changes: 3 additions & 0 deletions photonlib-java-examples/aimandrange/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## **`aimandrange`**

### See [PhotonLib Java Examples](./README.md#aimandrange)
3 changes: 3 additions & 0 deletions photonlib-java-examples/aimattarget/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## **`aimattarget`**

### See [PhotonLib Java Examples](./README.md#aimattarget)

This file was deleted.

94 changes: 0 additions & 94 deletions photonlib-java-examples/apriltagExample/build.gradle

This file was deleted.

104 changes: 0 additions & 104 deletions photonlib-java-examples/apriltagExample/simgui-ds.json

This file was deleted.

Loading