1 package com.neuronrobotics.sdk.addons.kinematics;
3 import java.io.InputStream;
4 import java.util.ArrayList;
8 import org.w3c.dom.Element;
9 import org.w3c.dom.Node;
10 import org.w3c.dom.NodeList;
14 import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
15 import com.neuronrobotics.sdk.addons.kinematics.xml.XmlFactory;
16 import com.neuronrobotics.sdk.common.Log;
25 private ArrayList<DHLink>
links =
new ArrayList<DHLink>();
28 private ArrayList<TransformNR>
chain =
new ArrayList<TransformNR>();
31 private ArrayList<TransformNR>
intChain =
new ArrayList<TransformNR>();
117 long start = System.currentTimeMillis();
165 double [] xProd =
new double [3];
167 xProd[0]=a[1]*b[2]-a[2]*b[1];
168 xProd[1]=a[2]*b[0]-a[0]*b[2];
169 xProd[2]=a[0]*b[1]-a[1]*b[0];
187 if (jointSpaceVector.length!=
getLinks().size())
188 throw new IndexOutOfBoundsException(
"DH links do not match defined links. expected "+
getLinks().size()+
" got "+jointSpaceVector.length);
191 for(
int i=0;i<
getLinks().size();i++) {
197 step=
getLinks().get(i).DhStep(jointSpaceVector[i]);
199 step=
getLinks().get(i).DhStep(Math.toRadians(jointSpaceVector[i]));
201 current = current.times(step);
207 if(chainToLoad!=
null){
214 if(chainToLoad.size()<=i)
215 chainToLoad.add(pose);
217 chainToLoad.set(i, pose);
220 }
catch(java.lang.RuntimeException ex) {
222 for(
int x=0;x<jointSpaceVector.length;x++) {
223 pose=pose+
" "+jointSpaceVector[x]+
" , \n";
226 throw new RuntimeException(ex.getMessage()+
" for pose "+pose);
262 public ArrayList<TransformNR>
getChain(
double[] jointSpaceVector) {
263 ArrayList<TransformNR> chainToLoad =
new ArrayList<TransformNR>();
275 chain=
new ArrayList<TransformNR>();
323 s+=l.toString()+
"\n";
346 int linkNum = jointSpaceVector.length;
347 double [] inv =
new double[linkNum];
350 double d =
links.get(1).getD()-
links.get(2).getD();
351 double r =
links.get(0).getR();
353 double lengthXYPlaneVect = Math.sqrt(Math.pow(target.
getX(),2)+Math.pow(target.
getY(),2));
354 double angleXYPlaneVect = Math.asin(target.
getY()/lengthXYPlaneVect);
356 double angleRectangleAdjustedXY =Math.asin(d/lengthXYPlaneVect);
358 double lengthRectangleAdjustedXY = lengthXYPlaneVect* Math.cos(angleRectangleAdjustedXY)-r;
361 double orentation = angleXYPlaneVect-angleRectangleAdjustedXY;
362 if(Math.abs(Math.toDegrees(orentation))<0.01){
365 double ySet = lengthRectangleAdjustedXY*Math.sin(orentation);
366 double xSet = lengthRectangleAdjustedXY*Math.cos(orentation);
369 double zSet = target.
getZ() -
links.get(0).getD();
371 zSet+=
links.get(4).getD();
381 double l1 =
links.get(1).getR();
382 double l2 =
links.get(2).getR();
384 double vect = Math.sqrt(xSet*xSet+ySet*ySet+zSet*zSet);
403 if (vect > l1+l2 || vect<0 ||lengthRectangleAdjustedXY<0 ) {
404 throw new RuntimeException(
"Hypotenus too long: "+vect+
" longer then "+l1+l2);
410 double A =Math.acos((Math.pow(b,2)+ Math.pow(c,2) - Math.pow(a,2)) / (2.0*b*c));
411 double B =Math.acos((Math.pow(c,2)+ Math.pow(a,2) - Math.pow(b,2)) / (2.0*a*c));
412 double C =Math.PI-A-B;
413 double elevation = Math.asin(zSet/vect);
422 inv[0] = Math.toDegrees(orentation);
423 inv[1] = -Math.toDegrees((A+elevation+
links.get(1).getTheta()));
424 if((
int)
links.get(1).getAlpha() ==180){
425 inv[2] = (Math.toDegrees(C))-180-
426 Math.toDegrees(
links.get(2).getTheta());
428 if((
int)
links.get(1).getAlpha() ==0){
429 inv[2] = -(Math.toDegrees(C))+Math.toDegrees(
links.get(2).getTheta());
432 inv[3] =(inv[1] -inv[2]);
437 for(
int i=0;i<inv.length;i++){
438 if(Math.abs(inv[i]) < 0.01){
447 for(;i<inv.length && i<jointSpaceVector.length ;i++){
448 inv[i]=jointSpaceVector[i];
TransformNR forwardOffset(TransformNR t)
TransformNR forwardKinematics(double[] jointSpaceVector, boolean store)
TransformNR forwardOffset(TransformNR transformNR)
ArrayList< TransformNR > getCachedChain()
void setChain(ArrayList< TransformNR > chain)
TransformNR forwardKinematics(double[] jointSpaceVector)
DHChain(AbstractKinematicsNR kin)
Matrix forwardKinematicsMatrix(double[] jointSpaceVector, ArrayList< TransformNR > chainToLoad)
double[] inverseKinematics(TransformNR target, double[] jointSpaceVector)
double[] crossProduct(double[] a, double[] b)
DhInverseSolver getInverseSolver()
double[] getlowerLimits()
ArrayList< TransformNR > intChain
ArrayList< TransformNR > getChain(double[] jointSpaceVector)
void setInverseSolver(DhInverseSolver is)
ArrayList< DHLink > links
ArrayList< DHLink > getLinks()
Matrix forwardKinematicsMatrix(double[] jointSpaceVector, boolean store)
void setFactory(LinkFactory factory)
void addLink(DHLink link)
ArrayList< TransformNR > chain
void removeLink(DHLink link)
double[] getUpperLimits()
void setLinks(ArrayList< DHLink > links)
ArrayList< LinkConfiguration > getLinkConfigurations()
double[] getLowerLimits()
double[] getUpperLimits()
double[] inverseKinematics(TransformNR target, double[] jointSpaceVector, DHChain chain)