diff --git a/Varianten/AdapterFIDEROS/resources/input/model.xml b/Varianten/AdapterFIDEROS/resources/input/model.xml index 86ffb18dfd70ff8b3d9ddc68f6f8bd50a49a7091..8ceda5a07b9259b913513195aeac96de7d60e6c6 100644 --- a/Varianten/AdapterFIDEROS/resources/input/model.xml +++ b/Varianten/AdapterFIDEROS/resources/input/model.xml @@ -11,27 +11,24 @@ </properties> <struct> <and abstract="true" mandatory="true" name="CarConfigurator"> - <alt mandatory="true" name="ConfiguratorMain"> + <and mandatory="true" name="ConfiguratorMain"> <alt abstract="true" name="TurtleBot"> <feature name="Burger"/> <feature name="Waffle"/> <feature name="WafflePi"/> - </alt> - <and abstract="true" name="CustomBot"> - <alt abstract="true" name="Camera"> - <feature name="Cam1"/> - <feature name="Cam2"/> - </alt> - <and abstract="true" name="NonOpticalSensor"> - <graphics key="collapsed" value="false"/> - <alt abstract="true" mandatory="true" name="Radar"> + <and abstract="true" name="CustomBot"> + <and abstract="true" name="RangeFinder"> <graphics key="collapsed" value="false"/> - <feature name="Radar1"/> - <feature name="Radar2"/> - </alt> + <alt abstract="true" mandatory="true" name="TwoDRF"> + <graphics key="collapsed" value="false"/> + <feature name="Sensor1"/> + <feature name="Sensor2"/> + <feature name="CustomTwoDRF"/> + </alt> + </and> </and> - </and> - </alt> + </alt> + </and> </and> </struct> </featureModel> diff --git a/Varianten/AdapterFIDEROS/resources/input/model_old.xml b/Varianten/AdapterFIDEROS/resources/input/model_old.xml new file mode 100644 index 0000000000000000000000000000000000000000..86ffb18dfd70ff8b3d9ddc68f6f8bd50a49a7091 --- /dev/null +++ b/Varianten/AdapterFIDEROS/resources/input/model_old.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<featureModel> + <properties> + <graphics key="showhiddenfeatures" value="true"/> + <graphics key="legendautolayout" value="true"/> + <graphics key="showshortnames" value="false"/> + <graphics key="layout" value="horizontal"/> + <graphics key="showcollapsedconstraints" value="true"/> + <graphics key="legendhidden" value="false"/> + <graphics key="layoutalgorithm" value="1"/> + </properties> + <struct> + <and abstract="true" mandatory="true" name="CarConfigurator"> + <alt mandatory="true" name="ConfiguratorMain"> + <alt abstract="true" name="TurtleBot"> + <feature name="Burger"/> + <feature name="Waffle"/> + <feature name="WafflePi"/> + </alt> + <and abstract="true" name="CustomBot"> + <alt abstract="true" name="Camera"> + <feature name="Cam1"/> + <feature name="Cam2"/> + </alt> + <and abstract="true" name="NonOpticalSensor"> + <graphics key="collapsed" value="false"/> + <alt abstract="true" mandatory="true" name="Radar"> + <graphics key="collapsed" value="false"/> + <feature name="Radar1"/> + <feature name="Radar2"/> + </alt> + </and> + </and> + </alt> + </and> + </struct> +</featureModel> diff --git a/Varianten/AdapterFIDEROS/resources/input/sensorconfig.xml b/Varianten/AdapterFIDEROS/resources/input/sensorconfig.xml index 4bb7afbe70eea0b88ca3b40489014fc55a7a4fbc..940d688f6e21a385f546ab51f3c628388f51035a 100644 --- a/Varianten/AdapterFIDEROS/resources/input/sensorconfig.xml +++ b/Varianten/AdapterFIDEROS/resources/input/sensorconfig.xml @@ -5,5 +5,8 @@ <min>0.3</min> <max>5.2</max> </range> + <noise> + <stddev>0.09</stddev> + </noise> </sensor> </configuration> diff --git a/Varianten/AdapterFIDEROS/resources/output/turtlebot3_burger.gazebo.xacro b/Varianten/AdapterFIDEROS/resources/output/turtlebot3_burger.gazebo.xacro index fa705c3812371f5c3511c419f8a9bf7ea7c74273..db59909444c0a2b3ca9406381ba40019ba288296 100644 --- a/Varianten/AdapterFIDEROS/resources/output/turtlebot3_burger.gazebo.xacro +++ b/Varianten/AdapterFIDEROS/resources/output/turtlebot3_burger.gazebo.xacro @@ -115,8 +115,8 @@ </horizontal> </scan> <range> - <min>0.3</min> - <max>5.2</max> + <min>0.120</min> + <max>3.5</max> <resolution>0.015</resolution> </range> <noise> diff --git a/Varianten/AdapterFIDEROS/src/Adapter.java b/Varianten/AdapterFIDEROS/src/Adapter.java index 38c46eea599be840467f081ad56da8e44e25024a..20e7dd67147f65e377669cd1e66b041a43cd8f3b 100644 --- a/Varianten/AdapterFIDEROS/src/Adapter.java +++ b/Varianten/AdapterFIDEROS/src/Adapter.java @@ -89,6 +89,23 @@ public class Adapter { return xQueryElements(doc, "//"+elementName); } + /** + * Checks whether two elements have an equal xml tag. + * (Name of the xml tag and all attributes including their order must be equal) + * + * @param element1 Element1 + * @param element2 Element2 + * @return true if of equal tag or false if not + */ + public static boolean equalTag(Element element1, Element element2) { + List<Attribute> attributeList1 = element1.getAttributes(); + List<Attribute> attributeList2 = element2.getAttributes(); + + if(!element1.getName().equals(element2.getName())) return false; + if(!attributeList1.equals(attributeList2)) return false; + return true; + } + /** * @param args */ @@ -135,19 +152,38 @@ public class Adapter { //TODO##### Operate on .gazebo.xacro ############ + List<Element> cSensorList = xQueryElements(sensorConfig, "//sensor"); + List<Element> gSensorList = xQueryElements(gazeboModel, "//sensor"); - //hard-coded and only for demo purposes - List<Element> cSensorList = xQueryElements(sensorConfig, "//sensor[@type='ray' and @name='lds_lfcd_sensor']"); - Element cSensor = cSensorList.get(0); + if(cSensorList.isEmpty()) { + System.out.println("No new sensor values in sensorconfig.xml"); + System.exit(-1); + } + if(gSensorList.isEmpty()) { + System.out.println("No sensors found in "+fileName); + System.exit(-1); + } - List<Element> gSensorList = xQueryElements(gazeboModel, "//sensor[@type='ray' and @name='lds_lfcd_sensor']"); - Element gSensor = gSensorList.get(0); - - String new_min = cSensor.getChild("range").getChild("min").getText(); - String new_max = cSensor.getChild("range").getChild("max").getText(); + for(Element cSensor : cSensorList) { + for(Element gSensor : gSensorList) { + if(equalTag(cSensor, gSensor)) { + //TODO automatischer Abgleich aller cSensor-Informationen mit gSensor und Wertersetzung + } + } + } - gSensor.getChild("ray").getChild("range").getChild("min").setText(new_min); - gSensor.getChild("ray").getChild("range").getChild("max").setText(new_max); + //hard-coded and only for demo purposes +// List<Element> cSensorList = xQueryElements(sensorConfig, "//sensor[@type='ray' and @name='lds_lfcd_sensor']"); +// Element cSensor = cSensorList.get(0); +// +// List<Element> gSensorList = xQueryElements(gazeboModel, "//sensor[@type='ray' and @name='lds_lfcd_sensor']"); +// Element gSensor = gSensorList.get(0); +// +// String new_min = cSensor.getChild("range").getChild("min").getText(); +// String new_max = cSensor.getChild("range").getChild("max").getText(); +// +// gSensor.getChild("ray").getChild("range").getChild("min").setText(new_min); +// gSensor.getChild("ray").getChild("range").getChild("max").setText(new_max); //############################################### @@ -160,23 +196,23 @@ public class Adapter { //XPathExamples - XPathFactory xFactory = XPathFactory.instance(); - XPathExpression<Element> xExpr = xFactory.compile("robot/gazebo/sensor/ray/range/min", Filters.element()); - Element test = xExpr.evaluateFirst(gazeboModel); - List<Element> test2 = searchAllElements(gazeboModel, "min"); - List<Element> test3 = searchAllElements(gazeboModel, "max"); - Element test4 = searchFirstElement(gazeboModel, "plugin"); - List<Attribute> test5 = xQueryAttributes(gazeboModel, "(//plugin)[1]/@*"); - - if(test != null) xmlOutput.output(test, System.out); - System.out.println("\n"); - xmlOutput.output(test2, System.out); - System.out.println("\n"); - xmlOutput.output(test3, System.out); - System.out.println("\n"); - if(test4 != null) xmlOutput.output(test4, System.out); - System.out.println("\n"); - for(Attribute a : test5) System.out.println(a.getName()+"="+a.getValue()); +// XPathFactory xFactory = XPathFactory.instance(); +// XPathExpression<Element> xExpr = xFactory.compile("robot/gazebo/sensor/ray/range/min", Filters.element()); +// Element test = xExpr.evaluateFirst(gazeboModel); +// List<Element> test2 = searchAllElements(gazeboModel, "min"); +// List<Element> test3 = searchAllElements(gazeboModel, "max"); +// Element test4 = searchFirstElement(gazeboModel, "plugin"); +// List<Attribute> test5 = xQueryAttributes(gazeboModel, "(//plugin)[1]/@*"); +// +// if(test != null) xmlOutput.output(test, System.out); +// System.out.println("\n"); +// xmlOutput.output(test2, System.out); +// System.out.println("\n"); +// xmlOutput.output(test3, System.out); +// System.out.println("\n"); +// if(test4 != null) xmlOutput.output(test4, System.out); +// System.out.println("\n"); +// for(Attribute a : test5) System.out.println(a.getName()+"="+a.getValue()); } catch (JDOMException | IOException e) { e.printStackTrace();