BowlerKernel
DHLink.java
Go to the documentation of this file.
1 package com.neuronrobotics.sdk.addons.kinematics;
2 
3 import java.util.ArrayList;
4 
5 
6 import org.w3c.dom.Element;
7 
8 import Jama.Matrix;
9 
10 import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
11 import com.neuronrobotics.sdk.addons.kinematics.xml.XmlFactory;
12 
13 // TODO: Auto-generated Javadoc
17 public class DHLink {
18 
20  private double d;
21 
23  private double theta;
24 
26  private double radius;
27 
29  private double alpha;
30 
32  private Matrix transX;
33 
35  private Matrix rotX;
36 
38  private Matrix transZ;
39 
41  private Matrix rotZ;
42 
44  private Matrix transX_J;
45 
47  private Matrix rotX_J;
48 
50  private Matrix transZ_J;
51 
53  private Matrix rotZ_J;
54 
56  private Object listener=null;
57 
59  private Object root=null;
60 
63 
65  private ArrayList<IDhLinkPositionListener> dhlisteners = new ArrayList<IDhLinkPositionListener>();
66 
69 
71 
72 
81  public DHLink(double d, double theta,double r, double alpha) {
82  this.setDelta(d);
83  this.setTheta(theta);
84  this.setRadius(r);
85  this.setAlpha(alpha);
86 
87  }
88 
95  public DHLink(Element nNode, LinkConfiguration newLinkConf) {
96  this.newLinkConf = newLinkConf;
97  setDelta(XmlFactory.getTagValueDouble("Delta", nNode));
98  setTheta(Math.toRadians(XmlFactory.getTagValueDouble("Theta", nNode)));
99  setRadius(XmlFactory.getTagValueDouble("Radius", nNode));
100  setAlpha(Math.toRadians(XmlFactory.getTagValueDouble("Alpha", nNode)));
101 
102  }
103 
104  public DHLink(DHLink dhl) {
105  setDelta(dhl.getDelta());
106  setTheta(dhl.getTheta());
107  setRadius(dhl.getRadius());
108  setAlpha(dhl.getAlpha());
109  }
110 
117  if(slaveMobileBase!=null)
120  l.onLinkGlobalPositionChange(newPose);
121  }
122  }
123 
130  if(!dhlisteners.contains(l))
131  dhlisteners.add(l);
132  }
133 
140  if(dhlisteners.contains(l))
141  dhlisteners.remove(l);
142  }
143 
149  /*
150  *
151  * Generate the xml configuration to generate a link of this configuration.
152  */
153  public String getXml(){
154  String mb = getSlaveMobileBase()==null?"":"\n\t\t"+getSlaveMobileBase().getEmbedableXml() +"\n";
155  return "\n\t<DHParameters>\n"+
156  "\t\t<Delta>"+d+"</Delta>\n"+
157  "\t\t<Theta>"+Math.toDegrees(theta)+"</Theta>\n"+
158  "\t\t<Radius>"+radius+"</Radius>\n"+
159  "\t\t<Alpha>"+Math.toDegrees(alpha)+"</Alpha>\n"+
160  mb+
161  "\t</DHParameters>\n";
162  }
163 
169  public double getD() {
170  return getDelta();
171  }
172 
178  public double getTheta() {
179  return theta;
180  }
181 
187  public double getR() {
188  return getRadius();
189  }
190 
196  public double getAlpha() {
197  return alpha;
198  }
199 
200 
208  public Matrix DhStepInverse(Matrix end, double jointValue) {
209  switch(type){
210  case PRISMATIC:
211  return DhStepInverse(end,0,jointValue);
212  case ROTORY:
213  return DhStepInverse(end,jointValue,0);
214  default:
215  case TOOL:
216  return DhStepInverse(end,0,0);
217  }
218 
219  }
220 
227  public Matrix DhStep(double jointValue) {
228  switch(type){
229  case PRISMATIC:
230  return DhStep(0,jointValue);
231  case ROTORY:
232  return DhStep(jointValue,0);
233  default:
234  case TOOL:
235  return DhStep(0,0);
236  }
237  }
238 
239 
247  public Matrix DhStep(double rotory,double prismatic) {
248 
249  setMatrix(rotory, prismatic);
250 
251  Matrix step = getTransZ();
252  step = step.times(getRotZ());
253  step = step.times(getTransX());
254  step = step.times(getRotX());
255 
256 
257  return step;
258  }
259 
268  public Matrix DhStepInverse(Matrix end,double rotory,double prismatic) {
269  setMatrix(rotory, prismatic);
270 
271  Matrix step = end.times(getRotX().inverse());
272  step = step.times(getTransX().inverse());
273  step = step.times(getRotZ().inverse());
274  step = step.times(getTransZ().inverse());
275 
276  return step;
277  }
278 
286  public Matrix DhStepInverse(double rotory,double prismatic) {
287 
288  Matrix end=new TransformNR().getMatrixTransform();
289 
290  return DhStepInverse(end,rotory,prismatic);
291  }
292 
293 
300  public Matrix DhStepInversePrismatic(double prismatic) {
301 
302  return DhStepInverse(0,prismatic);
303  }
304 
305 
312  public Matrix DhStepInverseRotory(double rotory) {
313  return DhStepInverse(rotory,0);
314  }
315 
316 
322  public void setTransX(Matrix transX) {
323  this.transX = transX;
324  }
325 
331  public void setRotX(Matrix rotX) {
332  this.rotX = rotX;
333  }
334 
335 
342  private void setMatrix(double rotory,double prismatic){
343  transZ = new Matrix( new double [][] {
344  {1,0,0,0},
345  {0,1,0,0},
346  {0,0,1,getD()+prismatic},
347  {0,0,0,1}});
348 
349  rotZ=new Matrix( new double [][] {
350  {Math.cos(getTheta()+rotory), -Math.sin(getTheta()+rotory), 0, 0},
351  {Math.sin(getTheta()+rotory), Math.cos(getTheta()+rotory), 0, 0},
352  {0, 0, 1, 0},
353  {0, 0, 0, 1}});
354  }
355 
361  public Matrix getTransX() {
362  if(transX == null){
363  transX=new Matrix( new double [][] {
364  {1,0,0,getR()},
365  {0,1,0,0},
366  {0,0,1,0},
367  {0,0,0,1}});
368  }
369  return transX;
370  }
371 
377  public Matrix getRotX() {
378  if(rotX == null){
379  rotX=new Matrix( new double [][] {
380  {1, 0, 0, 0},
381  {0, Math.cos(getAlpha()), -Math.sin(getAlpha()), 0},
382  {0, Math.sin(getAlpha()), Math.cos(getAlpha()), 0},
383  {0, 0, 0, 1}});
384  }
385  return rotX;
386  }
387 
393  public Matrix getTransZ() {
394  return transZ;
395  }
396 
402  public Matrix getRotZ() {
403  return rotZ;
404  }
405 
413  public Matrix DhStepJacobian(double rotoryVelocity,double prismaticVelocity) {
414 
415  setJacobianMatrix(rotoryVelocity, prismaticVelocity);
416 
417  Matrix step = getTransZ_J();
418  step = step.times(getRotZ_J());
419  step = step.times(getTransX_J());
420  step = step.times(getRotX_J());
421 
422  return step;
423  }
424 
431  private void setJacobianMatrix(double rotory,double prismatic){
432  rotZ_J = new Matrix( new double [][] {
433  {1,0,0, 0 },
434  {0,1,0, 0 },
435  {0,0,1, getD()+prismatic },
436  {0,0,0, 1 }});
437 
438  transZ_J = new Matrix( new double [][] {
439  {Math.cos(getTheta()+rotory),-Math.sin(getTheta()+rotory), 0, 0},
440  {Math.sin(getTheta()+rotory), Math.cos(getTheta()+rotory), 0, 0},
441  {0, 0, 1, 0},
442  {0, 0, 0, 1}});
443  }
444 
450  public Matrix getRotX_J() {
451  if(rotX_J == null){
452  rotX_J = new Matrix( new double [][] {
453  {1, 0, 0, 0},
454  {0, Math.cos(getAlpha()), -Math.sin(getAlpha()), 0},
455  {0, Math.sin(getAlpha()), Math.cos(getAlpha()), 0},
456  {0, 0, 0, 1}});
457  }
458  return rotX_J;
459  }
460 
466  public Matrix getTransX_J() {
467  if(transX_J == null){
468  transX_J= new Matrix( new double [][] {
469  {1,0,0,getR()},
470  {0,1,0,0},
471  {0,0,1,0},
472  {0,0,0,1}});
473  }
474  return transX_J;
475  }
476 
477 
478 
484  public Matrix getTransZ_J() {
485  return transZ_J;
486  }
487 
493  public Matrix getRotZ_J() {
494  return rotZ_J;
495  }
496 
497  /* (non-Javadoc)
498  * @see java.lang.Object#toString()
499  */
500  @Override
501  public String toString(){
502  String s="";
503  s+=" Delta = "+getDelta();
504  s+=" Theta = "+Math.toDegrees(getTheta())+" deg";
505  s+=" Radius = "+getRadius();
506  s+=" Alpha = "+Math.toDegrees(getAlpha())+" deg";
507  return s;
508  }
509 
515  public Object getListener() {
516  return listener;
517  }
518 
524  public void setListener(Object listener) {
525  this.listener = listener;
526  }
527 
533  public Object getRootListener() {
534  return root;
535  }
536 
542  void setRootListener(Object listener) {
543  this.root = listener;
544  }
545 
551  public double getDelta() {
552  return d;
553  }
554 
560  public void setDelta(double d) {
561  this.d = d;
562  if(newLinkConf!=null)newLinkConf.fireChangeEvent();
563  }
564 
570  public double getRadius() {
571  return radius;
572  }
573 
579  public void setRadius(double radius) {
580  this.radius = radius;
581  transX_J=null;
582  transX=null;
583  if(newLinkConf!=null)newLinkConf.fireChangeEvent();
584  }
585 
591  public void setTheta(double theta) {
592  this.theta = theta;
593  if(newLinkConf!=null)newLinkConf.fireChangeEvent();
594  }
595 
601  public void setAlpha(double alpha) {
602  this.alpha = alpha;
603  rotX=null;
604  rotX_J=null;
605  if(newLinkConf!=null)newLinkConf.fireChangeEvent();
606  }
607 
614  return type;
615  }
616 
622  public void setLinkType(DhLinkType type) {
623  this.type = type;
624  }
625 
631  public void setMobileBaseXml(MobileBase embedableXml) {
632  this.setSlaveMobileBase(embedableXml);
633  }
634 
636  return slaveMobileBase;
637  }
638 
639  public void setSlaveMobileBase(MobileBase embedableXml) {
640  this.slaveMobileBase = embedableXml;
641  }
642 
643 }
void setGlobalToFiducialTransform(TransformNR frameToBase, boolean fireUpdate)
static Double getTagValueDouble(String sTag, Element eElement)
Definition: XmlFactory.java:92