Last active
June 16, 2019 07:17
-
-
Save symmetryninja/d0192c543c5b65a5f7c9b964cc64aa5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// note PI10 is a constant with pi to ten places | |
void ikDualAngle(double targetX, double targetY, double targetZ) { | |
double legLength, base, lift, reach; | |
// leglength is our first hurdle | |
legLength = sqrt(sq(targetX) + sq(targetZ)); | |
// base rotation -- not working on this yet - set it to zero | |
base = 0; | |
// lift servo position | |
double a1 = atan(targetX/targetZ) * 180/PI10; | |
double a2 = acos( | |
(sq(RADIUS) - sq(HUMEROUS) - sq(legLength)) | |
/ | |
(-2 * legLength * HUMEROUS) | |
) * 180/PI10; | |
lift = 180 - (a1 + a2); // my joints are zero on the vertical | |
// reach servo position | |
reach = acos( | |
(sq(legLength) - sq(RADIUS) - sq(HUMEROUS)) | |
/ | |
(-2 * RADIUS * HUMEROUS) | |
) * 180/PI10; | |
dxLegState.angleBase = base; | |
dxLegState.angleReach = reach; | |
dxLegState.angleLift = lift; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment