Create a gist now

Instantly share code, notes, and snippets.

@schreiaj /omni.java
Last active Aug 29, 2015

OmniDrive General Solution
int wheels = 3;
double spinScale = 0.5;
double angles[] = {0, 1.507, 3.14};
double maxOutput = 1.0;
// left, center, right
double outputs[] = {0, 0, 0};
double maxValue = 0.0;
// Compute the array of inputs
for(int i = 0; i < wheels; i++){
outputs[i] = -(x)*Math.sin(angles[i])+y*Math.cos(angles[i])+(-spinScale*rot);
if(Math.abs(outputs[i]) > maxValue) {
maxValue = Math.abs(outputs[i]);
}
}
// If we've given any output a value greater than max
// then scale it down.
if(maxValue > maxOutput) {
double scale = maxOutput/maxValue;
for(int i = 0; i < wheels; i++) {
outputs[i] = outputs[i] * scale;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment