Skip to content

Commit 1b80998

Browse files
committed
Loading the mass of the body from the xml wthout getting confused by the
sub-nodes
1 parent 9c8d4a5 commit 1b80998

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

carlRobot.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@
876876
<roty>0.0</roty>
877877
<rotz>0.0</rotz>
878878
</baseToZframe>
879-
<mass>0.01</mass>
879+
<mass>99</mass>
880880
<centerOfMassFromCentroid> <x>0.0</x>
881881
<y>0.0</y>
882882
<z>0.0</z>

src/main/java/com/neuronrobotics/sdk/addons/kinematics/MobileBase.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void loadConfigs(Element doc) {
187187
loadLimb(doc, "steerable", steerable);
188188
loadLimb(doc, "appendage", appendages);
189189
try {
190-
String massString = XmlFactory.getTagValue("mass", doc);
190+
String massString =getTag(doc,"mass");
191191
setMassKg(Double.parseDouble(massString));
192192
} catch (Exception e) {
193193
e.printStackTrace();
@@ -263,7 +263,7 @@ private String getname(Element e) {
263263
* @param tag
264264
* the tag
265265
* @return the name
266-
*/
266+
*/
267267
private String getParallelGroup(Element e) {
268268
return getTag(e, "parallelGroup");
269269
}
@@ -279,12 +279,18 @@ private String getParallelGroup(Element e) {
279279
*/
280280
private String getTag(Element e, String tagname) {
281281
try {
282-
NodeList nodListofLinks = e.getChildNodes();
282+
NodeList nodListofLinks = e.getElementsByTagName(tagname);
283283

284284
for (int i = 0; i < nodListofLinks.getLength(); i++) {
285285
Node linkNode = nodListofLinks.item(i);
286-
if (linkNode.getNodeType() == Node.ELEMENT_NODE && linkNode.getNodeName().contentEquals(tagname)) {
287-
return XmlFactory.getTagValue(tagname, e);
286+
String nameParent = linkNode.getParentNode().getNodeName();
287+
boolean isMobileBase = nameParent.contains("mobilebase");
288+
if (linkNode.getNodeType() == Node.ELEMENT_NODE &&
289+
linkNode.getNodeName().contentEquals(tagname)
290+
&& isMobileBase) {
291+
String value = linkNode.getChildNodes().item(0).getNodeValue();
292+
System.out.println("Loading tag "+tagname+" from "+nameParent+" value "+value);
293+
return value;
288294
}
289295
}
290296
} catch (Exception ex) {
@@ -769,6 +775,7 @@ public double getMassKg() {
769775
}
770776

771777
public void setMassKg(double mass) {
778+
System.out.println("Mass of device "+getScriptingName()+" is "+mass);
772779
this.mass = mass;
773780
}
774781

src/main/java/com/neuronrobotics/sdk/addons/kinematics/xml/XmlFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static NodeList getAllNodesFromTag(String sTag, InputStream config){
7575
* @return the tag value
7676
*/
7777
public static String getTagValue(String sTag, Element eElement){
78+
7879
NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
7980
Node nValue = (Node) nlList.item(0);
8081
// System.out.println("\t\t"+sTag+" = "+nValue.getNodeValue());
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package junit.test.neuronrobotics.utilities;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.io.File;
6+
import java.io.FileInputStream;
7+
import java.io.FileNotFoundException;
8+
9+
import org.junit.Test;
10+
11+
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
12+
13+
public class LoadMassTest {
14+
15+
@Test
16+
public void test() throws FileNotFoundException {
17+
18+
File f = new File("carlRobot.xml");
19+
if (f.exists()) {
20+
MobileBase pArm = new MobileBase(new FileInputStream(f));
21+
System.out.println("Mass = "+pArm.getMassKg());
22+
assertEquals(99, pArm.getMassKg(),0.1);
23+
}
24+
}
25+
26+
}

0 commit comments

Comments
 (0)