Skip to content

Commit

Permalink
Make SimpleNote serializable for AScope (#280)
Browse files Browse the repository at this point in the history
* Make SimpleNote serializable for AScope

* Remove unintended import

---------

Co-authored-by: Alex Schokking <[email protected]>
  • Loading branch information
stephenjust and aschokking authored Mar 30, 2024
1 parent 108ef70 commit 3c15c1c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/main/java/competition/subsystems/vision/SimpleNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class SimpleNote implements StructSerializable {
final double yaw;
final double pitch;

public static final SimpleNoteStruct struct = new SimpleNoteStruct();

public SimpleNote(double area, double yaw, double pitch) {
this.area = area;
this.yaw = yaw;
Expand All @@ -21,5 +23,7 @@ public double getYaw() {
return yaw;
}

public double getPitch() { return pitch; }
public double getPitch() {
return pitch;
}
}
42 changes: 42 additions & 0 deletions src/main/java/competition/subsystems/vision/SimpleNoteStruct.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package competition.subsystems.vision;

import edu.wpi.first.util.struct.Struct;

import java.nio.ByteBuffer;

public class SimpleNoteStruct implements Struct<SimpleNote> {
@Override
public Class<SimpleNote> getTypeClass() {
return SimpleNote.class;
}

@Override
public String getTypeString() {
return "struct:SimpleNote";
}

@Override
public int getSize() {
return kSizeDouble * 3;
}

@Override
public String getSchema() {
return "double area; double yaw; double pitch";
}

@Override
public SimpleNote unpack(ByteBuffer byteBuffer) {
var area = byteBuffer.getDouble();
var yaw = byteBuffer.getDouble();
var pitch = byteBuffer.getDouble();
return new SimpleNote(area, yaw, pitch);
}

@Override
public void pack(ByteBuffer byteBuffer, SimpleNote simpleNote) {
byteBuffer.putDouble(simpleNote.getArea());
byteBuffer.putDouble(simpleNote.getYaw());
byteBuffer.putDouble(simpleNote.getPitch());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ public void periodic() {
}, () -> {
aKitLog.record("CenterCamLargestTargetArea", -1.0);
aKitLog.record("CenterCamLargestTargetYaw", 0.0);
aKitLog.record("CenterCamLargestTargetPitch", 0);
aKitLog.record("CenterCamLargestTargetPitch", 0.0);
});

// aKitLog.record("CenterlineDetections", centerlineDetections);
aKitLog.record("CenterlineDetections", centerlineDetections);
aKitLog.record("DetectedNotes", detectedNotes);
aKitLog.record("PassiveDetectedNotes", passiveDetectedNotes);
}
Expand Down

0 comments on commit 3c15c1c

Please sign in to comment.