Skip to content

Commit 7f0aa13

Browse files
FieldViewWidget sends over data for manual turret aim location
1 parent 44ec342 commit 7f0aa13

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

dash.conf846

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"key" : "SmartDashboard/HubAim",
118118
"type" : "hubaim",
119119
"title" : "HubAim",
120-
"col" : 2,
120+
"col" : 0,
121121
"row" : 0
122122
} ]
123-
}
123+
}

src/main/java/com/funkylogclient/FieldViewWidget.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import java.util.List;
1919
import java.util.Map;
2020
import java.util.HashMap;
21+
import edu.wpi.first.networktables.NetworkTableEntry;
22+
import edu.wpi.first.networktables.NetworkTableInstance;
23+
import edu.wpi.first.networktables.NetworkTable;
2124

2225
class Pose2D {
2326
double x;
@@ -81,6 +84,17 @@ public int getColSpan() {
8184
public int getRowSpan() {
8285
return (fieldRotationIndex % 2 != 0) ? 4 : 3;
8386
}
87+
private void collectMouseCoords()
88+
{
89+
canvasPane.setOnMouseDragged(event -> {
90+
double xRatio = canvasPane.getWidth()/fieldImage.getWidth();
91+
double yRatio = canvasPane.getHeight()/fieldImage.getHeight();
92+
double x_dist = xRatio * 651.22 * event.getX() / canvasPane.getWidth(); // x dist in inches
93+
double y_dist = yRatio * 317.69 * event.getY() / canvasPane.getHeight(); // y dist in inches
94+
95+
writeCoordinateBack(new double[]{x_dist, y_dist});
96+
});
97+
}
8498

8599
private void createFieldView() {
86100
contentBox.setStyle("-fx-background-color: #0D0D0D; -fx-background-radius: 0 0 8 8;");
@@ -173,7 +187,7 @@ public void handle(long now) {
173187
displayX = lastPose.x + dx * extrapolationTime;
174188
displayY = lastPose.y + dy * extrapolationTime;
175189
displayRotation = lastPose.rotation + dtheta * extrapolationTime;
176-
190+
177191
while (displayRotation > Math.PI)
178192
displayRotation -= 2 * Math.PI;
179193
while (displayRotation < -Math.PI)
@@ -257,6 +271,7 @@ private void redrawBackground() {
257271
}
258272

259273
private void redrawDynamicContent() {
274+
collectMouseCoords();
260275
double cw = foregroundCanvas.getWidth();
261276
double ch = foregroundCanvas.getHeight();
262277
if (cw <= 0 || ch <= 0) return;
@@ -271,6 +286,7 @@ private void redrawDynamicContent() {
271286
fieldH = cw;
272287
}
273288

289+
274290
gcForeground.translate(cw / 2, ch / 2);
275291
gcForeground.rotate(fieldRotationIndex * 90);
276292
gcForeground.translate(-fieldW / 2, -fieldH / 2);
@@ -482,6 +498,11 @@ public void setRemoveCallback(Runnable callback) {
482498
this.removeCallback = callback;
483499
}
484500

501+
@Override
502+
public void setDisabled(boolean disabled) {
503+
super.setDisabled(false);
504+
}
505+
485506
@Override
486507
public void updateValue(Object value) {
487508
double newX = robotX;
@@ -547,6 +568,27 @@ public void updateValue(Object value) {
547568
displayRotation = newRotation;
548569
}
549570

571+
private void writeCoordinateBack(double[] distance)
572+
{
573+
try
574+
{
575+
NetworkTableInstance instance = NetworkTableInstance.getDefault();
576+
NetworkTable prefs = instance.getTable("Preferences");
577+
NetworkTable location = prefs.getSubTable("location");
578+
579+
location.getEntry("x_location").setDouble(distance[0]);
580+
location.getEntry("y_location").setDouble(distance[1]);
581+
582+
System.out.println("X location in inches" + distance[0]);
583+
System.out.println("Y location in inches" + distance[1]);
584+
585+
}
586+
catch (Exception e)
587+
{
588+
System.err.println("Ntables did not work" + e.getMessage());
589+
}
590+
}
591+
550592
@Override
551593
public Node getContent() {
552594
return container;
636 Bytes
Loading

0 commit comments

Comments
 (0)