Skip to content

Instantly share code, notes, and snippets.

View MetalCow-Robotics's full-sized avatar

TeamAdmin MetalCow-Robotics

View GitHub Profile
@MetalCow-Robotics
MetalCow-Robotics / Unit.java
Last active August 29, 2015 14:14
Unit Class (Java implementation)
package org.metalcowrobotics.rapinterpreter;
import java.util.HashMap;
import java.util.Map;
/*
Ever wanted to add and deal with units cleanly in Java?
Well now you can!
Include this file, and do stuff like this:
@MetalCow-Robotics
MetalCow-Robotics / Angles.java
Created January 21, 2015 17:47
Angle subtraction code
// This only works if both of these variables are in the domain of [-180,180]
double currentHeading=90;
double desiredHeading=49;
// Do the subtraction
double error=currentHeading-desiredHeading;
// If the error is under -180, it is inefficient. So, add a full turn to that number. That way something like -190 becomes 170. The magnitude is smaller but if you plot that angle, it is the same angle.
if (error<-180)
error+=360;
// Same logic, but different signs.