Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
62 changes: 36 additions & 26 deletions src/com/libKudos254/Rotation2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,44 @@
/**
* A rotation in a 2d coordinate frame represented a point on the unit circle
* (cosine and sine).
*
* <p/>
* Inspired by Sophus (https://github.com/strasdat/Sophus/tree/master/sophus)
*/
public class Rotation2d {
protected static final double kEpsilon = 1E-9;

protected double cos_angle_;
protected double sin_angle_;
protected double cosAngle;
protected double sinAngle;

public Rotation2d() {
this(1, 0, false);
}

public Rotation2d(double x, double y, boolean normalize) {
cos_angle_ = x;
sin_angle_ = y;
/**
* Constructor for Rotation2d object.
* @param cos sets cosAngle
* @param sin sets sinAngle
* @param normalize runs normalize() if true
*/
public Rotation2d(double cos, double sin, boolean normalize) {
cosAngle = cos;
sinAngle = sin;
if (normalize) {
normalize();
}
}

public Rotation2d(Rotation2d other) {
cos_angle_ = other.cos_angle_;
sin_angle_ = other.sin_angle_;
cosAngle = other.cosAngle;
sinAngle = other.sinAngle;
}

public static Rotation2d fromRadians(double angle_radians) {
return new Rotation2d(Math.cos(angle_radians), Math.sin(angle_radians), false);
public static Rotation2d fromRadians(double angleRadians) {
return new Rotation2d(Math.cos(angleRadians), Math.sin(angleRadians), false);
}

public static Rotation2d fromDegrees(double angle_degrees) {
return fromRadians(Math.toRadians(angle_degrees));
public static Rotation2d fromDegrees(double angleDegrees) {
return fromRadians(Math.toRadians(angleDegrees));
}

/**
Expand All @@ -45,37 +51,41 @@ public static Rotation2d fromDegrees(double angle_degrees) {
* re-scale the sin and cos to reset rounding errors.
*/
public void normalize() {
double magnitude = Math.hypot(cos_angle_, sin_angle_);
double magnitude = Math.hypot(cosAngle, sinAngle);
if (magnitude > kEpsilon) {
sin_angle_ /= magnitude;
cos_angle_ /= magnitude;
sinAngle /= magnitude;
cosAngle /= magnitude;
} else {
sin_angle_ = 0;
cos_angle_ = 1;
sinAngle = 0;
cosAngle = 1;
}
}

public double cos() {
return cos_angle_;
return cosAngle;
}

public double sin() {
return sin_angle_;
return sinAngle;
}

/**
* Returns the tangent of an angle.
* @return returns the tangent
*/
public double tan() {
if (cos_angle_ < kEpsilon) {
if (sin_angle_ >= 0.0) {
if (cosAngle < kEpsilon) {
if (sinAngle >= 0.0) {
return Double.POSITIVE_INFINITY;
} else {
return Double.NEGATIVE_INFINITY;
}
}
return sin_angle_ / cos_angle_;
return sinAngle / cosAngle;
}

public double getRadians() {
return Math.atan2(sin_angle_, cos_angle_);
return Math.atan2(sinAngle, cosAngle);
}

public double getDegrees() {
Expand All @@ -92,8 +102,8 @@ public double getDegrees() {
* @return This rotation rotated by other.
*/
public Rotation2d rotateBy(Rotation2d other) {
return new Rotation2d(cos_angle_ * other.cos_angle_ - sin_angle_ * other.sin_angle_,
cos_angle_ * other.sin_angle_ + sin_angle_ * other.cos_angle_, true);
return new Rotation2d(cosAngle * other.cosAngle - sinAngle * other.sinAngle,
cosAngle * other.sinAngle + sinAngle * other.cosAngle, true);
}

/**
Expand All @@ -102,7 +112,7 @@ public Rotation2d rotateBy(Rotation2d other) {
* @return The opposite of this rotation.
*/
public Rotation2d inverse() {
return new Rotation2d(cos_angle_, -sin_angle_, false);
return new Rotation2d(cosAngle, -sinAngle, false);
}

@Override
Expand Down
122 changes: 65 additions & 57 deletions src/com/libKudos254/vision/AdbBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,82 @@
/**
* AdbBridge interfaces to an Android Debug Bridge (adb) binary, which is needed
* to communicate to Android devices over USB.
*
* <p/>
* adb binary provided by https://github.com/Spectrum3847/RIOdroid
*/
public class AdbBridge {
Path bin_location_;
public final static Path DEFAULT_LOCATION = Paths.get("/usr/bin/adb");
Path binLocation;
public static final Path DEFAULT_LOCATION = Paths.get("/usr/bin/adb");

public AdbBridge() {
Path adb_location;
String env_val = System.getenv("FRC_ADB_LOCATION");
if (env_val == null || "".equals(env_val)) {
adb_location = DEFAULT_LOCATION;
} else {
adb_location = Paths.get(env_val);
}
bin_location_ = adb_location;
/**
* Constructor for AdBridge.
*/
public AdbBridge() {
Path adbLocation;
String envVal = System.getenv("FRC_adbLocation");
if (envVal == null || "".equals(envVal)) {
adbLocation = DEFAULT_LOCATION;
} else {
adbLocation = Paths.get(envVal);
}
binLocation = adbLocation;
}

public AdbBridge(Path location) {
bin_location_ = location;
}

private boolean runCommand(String args) {
Runtime r = Runtime.getRuntime();
String cmd = bin_location_.toString() + " " + args;
public AdbBridge(Path location) {
binLocation = location;
}

try {
Process p = r.exec(cmd);
p.waitFor();
} catch (IOException e) {
System.err.println("AdbBridge: Could not run command " + cmd);
e.printStackTrace();
return false;
} catch (InterruptedException e) {
System.err.println("AdbBridge: Could not run command " + cmd);
e.printStackTrace();
return false;
}
return true;
private boolean runCommand(String args) {
Runtime run = Runtime.getRuntime();
String cmd = binLocation.toString() + " " + args;
try {
Process proc = run.exec(cmd);
proc.waitFor();
} catch (IOException exc) {
System.err.println("AdbBridge: Could not run command " + cmd);
exc.printStackTrace();
return false;
} catch (InterruptedException exc) {
System.err.println("AdbBridge: Could not run command " + cmd);
exc.printStackTrace();
return false;
}
return true;
}

public void start() {
System.out.println("Starting adb");
runCommand("start");
}

public void start() {
System.out.println("Starting adb");
runCommand("start");
}
public void stop() {
System.out.println("Stopping adb");
runCommand("kill-server");
}

public void stop() {
System.out.println("Stopping adb");
runCommand("kill-server");
}
/**
* Stops and starts the adb, restarting it.
*/
public void restartAdb() {
System.out.println("Restarting adb");
stop();
start();
}

public void restartAdb() {
System.out.println("Restarting adb");
stop();
start();
}
public void portForward(int localPort, int remotePort) {
runCommand("forward tcp:" + localPort + " tcp:" + remotePort);
}

public void portForward(int local_port, int remote_port) {
runCommand("forward tcp:" + local_port + " tcp:" + remote_port);
}

public void reversePortForward(int remote_port, int local_port) {
runCommand("reverse tcp:" + remote_port + " tcp:" + local_port);
}
public void reversePortForward(int remotePort, int localPort) {
runCommand("reverse tcp:" + remotePort + " tcp:" + localPort);
}

public void restartApp() {
System.out.println("Restarting app");
runCommand("shell am force-stop com.team254.cheezdroid \\; "
+ "am start com.team254.cheezdroid/com.team254.cheezdroid.VisionTrackerActivity");
}
/**
* Restarts the app.
*/
public void restartApp() {
System.out.println("Restarting app");
runCommand("shell am force-stop com.team254.cheezdroid \\; "
+ "am start com.team254.cheezdroid/com.team254.cheezdroid.VisionTrackerActivity");
}
}
15 changes: 9 additions & 6 deletions src/com/libKudos254/vision/CrashTracker.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.libKudos254.vision;

import java.io.*;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.UUID;

/**
* Tracks start-up and caught crash events, logging them to a file which dosn't
* roll over
* Tracks start-up and caught crash events, logging them to a file which doesn't
* roll over.
*/
public class CrashTracker {

Expand Down Expand Up @@ -46,7 +48,8 @@ private static void logMarker(String mark) {

private static void logMarker(String mark, Throwable nullableException) {

try (PrintWriter writer = new PrintWriter(new FileWriter("/home/lvuser/crash_tracking.txt", true))) {
try (PrintWriter writer = new PrintWriter(
new FileWriter("/home/lvuser/crash_tracking.txt", true))) {
writer.print(RUN_INSTANCE_UUID.toString());
writer.print(", ");
writer.print(mark);
Expand All @@ -59,8 +62,8 @@ private static void logMarker(String mark, Throwable nullableException) {
}

writer.println();
} catch (IOException e) {
e.printStackTrace();
} catch (IOException exc) {
exc.printStackTrace();
}
}
}
8 changes: 4 additions & 4 deletions src/com/libKudos254/vision/CrashTrackingRunnable.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.libKudos254.vision;

/**
* Runnable class with reports all uncaught throws to CrashTracker
* Runnable class with reports all uncaught throws to CrashTracker.
*/
public abstract class CrashTrackingRunnable implements Runnable {

@Override
public final void run() {
try {
runCrashTracked();
} catch (Throwable t) {
CrashTracker.logThrowableCrash(t);
throw t;
} catch (Throwable exc) {
CrashTracker.logThrowableCrash(exc);
throw exc;
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/com/libKudos254/vision/TargetInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
* location in three-dimensional space.
*/
public class TargetInfo {
protected double x = 1.0;
protected double y;
protected double z;
protected double horizantalAxis = 1.0;
protected double verticalAxis;
protected double depthAxis;

public TargetInfo(double y, double z) {
this.y = y;
this.z = z;
}
public TargetInfo(double verticalAxis, double depthAxis) {
this.verticalAxis = verticalAxis;
this.depthAxis = depthAxis;
}

public double getX() {
return x;
}
public double getX() {
return horizantalAxis;
}

public double getY() {
return y;
}
public double getY() {
return verticalAxis;
}

public double getZ() {
return z;
}
public double getZ() {
return depthAxis;
}
}
Loading