BowlerKernel
MobileBase.java
Go to the documentation of this file.
1 package com.neuronrobotics.sdk.addons.kinematics;
2 
3 import java.io.BufferedWriter;
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.FileWriter;
7 import java.io.InputStream;
8 import java.util.ArrayList;
9 import java.util.HashMap;
10 import java.util.Set;
11 
12 import org.w3c.dom.Document;
13 import org.w3c.dom.Element;
14 import org.w3c.dom.Node;
15 import org.w3c.dom.NodeList;
16 
17 import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR;
18 import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
19 import com.neuronrobotics.sdk.addons.kinematics.parallel.ParallelGroup;
20 import com.neuronrobotics.sdk.addons.kinematics.xml.XmlFactory;
21 import com.neuronrobotics.sdk.common.DeviceManager;
22 import com.neuronrobotics.sdk.common.Log;
23 
24 // TODO: Auto-generated Javadoc
30 
32  private final ArrayList<DHParameterKinematics> legs = new ArrayList<DHParameterKinematics>();
33 
35  private final ArrayList<DHParameterKinematics> appendages = new ArrayList<DHParameterKinematics>();
36 
38  private final ArrayList<DHParameterKinematics> steerable = new ArrayList<DHParameterKinematics>();
39 
41  private final ArrayList<DHParameterKinematics> drivable = new ArrayList<DHParameterKinematics>();
42 
44  private final ArrayList<IOnMobileBaseRenderChange> changeListeners = new ArrayList<IOnMobileBaseRenderChange>();
45 
48 
50  private String[] walkingEngine = new String[] { "https://github.com/madhephaestus/carl-the-hexapod.git",
51  "WalkingDriveEngine.groovy" };
52 
53  private HashMap<String, String[]> vitamins = new HashMap<String, String[]>();
54  private HashMap<String, String> vitaminVariant = new HashMap<String, String>();
55 
57  private String[] selfSource = new String[2];
58 
59  private double mass = 0.5;// KG
61 
63 
64  private HashMap<String, ParallelGroup> parallelGroups = new HashMap<String, ParallelGroup>();
66 
70  public MobileBase() {
71  }// used for building new bases live
72 
79  try {
80  return homeProvider.calcHome(limb);
81  } catch (Throwable t) {
82  }
83  return limb.calcHome();
84  }
85 
86  public HashMap<DHParameterKinematics, TransformNR> getTipLocations() {
87 
88  HashMap<DHParameterKinematics, TransformNR> tipList = new HashMap<DHParameterKinematics, TransformNR>();
89  for (DHParameterKinematics leg : legs) {
90  // Read the location of the foot before moving the body
91  TransformNR home = calcHome(leg);
92  tipList.put(leg, home);
93  }
94  return tipList;
95  }
96 
97  public boolean pose(TransformNR newAbsolutePose) throws Exception {
98  HashMap<DHParameterKinematics, TransformNR> tipLocations = getTipLocations();
99 
100  return pose(newAbsolutePose, getIMUFromCentroid(), tipLocations);
101  }
102 
103  public boolean poseAroundPoint(TransformNR newAbsolutePose, TransformNR around) throws Exception {
104  HashMap<DHParameterKinematics, TransformNR> tipLocations = getTipLocations();
105 
106  return pose(newAbsolutePose, around, tipLocations);
107  }
108 
109  public boolean pose(TransformNR newAbsolutePose, TransformNR around,
110  HashMap<DHParameterKinematics, TransformNR> tipList) throws Exception {
111  TransformNR newPoseTransformedToIMUCenter = newAbsolutePose.times(around.inverse());
112  TransformNR newPoseAdjustedBacktoRobotCenterFrame = around.times(newPoseTransformedToIMUCenter);
114  // Perform a pose opperation
115  setGlobalToFiducialTransform(newPoseAdjustedBacktoRobotCenterFrame);
116 
117  for (DHParameterKinematics leg : legs) {
118  TransformNR pose = tipList.get(leg);
119  if (leg.checkTaskSpaceTransform(pose))// move the leg only is the pose of hte limb is possible
120  leg.setDesiredTaskSpaceTransform(pose, 0);// set leg to the location of where the foot was
121  else {
123  for (DHParameterKinematics l : legs) {
124  TransformNR p = tipList.get(l);
125  l.setDesiredTaskSpaceTransform(p, 0);// set leg to the location of where the foot was
126  }
127  return false;
128  }
129  }
130  return true;
131  }
132 
138  public MobileBase(InputStream configFile) {
139  this();
140  Document doc = XmlFactory.getAllNodesDocument(configFile);
141  NodeList nodListofLinks = doc.getElementsByTagName("root");
142 
143  if (nodListofLinks.getLength() != 1) {
144  // System.out.println("Found "+nodListofLinks.getLength());
145  throw new RuntimeException("one mobile base is needed per level");
146  }
147  NodeList rootNode = nodListofLinks.item(0).getChildNodes();
148 
149  for (int i = 0; i < rootNode.getLength(); i++) {
150 
151  Node linkNode = rootNode.item(i);
152  if (linkNode.getNodeType() == Node.ELEMENT_NODE && linkNode.getNodeName().contains("mobilebase")) {
153  Element e = (Element) linkNode;
154  loadConfigs(e);
155  }
156  }
157 
158  }
159 
165  public MobileBase(Element doc) {
166 
167  loadConfigs(doc);
168 
169  }
170 
171  public ParallelGroup getParallelGroup(String name) {
172  if (name == null)
173  throw new RuntimeException("No groups named null allowed");
174  if (getParallelGroups().get(name) == null) {
175  getParallelGroups().put(name, new ParallelGroup(name));
176  }
177  return getParallelGroups().get(name);
178  }
179 
180  public Set<String> getParallelGroupNames() {
181  return getParallelGroups().keySet();
182  }
183 
184  public ArrayList<DHParameterKinematics> getAllParallelGroups() {
185  ArrayList<DHParameterKinematics> list = new ArrayList<DHParameterKinematics>();
186  for (String name : getParallelGroupNames()) {
187  list.add(getParallelGroup(name));
188  }
189  return list;
190  }
191 
193  for (String name : getParallelGroupNames()) {
194  for (DHParameterKinematics dh : getParallelGroup(name).getConstituantLimbs()) {
195  if (dh == limb) {
196  return getParallelGroup(name);
197  }
198  }
199  }
200  return null;
201  }
202 
203  public void addLimbToParallel(DHParameterKinematics limb, TransformNR tipOffset, String name, String relativeLimb,
204  int relativeIndex) {
205  removeLimFromParallel(limb);
207  g.addLimb(limb, tipOffset, relativeLimb, relativeIndex);
208  }
209 
212  if (g != null) {
213  g.removeLimb(limb);
214  }
215  if (g.getConstituantLimbs().size() == 0) {
217  }
218  }
219 
225  private void loadConfigs(Element doc) {
227 
228  setGitCadEngine(getGitCodes(doc, "cadEngine"));
229  setGitWalkingEngine(getGitCodes(doc, "driveEngine"));
230  try {
231  String[] paralellCad = getGitCodes(doc, "parallelCadEngine");
232  getParallelGroup(paralellCad[2]).setGitCadToolEngine(paralellCad);
233  } catch (Exception e) {
234 
235  }
236 
237  loadVitamins(doc);
238  loadLimb(doc, "leg", legs);
239  loadLimb(doc, "drivable", drivable);
240  loadLimb(doc, "steerable", steerable);
241  loadLimb(doc, "appendage", appendages);
242  try {
243  String massString = getTag(doc, "mass");
244  setMassKg(Double.parseDouble(massString));
245  } catch (Exception e) {
246  e.printStackTrace();
247  }
248 
249  TransformNR cmcenter = loadTransform("centerOfMassFromCentroid", doc);
250  if (cmcenter != null)
251  setCenterOfMassFromCentroid(cmcenter);
252  TransformNR IMUcenter = loadTransform("imuFromCentroid", doc);
253  if (IMUcenter != null)
254  setIMUFromCentroid(IMUcenter);
255  TransformNR baseToZframe = loadTransform("baseToZframe", doc);
256  setRobotToFiducialTransform(baseToZframe);
257 
258  fireBaseUpdates();
259  }
260 
261  public void initializeParalellGroups() {
262  for (String key : getParallelGroups().keySet()) {
263  if (key != null) {
264  ParallelGroup g = getParallelGroups().get(key);
265  // Clean up broken configurations
266  if (g.getConstituantLimbs().size() == 0) {
268  } else
269  try {
271  } catch (Exception e) {
272  e.printStackTrace();
273  }
274 
275  }
276  }
277  }
278 
279  private TransformNR loadTransform(String tagname, Element e) {
280 
281  try {
282  NodeList nodListofLinks = e.getChildNodes();
283 
284  for (int i = 0; i < nodListofLinks.getLength(); i++) {
285  Node linkNode = nodListofLinks.item(i);
286  if (linkNode.getNodeType() == Node.ELEMENT_NODE && linkNode.getNodeName().contentEquals(tagname)) {
287  Element cntr = (Element) linkNode;
288  return new TransformNR(Double.parseDouble(XmlFactory.getTagValue("x", cntr)),
289  Double.parseDouble(XmlFactory.getTagValue("y", cntr)),
290  Double.parseDouble(XmlFactory.getTagValue("z", cntr)),
291  new RotationNR(new double[] { Double.parseDouble(XmlFactory.getTagValue("rotw", cntr)),
292  Double.parseDouble(XmlFactory.getTagValue("rotx", cntr)),
293  Double.parseDouble(XmlFactory.getTagValue("roty", cntr)),
294  Double.parseDouble(XmlFactory.getTagValue("rotz", cntr)) }));
295  }
296  }
297 
298  } catch (Exception ex) {
299  ex.printStackTrace();
300 
301  }
302  return new TransformNR();
303  }
304 
312  private String getname(Element e) {
313  String name = getTag(e, "name");
314  if (name == null)
315  name = "nonamespecified";
316  return name;
317  }
318 
326  private String getParallelGroup(Element e) {
327  return getTag(e, "parallelGroup");
328  }
329 
337  private String getTag(Element e, String tagname) {
338  try {
339  NodeList nodListofLinks = e.getElementsByTagName(tagname);
340 
341  for (int i = 0; i < nodListofLinks.getLength(); i++) {
342  Node linkNode = nodListofLinks.item(i);
343  String nameParent = linkNode.getParentNode().getNodeName();
344  boolean isMobileBase = !nameParent.contains("link");
345  if (linkNode.getNodeType() == Node.ELEMENT_NODE && linkNode.getNodeName().contentEquals(tagname)
346  && isMobileBase) {
347  String value = linkNode.getChildNodes().item(0).getNodeValue();
348  // System.out.println("Loading tag "+tagname+" from "+nameParent+" value
349  // "+value);
350  return value;
351  }
352  }
353  } catch (Exception ex) {
354  ex.printStackTrace();
355  }
356  return null;
357  }
358 
366  private void loadLimb(Element doc, String tag, ArrayList<DHParameterKinematics> list) {
367  NodeList nodListofLinks = doc.getChildNodes();
368  for (int i = 0; i < nodListofLinks.getLength(); i++) {
369  Node linkNode = nodListofLinks.item(i);
370  if (linkNode.getNodeType() == Node.ELEMENT_NODE && linkNode.getNodeName().contentEquals(tag)) {
371  Element e = (Element) linkNode;
372  final String name = getname(e);
373  // System.out.println("Loading arm "+name);
375  .getSpecificDevice(DHParameterKinematics.class, name);
376  if (kin == null) {
377  kin = new DHParameterKinematics(e);
378 
379  }
380  kin.setScriptingName(name);
381  String parallel = getParallelGroup(e);
382  // System.out.println("paralell "+parallel);
383  if (parallel != null) {
384  System.out.println("Loading Paralell group " + parallel + " limb " + name);
385  TransformNR paraOffset = loadTransform("parallelGroupTipOffset", e);
386  String relativeName = getTag(e, "relativeTo");
387  int index = 0;
388  try {
389  index = Integer.parseInt(getTag(e, "relativeToLink"));
390  } catch (Exception ex) {
391  paraOffset = null;
392  relativeName = null;
393  }
394  ParallelGroup parallelGroup = getParallelGroup(parallel);
395  parallelGroup.setScriptingName(parallel);
396  parallelGroup.setupReferencedLimbStartup(kin, paraOffset, relativeName, index);
397 // if(!list.contains(parallelGroup)) {
398 // list.add(parallelGroup);
399 // }
400  }
401  // else {
402  list.add(kin);
403  // }
404  }
405  }
406  }
407 
408  /*
409  * (non-Javadoc)
410  *
411  * @see com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR#
412  * disconnectDevice()
413  */
414  @Override
415  public void disconnectDevice() {
416  for (DHParameterKinematics kin : getAllDHChains()) {
417  kin.disconnect();
418  }
419  }
420 
421  /*
422  * (non-Javadoc)
423  *
424  * @see com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR#
425  * connectDevice()
426  */
427  @Override
428  public boolean connectDevice() {
429  for (DHParameterKinematics kin : getAllDHChains()) {
430  if (!kin.connect()) {
431  Log.error("Connection failed!");
432  return false;
433  }
434  }
435  return true;
436  }
437 
438  /*
439  * (non-Javadoc)
440  *
441  * @see com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR#
442  * inverseKinematics(com.neuronrobotics.sdk.addons.kinematics.math. TransformNR)
443  */
444  @Override
445  public double[] inverseKinematics(TransformNR taskSpaceTransform) throws Exception {
446  // TODO Auto-generated method stub
447  return new double[getNumberOfLinks()];
448  }
449 
450  /*
451  * (non-Javadoc)
452  *
453  * @see com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR#
454  * forwardKinematics(double[])
455  */
456  @Override
457  public TransformNR forwardKinematics(double[] jointSpaceVector) {
458  // TODO Auto-generated method stub
459  return new TransformNR();
460  }
461 
467  public ArrayList<DHParameterKinematics> getLegs() {
468  return legs;
469  }
470 
476  public ArrayList<DHParameterKinematics> getAppendages() {
477  return appendages;
478  }
479 
485  public ArrayList<DHParameterKinematics> getAllDHChains() {
486  ArrayList<DHParameterKinematics> copy = new ArrayList<DHParameterKinematics>();
487  for (DHParameterKinematics l : legs) {
488  copy.add(l);
489  }
491  copy.add(l);
492 
493  }
494  for (DHParameterKinematics l : steerable) {
495  copy.add(l);
496  }
497  for (DHParameterKinematics l : drivable) {
498  copy.add(l);
499  }
500  return copy;
501  }
502 
510  private void loadVitamins(Element doc) {
511  NodeList nodListofLinks = doc.getChildNodes();
512  for (int i = 0; i < nodListofLinks.getLength(); i++) {
513  Node linkNode = nodListofLinks.item(i);
514  try {
515  if (linkNode.getNodeType() == Node.ELEMENT_NODE && linkNode.getNodeName().contentEquals("vitamins")) {
516  getVitamins((Element) linkNode);
517  }
518  } catch (Exception e) {
519 
520  }
521  }
522  }
523 
524  public HashMap<String, String[]> getVitamins() {
525  return vitamins;
526  }
527 
533  private void getVitamins(Element doc) {
534 
535  try {
536  NodeList nodListofLinks = doc.getChildNodes();
537  for (int i = 0; i < nodListofLinks.getLength(); i++) {
538  Node linkNode = nodListofLinks.item(i);
539  if (linkNode.getNodeType() == Node.ELEMENT_NODE && linkNode.getNodeName().contentEquals("vitamin")) {
540  Element e = (Element) linkNode;
541  setVitamin(XmlFactory.getTagValue("name", e), XmlFactory.getTagValue("type", e),
542  XmlFactory.getTagValue("id", e));
543  try {
545  } catch (Exception ex) {
546  }
547  }
548  }
549  return;
550  } catch (Exception e) {
551  e.printStackTrace();
552  }
553  return;
554  }
555 
564  public void setVitamin(String name, String type, String id) {
565  if (getVitamins().get(name) == null) {
566  getVitamins().put(name, new String[2]);
567  }
568  getVitamins().get(name)[0] = type;
569  getVitamins().get(name)[1] = id;
570  }
571 
578  public void setVitaminVariant(String name, String tagValue2) {
579  vitaminVariant.put(name, tagValue2);
580  }
581 
588  public String getVitaminVariant(String name) {
589  return vitaminVariant.get(name);
590  }
591 
592  /*
593  * (non-Javadoc)
594  *
595  * @see com.neuronrobotics.sdk.addons.kinematics.AbstractKinematicsNR#getXml()
596  */
597  /*
598  *
599  * Generate the xml configuration to generate an XML of this robot.
600  */
601  public String getXml() {
602  String xml = "<root>\n";
603  xml += getEmbedableXml();
604  xml += "\n</root>";
605  return xml;
606  }
607 
613  /*
614  *
615  * Generate the xml configuration to generate an XML of this robot.
616  */
617  public String getEmbedableXml() {
619 
620  String allVitamins = "";
621  for (String key : getVitamins().keySet()) {
622  String v = "\t\t<vitamin>\n";
623  v += "\t\t\t<name>" + key + "</name>\n" + "\t\t\t<type>" + getVitamins().get(key)[0] + "</type>\n"
624  + "\t\t\t<id>" + getVitamins().get(key)[1] + "</id>\n";
625  if (getVitaminVariant(key) != null) {
626  v += "\t\t\t<variant>" + getVitamins().get(key)[1] + "</variant>\n";
627  }
628  v += "\t\t</vitamin>\n";
629  allVitamins += v;
630  }
631  String xml = "<mobilebase>\n";
632 
633  xml += "\t<cadEngine>\n";
634  xml += "\t\t<git>" + getGitCadEngine()[0] + "</git>\n";
635  xml += "\t\t<file>" + getGitCadEngine()[1] + "</file>\n";
636  xml += "\t</cadEngine>\n";
637 
638  xml += "\t<driveEngine>\n";
639  xml += "\t\t<git>" + getGitWalkingEngine()[0] + "</git>\n";
640  xml += "\t\t<file>" + getGitWalkingEngine()[1] + "</file>\n";
641  xml += "\t</driveEngine>\n";
642 
643  for (String key : getParallelGroups().keySet()) {
644  ParallelGroup g = getParallelGroups().get(key);
645  if (key != null) {
646  xml += "\t<parallelCadEngine>\n";
647  xml += "\t\t<parallelGroup>" + key + "</parallelGroup>\n";
648  xml += "\t\t<git>" + g.getGitCadToolEngine()[0] + "</git>\n";
649  xml += "\t\t<file>" + g.getGitCadToolEngine()[1] + "</file>\n";
650  xml += "\t</parallelCadEngine>\n";
651  }
652  }
653 
654  xml += "\n<name>" + getScriptingName() + "</name>\n";
655  for (DHParameterKinematics l : legs) {
656  xml += "<leg>\n";
657  xml = makeLimbTag(xml, l);
658  xml += "\n</leg>\n";
659  }
661  xml += "<appendage>\n";
662  xml = makeLimbTag(xml, l);
663  xml += "\n</appendage>\n";
664  }
665 
666  for (DHParameterKinematics l : steerable) {
667  xml += "<steerable>\n";
668  xml += "\n<name>" + l.getScriptingName() + "</name>\n";
669  xml += l.getEmbedableXml();
670  xml += "\n</steerable>\n";
671  }
672  for (DHParameterKinematics l : drivable) {
673  xml += "<drivable>\n";
674  xml += "\n<name>" + l.getScriptingName() + "</name>\n";
675  xml += l.getEmbedableXml();
676  xml += "\n</drivable>\n";
677  }
678 
679  xml += "\n<ZframeToRAS>\n";
681  xml += "\n</ZframeToRAS>\n";
682 
683  xml += "\n<baseToZframe>\n";
685  xml += "\n</baseToZframe>\n" + "\t<mass>" + getMassKg() + "</mass>\n" + "\t<centerOfMassFromCentroid>"
686  + getCenterOfMassFromCentroid().getXml() + "</centerOfMassFromCentroid>\n" + "\t<imuFromCentroid>"
687  + getIMUFromCentroid().getXml() + "</imuFromCentroid>\n";
688  xml += "\n<vitamins>\n" + allVitamins + "\n</vitamins>\n";
689  xml += "\n</mobilebase>\n";
691  return xml;
692  }
693 
694  private String makeLimbTag(String xml, DHParameterKinematics l) {
695  xml += "\n<name>" + l.getScriptingName() + "</name>\n";
696  for (String key : getParallelGroups().keySet()) {
697  ParallelGroup parallelGroup = getParallelGroups().get(key);
698  for (DHParameterKinematics pL : parallelGroup.getConstituantLimbs())
699 
700  if (pL == l) {
701  xml += "\n<parallelGroup>" + key + "</parallelGroup>\n";
702  if (parallelGroup.getTipOffset(l) != null) {
703  xml += "\n<parallelGroupTipOffset>\n" + parallelGroup.getTipOffset(l).getXml()
704  + "\n\t<relativeTo>" + parallelGroup.getTipOffsetRelativeName(l) + "</relativeTo>\n"
705  + "\n\t<relativeToLink>" + parallelGroup.getTipOffsetRelativeIndex(l)
706  + "</relativeToLink>\n" + "\n</parallelGroupTipOffset>\n";
707  }
708  }
709  }
710  xml += l.getEmbedableXml();
711  return xml;
712  }
713 
719  public ArrayList<DHParameterKinematics> getSteerable() {
720  return steerable;
721  }
722 
728  public ArrayList<DHParameterKinematics> getDrivable() {
729  return drivable;
730  }
731 
738 
739  return walkingDriveEngine;
740  }
741 
748  this.walkingDriveEngine = walkingDriveEngine;
749  }
750 
757  public void DriveArc(TransformNR newPose, double seconds) {
758  getWalkingDriveEngine().DriveArc(this, newPose, seconds);
759  updatePositions();
760  }
761 
767  public void DriveVelocityStraight(double cmPerSecond) {
768  getWalkingDriveEngine().DriveVelocityStraight(this, cmPerSecond);
769 
770  updatePositions();
771  }
772 
779  public void DriveVelocityArc(double degreesPerSecond, double cmRadius) {
780  getWalkingDriveEngine().DriveVelocityArc(this, degreesPerSecond, cmRadius);
781 
782  updatePositions();
783  }
784 
788  public void updatePositions() {
791  }
792 
798  public String[] getGitWalkingEngine() {
799  return walkingEngine;
800  }
801 
807  public void setGitWalkingEngine(String[] walkingEngine) {
808  if (walkingEngine != null && walkingEngine[0] != null && walkingEngine[1] != null)
809  this.walkingEngine = walkingEngine;
810  }
811 
817  public String[] getGitSelfSource() {
818  return selfSource;
819  }
820 
828  public void setGitSelfSource(String[] selfSource) {
829  this.selfSource = selfSource;
830  }
831 
832  public double getMassKg() {
833  return mass;
834  }
835 
836  public void setMassKg(double mass) {
837  System.out.println("Mass of device " + getScriptingName() + " is " + mass);
838  this.mass = mass;
839  }
840 
843  }
844 
846  this.centerOfMassFromCentroid = centerOfMassFromCentroid;
847  }
848 
850  return IMUFromCentroid;
851  }
852 
854  this.IMUFromCentroid = centerOfMassFromCentroid;
855  }
856 
859  }
860 
861 
862 
863  private void fireBaseUpdates() {
864  TransformNR frameToBase = forwardOffset(new TransformNR());
866  l.setGlobalToFiducialTransform(frameToBase);
867  }
868  }
869 
870  public void shutDownParallel(ParallelGroup group) {
871  group.close();
872  parallelGroups.remove(group.getNameOfParallelGroup());
873  }
874 
875  private HashMap<String, ParallelGroup> getParallelGroups() {
876  return parallelGroups;
877  }
878 
879  @Override
880  public boolean connect() {
881  super.connect();
882 
883  for (DHParameterKinematics kin : this.getAllDHChains()) {
884  for (int i = 0; i < kin.getNumberOfLinks(); i++) {
885  MobileBase m = kin.getDhLink(i).getSlaveMobileBase();
886  if (m != null) {
887  m.connect();
888  }
889  }
890  }
891  for (DHParameterKinematics kin : getAllDHChains()) {
892  addListeners(kin);
893  }
895  @Override
896  public void onFiducialToGlobalUpdate(AbstractKinematicsNR source, TransformNR regestration) {
897  fireBaseUpdates();
898  }
899 
900  @Override
901  public void onBaseToFiducialUpdate(AbstractKinematicsNR source, TransformNR regestration) {
902  fireBaseUpdates();
903  }
904  });
905  return isAvailable();
906  }
907 
909  for (int i = 0; i < kin.getNumberOfLinks(); i++) {
910  kin.addChangeListener(i, this);
912  if (m != null) {
914  }
915 
916  }
917  kin.addJointSpaceListener(this);
919 
920  }
921 
922  public static void main(String[] args) throws Exception {
923  File f = new File("paralleloutput.xml");
924 
925  MobileBase pArm = new MobileBase(new FileInputStream(f));
926 // pArm.isAvailable();
927 // pArm.connect();
928 // pArm.connectDeviceImp();
929 // pArm.connectDevice();
930 
931  String xmlParsed = pArm.getXml();
932  BufferedWriter writer = null;
933 
934  writer = new BufferedWriter(new FileWriter("paralleloutput2.xml"));
935  writer.write(xmlParsed);
936 
937  if (writer != null)
938  writer.close();
939 
940  ParallelGroup group = pArm.getParallelGroup("ParallelArmGroup");
941 
943 
944  group.setDesiredTaskSpaceTransform(Tip.copy().translateX(-1), 0);
945  for (DHParameterKinematics limb : group.getConstituantLimbs()) {
946  TransformNR TipOffset = group.getTipOffset().get(limb);
947  TransformNR newTip = limb.getCurrentTaskSpaceTransform().times(TipOffset);
948 
949  System.out.println("Expected tip to be " + Tip.getX() + " and got: " + newTip.getX());
950  // assertTrue(!Double.isNaN(Tip.getX()));
951  // assertEquals(Tip.getX(), newTip.getX(), .1);
952  }
953 
954  }
955 
957  for (int i = 0; i < changeListeners.size(); i++) {
960  }
961  }
962 
964  this.homeProvider = homeProvider;
965  }
966 
968  if (changeListeners.contains(l))
969  return;
970  changeListeners.add(l);
971  }
972 
974  if (changeListeners.contains(l))
975  changeListeners.remove(l);
976  }
977 
979 
980  changeListeners.clear();
981  }
982 
983  @Override
984  public void event(LinkConfiguration newConf) {
985  // TODO Auto-generated method stub
987  }
988 
989  @Override
991  // TODO Auto-generated method stub
993  }
994 
995  @Override
996  public void onJointSpaceUpdate(AbstractKinematicsNR source, double[] joints) {
997  // TODO Auto-generated method stub
999  }
1000 
1001  @Override
1002  public void onJointSpaceTargetUpdate(AbstractKinematicsNR source, double[] joints) {
1003  // TODO Auto-generated method stub
1004 
1005  }
1006 
1007  @Override
1008  public void onJointSpaceLimit(AbstractKinematicsNR source, int axis, JointLimit event) {
1009  // TODO Auto-generated method stub
1010 
1011  }
1012 
1013  @Override
1014  public void sync() {
1015  doSync();
1016  }
1017 
1018 }
void addChangeListener(int linkIndex, ILinkConfigurationChangeListener l)
void setGlobalToFiducialTransform(TransformNR frameToBase, boolean fireUpdate)
double[] setDesiredTaskSpaceTransform(TransformNR taskSpaceTransform, double seconds)
void onJointSpaceTargetUpdate(AbstractKinematicsNR source, double[] joints)
ArrayList< DHParameterKinematics > getDrivable()
String makeLimbTag(String xml, DHParameterKinematics l)
void setVitaminVariant(String name, String tagValue2)
void loadLimb(Element doc, String tag, ArrayList< DHParameterKinematics > list)
void setWalkingDriveEngine(IDriveEngine walkingDriveEngine)
void setGitWalkingEngine(String[] walkingEngine)
void setIMUFromCentroid(TransformNR centerOfMassFromCentroid)
ArrayList< DHParameterKinematics > getAppendages()
final ArrayList< DHParameterKinematics > appendages
Definition: MobileBase.java:35
void setCenterOfMassFromCentroid(TransformNR centerOfMassFromCentroid)
void addIOnMobileBaseRenderChange(IOnMobileBaseRenderChange l)
ArrayList< DHParameterKinematics > getAllDHChains()
ArrayList< DHParameterKinematics > getLegs()
TransformNR forwardKinematics(double[] jointSpaceVector)
void addLimbToParallel(DHParameterKinematics limb, TransformNR tipOffset, String name, String relativeLimb, int relativeIndex)
HashMap< String, ParallelGroup > parallelGroups
Definition: MobileBase.java:64
void onJointSpaceUpdate(AbstractKinematicsNR source, double[] joints)
boolean pose(TransformNR newAbsolutePose, TransformNR around, HashMap< DHParameterKinematics, TransformNR > tipList)
void removeLimFromParallel(DHParameterKinematics limb)
void setHomeProvider(ICalcLimbHomeProvider homeProvider)
final ArrayList< DHParameterKinematics > drivable
Definition: MobileBase.java:41
String getTag(Element e, String tagname)
HashMap< DHParameterKinematics, TransformNR > getTipLocations()
Definition: MobileBase.java:86
boolean poseAroundPoint(TransformNR newAbsolutePose, TransformNR around)
ParallelGroup getParallelGroup(DHParameterKinematics limb)
void onJointSpaceLimit(AbstractKinematicsNR source, int axis, JointLimit event)
final ArrayList< DHParameterKinematics > legs
Definition: MobileBase.java:32
double[] inverseKinematics(TransformNR taskSpaceTransform)
void DriveVelocityArc(double degreesPerSecond, double cmRadius)
HashMap< String, ParallelGroup > getParallelGroups()
ArrayList< DHParameterKinematics > getSteerable()
final ArrayList< IOnMobileBaseRenderChange > changeListeners
Definition: MobileBase.java:44
void setVitamin(String name, String type, String id)
boolean pose(TransformNR newAbsolutePose)
Definition: MobileBase.java:97
TransformNR loadTransform(String tagname, Element e)
TransformNR calcHome(DHParameterKinematics limb)
Definition: MobileBase.java:78
ArrayList< DHParameterKinematics > getAllParallelGroups()
void addListeners(DHParameterKinematics kin)
final ArrayList< DHParameterKinematics > steerable
Definition: MobileBase.java:38
void removeIOnMobileBaseRenderChange(IOnMobileBaseRenderChange l)
void DriveArc(TransformNR newPose, double seconds)
HashMap< DHParameterKinematics, TransformNR > getTipOffset()
void addLimb(DHParameterKinematics limb, TransformNR tip, String name, int index)
void setupReferencedLimbStartup(DHParameterKinematics limb, TransformNR tip, String name, int index)
static String getTagValue(String sTag, Element eElement)
Definition: XmlFactory.java:77
static Document getAllNodesDocument(InputStream config)
Definition: XmlFactory.java:37
static void error(String message)
Definition: Log.java:92
TransformNR calcHome(DHParameterKinematics limb)
default void DriveVelocityStraight(MobileBase source, double cmPerSecond)
default void DriveVelocityArc(MobileBase source, double degreesPerSecond, double cmRadius)
abstract void DriveArc(MobileBase source, TransformNR newPose, double seconds)