@@ -391,31 +391,31 @@ public File getFile() throws Exception {
391391 }
392392
393393 public MobileBase build () throws Exception {
394- if (!mobileBase .isAvailable ())
394+ if (!mobileBase .isAvailable ())
395395 mobileBase .connect ();
396- String filename = (xmlName != null ) ? xmlName : mobileBase .getScriptingName () ;
396+ String filename = (xmlName != null ) ? xmlName : mobileBase .getScriptingName ();
397397 mobileBase .setGitSelfSource (new String [] { gitURL , filename });
398398 for (int i = 0 ; i < controllers .size (); i ++) {
399399 AddRobotController con = controllers .get (i );
400- for (VitaminLocation l : con .getVitamins (con .getName ()+ "_" + i )) {
400+ for (VitaminLocation l : con .getVitamins (con .getName () + "_" + i )) {
401401 try {
402- if (!mobileBase .hasVitamin (l ))
402+ if (!mobileBase .hasVitamin (l ))
403403 mobileBase .addVitamin (l );
404- }catch (Exception ex ) {
404+ } catch (Exception ex ) {
405405 ex .printStackTrace ();
406406 }
407407 }
408408 }
409- for (int i = 0 ; i < limbs .size ();i ++) {
410- AddRobotLimb limb = limbs .get (i );
411- if (mobileBase .getLimbByName (limb .getName ())== null ) {
409+ for (int i = 0 ; i < limbs .size (); i ++) {
410+ AddRobotLimb limb = limbs .get (i );
411+ if (mobileBase .getLimbByName (limb .getName ()) == null ) {
412412 TransformNR location = limb .getLocation ();
413- DHParameterKinematics kin = limb .getLimb ().getLimb (limb .getName ());
413+ DHParameterKinematics kin = limb .getLimb ().getLimb (limb .getName ());
414414 kin .setRobotToFiducialTransform (location .copy ());
415- //TODO add the channel mapping here
415+ // TODO add the channel mapping here
416416 kin .connect ();
417417 kin .zero ();
418- switch (limb .getLimb ().getType ()) {
418+ switch (limb .getLimb ().getType ()) {
419419 case arm :
420420 case flap :
421421 case hand :
@@ -432,20 +432,32 @@ public MobileBase build() throws Exception {
432432 mobileBase .getFixed ().add (kin );
433433 break ;
434434 default :
435- throw new RuntimeException ("Unknown limb type in builder! " + limb .getLimb ().getType ());
435+ throw new RuntimeException ("Unknown limb type in builder! " + limb .getLimb ().getType ());
436436 }
437437 }
438438 }
439- for (int i =0 ;i <mods .size ();i ++) {
440- ModifyLimb mod =mods .get (i );
441- DHParameterKinematics kin =mod .getLimb ();
442- if (kin ==null )
439+ ArrayList <ModifyLimb > toRemove = new ArrayList <ModifyLimb >();
440+ for (int i = 0 ; i < mods .size (); i ++) {
441+ ModifyLimb mod = mods .get (i );
442+ DHParameterKinematics kin = mod .getLimb ();
443+ if (kin == null )
443444 continue ;
445+
444446 TransformNR base = mod .getBase ();
445- System .out .println ("Base set to " +base );
446- kin .setRobotToFiducialTransform (base );
447- kin .setDesiredTaskSpaceTransform (mod .getTip (), 0 );
447+ if (base != null ) {
448+ //System.out.println("Base set to " + base);
449+ kin .setRobotToFiducialTransform (base );
450+ }
451+ if (mod .getTip () != null ) {
452+ try {
453+ kin .setDesiredTaskSpaceTransform (mod .getTip (), 0 );
454+ }catch (Exception ex ) {
455+ ex .printStackTrace ();
456+ toRemove .add (mod );
457+ }
458+ }
448459 }
460+ mods .removeAll (toRemove );
449461 getCadManager ().render ();
450462 // Push to git
451463 ScriptingEngine .pushCodeToGit (gitURL , null , filename , mobileBase .getXml (), "Builder Write XML" , true );
@@ -462,10 +474,10 @@ public void removeController(AddRobotController controller) {
462474 getControllers ().remove (controller );
463475 for (int i = 0 ; i < controllers .size (); i ++) {
464476 AddRobotController con = controllers .get (i );
465- for (VitaminLocation l : con .getVitamins (con .getName ()+ "_" + i )) {
477+ for (VitaminLocation l : con .getVitamins (con .getName () + "_" + i )) {
466478 try {
467479 mobileBase .removeVitamin (l );
468- }catch (Exception ex ) {
480+ } catch (Exception ex ) {
469481 ex .printStackTrace ();
470482 }
471483 }
@@ -475,25 +487,28 @@ public void removeController(AddRobotController controller) {
475487 public ArrayList <AddRobotController > getControllers () {
476488 return controllers ;
477489 }
490+
478491 public ControllerFeatures getCapibilities () {
479492 ControllerFeatures test = new ControllerFeatures ();
480- for (AddRobotController c : controllers ) {
493+ for (AddRobotController c : controllers ) {
481494 test .add (c .getController ().getProvides ());
482495 test .subtract (c .getController ().getConsumes ());
483496 }
484- for (AddRobotLimb c : limbs ) {
497+ for (AddRobotLimb c : limbs ) {
485498 test .add (c .getLimb ().getProvides ());
486499 test .subtract (c .getLimb ().getConsumes ());
487500 }
488501 return test ;
489502 }
503+
490504 public void addLimb (AddRobotLimb controller ) {
491- addLimb (controller ,false );
505+ addLimb (controller , false );
492506 }
507+
493508 public void addLimb (AddRobotLimb controller , boolean forceLoad ) {
494509 LimbOption consumes = controller .getLimb ();
495- if (!checkOptionSupported (consumes ) && !forceLoad ) {
496- throw new RuntimeException ("Robot doesnt have enough resources to support " + controller .getLimb ());
510+ if (!checkOptionSupported (consumes ) && !forceLoad ) {
511+ throw new RuntimeException ("Robot doesnt have enough resources to support " + controller .getLimb ());
497512 }
498513 if (!getLimmbs ().contains (controller ))
499514 getLimmbs ().add (controller );
@@ -502,14 +517,17 @@ public void addLimb(AddRobotLimb controller, boolean forceLoad) {
502517 public boolean checkOptionSupported (LimbOption consumes ) {
503518 return getCapibilities ().check (consumes .consumes );
504519 }
520+
505521 public void addModification (ModifyLimb modifyLimb ) {
506- if (!mods .contains (modifyLimb ))
522+ if (!mods .contains (modifyLimb ))
507523 mods .add (modifyLimb );
508524 }
525+
509526 public void removeModification (ModifyLimb modifyLimb ) {
510- if (mods .contains (modifyLimb ))
527+ if (mods .contains (modifyLimb ))
511528 mods .remove (modifyLimb );
512529 }
530+
513531 public void removeLimb (AddRobotLimb controller ) {
514532 if (getLimmbs ().contains (controller ))
515533 getLimmbs ().remove (controller );
@@ -527,6 +545,4 @@ public MobileBaseCadManager getCadManager() {
527545 return mobileBaseCadManager ;
528546 }
529547
530-
531-
532548}
0 commit comments