Skip to content

Instantly share code, notes, and snippets.

@mdiblasi
Forked from madhephaestus/TrobotLinks.xml
Last active September 29, 2015 23:08
Show Gist options
  • Save mdiblasi/3b31eec7e2db7c50a1e5 to your computer and use it in GitHub Desktop.
Save mdiblasi/3b31eec7e2db7c50a1e5 to your computer and use it in GitHub Desktop.
Trobot Arm
import java.util.ArrayList;
import com.neuronrobotics.sdk.addons.kinematics.DHChain;
import com.neuronrobotics.sdk.addons.kinematics.DHLink;
import com.neuronrobotics.sdk.addons.kinematics.DhInverseSolver;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
import com.neuronrobotics.sdk.common.Log;
import Jama.Matrix;
return new DhInverseSolver() {
@Override
public double[] inverseKinematics(TransformNR target,
double[] jointSpaceVector,DHChain chain ) {
ArrayList<DHLink> links = chain.getLinks();
// This is the jacobian for the given configuration
Matrix jacobian = chain.getJacobian(jointSpaceVector);
Matrix taskSpaceMatrix = target.getMatrixTransform();
// Print dimensions of matrices.
println "Jacobian Rows: "+jacobian.getArray().length
println "Jacobian Columns: "+jacobian.getArray()[1].length
println "Task Space Rows: "+taskSpaceMatrix.getArray().length
println "Task Space Columns: "+taskSpaceMatrix.getArray()[1].length
// Perform first half of Pseudo Jacobian calculations.
int linkNum = jointSpaceVector.length;
double [] inv = new double[linkNum];
Matrix Jt
Matrix Jstore
Matrix Jp
Jt = jacobian.transpose()
Jstore = jacobian.times(Jt)
Jstore = Jstore.inverse()
Jp = Jt.times(Jstore)
// Generate and fill 6x1 joint space matrix.
x = target.getX()
y = target.getY()
z = target.getZ()
RotationNR rot = target.getRotation();
t = rot.getRotationTilt()
e = rot.getRotationElevation()
a = rot.getRotationAzimuth()
double[][] vals = {{x.},{y.},{z.},{t.},{e.},{a.}};
Matrix testMatrix = new Matrix(vals);
println "Test Rows: "+testMatrix.getArray().length
println "Test Columns: "+testMatrix.getArray()[1].length
testMatrix.set(0, 0, x)
testMatrix.set(1, 0, y)
testMatrix.set(2, 0, z)
testMatrix.set(3, 0, t)
testMatrix.set(4, 0, e)
testMatrix.set(5, 0, a)
println"Before"
// Complete Pseudo Jacobian calculations.
Jstore = Jp.times(testMatrix)
println"Success"
inv[0] = Jstore.get(0, 0)
inv[1] = Jstore.get(1, 0)
inv[2] = Jstore.get(2, 0)
inv[3] = Jstore.get(3, 0)
inv[4] = Jstore.get(4, 0)
inv[5] = Jstore.get(5, 0)
println inv
return inv;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment