Skip to content
Snippets Groups Projects
Commit d776b771 authored by marvin's avatar marvin
Browse files

Added xml tag search function

+javadoc
+search for xml tags
+XPath example
+new jaxen.jar library
parent c7fa79eb
Branches
No related merge requests found
......@@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/jdom-2.0.6.jar"/>
<classpathentry kind="lib" path="lib/jaxen-1.2.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
File added
<?xml version="1.0" encoding="UTF-8"?>
<sdf version="1.5">
<model name="turtlebot3_burger">
<link name="base">
<inertial>
<pose>-0.032 0 0.070 0 0 0</pose>
<inertia>
<ixx>0.001</ixx>
<ixy>0.000</ixy>
<ixz>0.000</ixz>
<iyy>0.001</iyy>
<iyz>0.000</iyz>
<izz>0.001</izz>
</inertia>
<mass>1.0</mass>
</inertial>
<collision name="base_collision">
<pose>-0.032 0 0.070 0 0 0</pose>
<geometry>
<box>
<size>0.140 0.140 0.140</size>
</box>
</geometry>
</collision>
<visual name="base_visual">
<pose>-0.032 0 0 0 0 0</pose>
<geometry>
<mesh>
<uri>model://turtlebot3_burger/meshes/burger_base.dae</uri>
<scale>0.001 0.001 0.001</scale>
</mesh>
</geometry>
</visual>
<collision name="caster_collision">
<pose>-0.081 0 -0.004 0 0 0</pose>
<geometry>
<sphere>
<radius>0.005000</radius>
</sphere>
</geometry>
<surface>
<friction>
<ode>
<mu>100000.0</mu>
<mu2>100000.0</mu2>
<fdir1>0 0 0</fdir1>
<slip1>0</slip1>
<slip2>0</slip2>
</ode>
</friction>
</surface>
</collision>
</link>
<link name="lidar">
<inertial>
<pose>-0.020 0 0.161 0 0 0</pose>
<inertia>
<ixx>0.001</ixx>
<ixy>0.000</ixy>
<ixz>0.000</ixz>
<iyy>0.001</iyy>
<iyz>0.000</iyz>
<izz>0.001</izz>
</inertia>
<mass>0.125</mass>
</inertial>
<collision name="lidar_sensor_collision">
<pose>-0.020 0 0.161 0 0 0</pose>
<geometry>
<cylinder>
<radius>0.0508</radius>
<length>0.055</length>
</cylinder>
</geometry>
</collision>
<visual name="lidar_sensor_visual">
<pose>-0.032 0 0.171 0 0 0</pose>
<geometry>
<mesh>
<uri>model://turtlebot3_burger/meshes/lds.dae</uri>
<scale>0.001 0.001 0.001</scale>
</mesh>
</geometry>
</visual>
<sensor name="hls_lfcd_lds" type="ray">
<always_on>1</always_on>
<visualize>0</visualize>
<pose>-0.032 0 0.171 0 0 0</pose>
<update_rate>1800</update_rate>
<ray>
<scan>
<horizontal>
<samples>360</samples>
<resolution>1.000000</resolution>
<min_angle>0.000000</min_angle>
<max_angle>6.280000</max_angle>
</horizontal>
</scan>
<range>
<min>0.120000</min>
<max>3.5</max>
<resolution>0.015000</resolution>
</range>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.01</stddev>
</noise>
</ray>
</sensor>
</link>
<link name="left_wheel">
<inertial>
<pose>0 0.08 0.023 -1.57 0 0</pose>
<inertia>
<ixx>0.001</ixx>
<ixy>0.000</ixy>
<ixz>0.000</ixz>
<iyy>0.001</iyy>
<iyz>0.000</iyz>
<izz>0.001</izz>
</inertia>
<mass>0.1</mass>
</inertial>
<collision name="left_wheel_collision">
<pose>0 0.08 0.023 -1.57 0 0</pose>
<geometry>
<cylinder>
<radius>0.033</radius>
<length>0.018</length>
</cylinder>
</geometry>
<surface>
<!-- This friction pamareter don't contain reliable data!! -->
<friction>
<ode>
<mu>100000.0</mu>
<mu2>100000.0</mu2>
<fdir1>0 0 0</fdir1>
<slip1>0.0</slip1>
<slip2>0.0</slip2>
</ode>
</friction>
</surface>
</collision>
<visual name="left_wheel_visual">
<pose>0 0.08 0.023 0 0 0</pose>
<geometry>
<mesh>
<uri>model://turtlebot3_burger/meshes/left_tire.dae</uri>
<scale>0.001 0.001 0.001</scale>
</mesh>
</geometry>
</visual>
</link>
<link name="right_wheel">
<inertial>
<pose>0.0 -0.08 0.023 -1.57 0 0</pose>
<inertia>
<ixx>0.001</ixx>
<ixy>0.000</ixy>
<ixz>0.000</ixz>
<iyy>0.001</iyy>
<iyz>0.000</iyz>
<izz>0.001</izz>
</inertia>
<mass>0.1</mass>
</inertial>
<collision name="right_wheel_collision">
<pose>0.0 -0.08 0.023 -1.57 0 0</pose>
<geometry>
<cylinder>
<radius>0.033</radius>
<length>0.018</length>
</cylinder>
</geometry>
<surface>
<!-- This friction pamareter don't contain reliable data!! -->
<friction>
<ode>
<mu>100000.0</mu>
<mu2>100000.0</mu2>
<fdir1>0 0 0</fdir1>
<slip1>0.0</slip1>
<slip2>0.0</slip2>
</ode>
</friction>
</surface>
</collision>
<visual name="right_wheel_visual">
<pose>0.0 -0.08 0.023 0 0 0</pose>
<geometry>
<mesh>
<uri>model://turtlebot3_burger/meshes/right_tire.dae</uri>
<scale>0.001 0.001 0.001</scale>
</mesh>
</geometry>
</visual>
</link>
<joint name="left_wheel_joint" type="revolute">
<parent>base</parent>
<child>left_wheel</child>
<pose>0.0 0.08 0.023 -1.57 0 0</pose>
<axis>
<xyz>0 1 0</xyz>
</axis>
</joint>
<joint name="right_wheel_joint" type="revolute">
<parent>base</parent>
<child>right_wheel</child>
<pose>0.0 -0.08 0.023 -1.57 0 0</pose>
<axis>
<xyz>0 1 0</xyz>
</axis>
</joint>
<joint name="lidar_joint" type="fixed">
<parent>base</parent>
<child>lidar</child>
<pose>-0.032 0 0.171 0 0 0</pose>
<axis>
<xyz>0 0 1</xyz>
<use_parent_model_frame>true</use_parent_model_frame>
</axis>
</joint>
<static>0</static>
</model>
</sdf>
<?xml version="1.0" encoding="UTF-8"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro" name="turtlebot3_burger_sim">
<xacro:arg name="laser_visual" default="false" />
<xacro:arg name="imu_visual" default="false" />
<gazebo reference="base_link">
<material>Gazebo/DarkGrey</material>
</gazebo>
<gazebo reference="wheel_left_link">
<mu1>0.1</mu1>
<mu2>0.1</mu2>
<kp>500000.0</kp>
<kd>10.0</kd>
<minDepth>0.001</minDepth>
<maxVel>0.1</maxVel>
<fdir1>1 0 0</fdir1>
<material>Gazebo/FlatBlack</material>
</gazebo>
<gazebo reference="wheel_right_link">
<mu1>0.1</mu1>
<mu2>0.1</mu2>
<kp>500000.0</kp>
<kd>10.0</kd>
<minDepth>0.001</minDepth>
<maxVel>0.1</maxVel>
<fdir1>1 0 0</fdir1>
<material>Gazebo/FlatBlack</material>
</gazebo>
<gazebo reference="caster_back_link">
<mu1>0.1</mu1>
<mu2>0.1</mu2>
<kp>1000000.0</kp>
<kd>100.0</kd>
<minDepth>0.001</minDepth>
<maxVel>1.0</maxVel>
<material>Gazebo/FlatBlack</material>
</gazebo>
<gazebo reference="imu_link">
<sensor type="imu" name="imu">
<always_on>true</always_on>
<visualize>$(arg imu_visual)</visualize>
</sensor>
<material>Gazebo/FlatBlack</material>
</gazebo>
<gazebo>
<plugin name="turtlebot3_burger_controller" filename="libgazebo_ros_diff_drive.so">
<commandTopic>cmd_vel</commandTopic>
<odometryTopic>odom</odometryTopic>
<odometryFrame>odom</odometryFrame>
<odometrySource>world</odometrySource>
<publishOdomTF>true</publishOdomTF>
<robotBaseFrame>base_footprint</robotBaseFrame>
<publishWheelTF>false</publishWheelTF>
<publishTf>true</publishTf>
<publishWheelJointState>true</publishWheelJointState>
<legacyMode>false</legacyMode>
<updateRate>30</updateRate>
<leftJoint>wheel_left_joint</leftJoint>
<rightJoint>wheel_right_joint</rightJoint>
<wheelSeparation>0.160</wheelSeparation>
<wheelDiameter>0.066</wheelDiameter>
<wheelAcceleration>1</wheelAcceleration>
<wheelTorque>10</wheelTorque>
<rosDebugLevel>na</rosDebugLevel>
</plugin>
</gazebo>
<gazebo>
<plugin name="imu_plugin" filename="libgazebo_ros_imu.so">
<alwaysOn>true</alwaysOn>
<bodyName>imu_link</bodyName>
<frameName>imu_link</frameName>
<topicName>imu</topicName>
<serviceName>imu_service</serviceName>
<gaussianNoise>0.0</gaussianNoise>
<updateRate>200</updateRate>
<imu>
<noise>
<type>gaussian</type>
<rate>
<mean>0.0</mean>
<stddev>2e-4</stddev>
<bias_mean>0.0000075</bias_mean>
<bias_stddev>0.0000008</bias_stddev>
</rate>
<accel>
<mean>0.0</mean>
<stddev>1.7e-2</stddev>
<bias_mean>0.1</bias_mean>
<bias_stddev>0.001</bias_stddev>
</accel>
</noise>
</imu>
</plugin>
</gazebo>
<gazebo reference="base_scan">
<material>Gazebo/FlatBlack</material>
<sensor type="ray" name="lds_lfcd_sensor">
<pose>0 0 0 0 0 0</pose>
<visualize>$(arg laser_visual)</visualize>
<update_rate>5</update_rate>
<ray>
<scan>
<horizontal>
<samples>360</samples>
<resolution>1</resolution>
<min_angle>0.0</min_angle>
<max_angle>6.28319</max_angle>
</horizontal>
</scan>
<range>
<min>0.120</min>
<max>3.5</max>
<resolution>0.015</resolution>
</range>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.01</stddev>
</noise>
</ray>
<plugin name="gazebo_ros_lds_lfcd_controller" filename="libgazebo_ros_laser.so">
<topicName>scan</topicName>
<frameName>base_scan</frameName>
</plugin>
</sensor>
</gazebo>
</robot>
......@@ -2,8 +2,10 @@ import java.io.*;
import java.util.*;
import org.jdom2.*;
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.XMLOutputter;
import org.jdom2.xpath.*;
......@@ -14,61 +16,37 @@ import org.jdom2.output.XMLOutputter;
* featuremodel.xml file.
*/
public class Adapter {
// //TODO
// public List<Element> searchTagBelow(Element element) {
// List<Element> childList = element.getChildren();
// Iterator<Element> iterator = childList.iterator();
// List<Element> resultList = new ArrayList<Element>();
//
// while (iterator.hasNext()) {
// if(element.getTextNormalize())
// searchTagBelow(element, resultList);
// }
//
// return resultList;
// }
// //TODO
// private List<Element> searchTagBelow(Element element,List<Element> resultList) {
//
// return resultList;
// }
//TODO
public static List<Element> searchTagBelow(Element element, String tagName) {
List<Element> childList = element.getChildren();
Iterator<Element> iterator = childList.iterator();
List<Element> resultList = new ArrayList<Element>();
if(element.getName().equals(tagName)) {
resultList.add(element);
}
/**
* Searches a document for the first occurrence of an xml tag using XPath.
*
* @param doc The JDOM Document
* @param elementName Name of the xml tag
* @return First element found or NULL if no match found
*/
public static Element queryFirstElement(Document doc, String elementName) {
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expr = xFactory.compile("//"+elementName, Filters.element());
Element result = expr.evaluateFirst(doc);
while (iterator.hasNext()) {
Element nextElement= iterator.next();
searchTagBelow(nextElement, tagName, resultList);
}
return resultList;
return result;
}
//TODO
private static List<Element> searchTagBelow(Element element, String tagName, List<Element> resultList) {
List<Element> childList = element.getChildren();
Iterator<Element> iterator = childList.iterator();
if(element.getName().equals(tagName)) {
resultList.add(element);
}
/**
* Searches a document for all occurrences of an xml tag using XPath.
*
* @param doc The JDOM Document
* @param elementName Name of the xml tag
* @return List with all elements found or empty List if no match found
*/
public static List<Element> queryAllElements(Document doc, String elementName) {
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expr = xFactory.compile("//"+elementName, Filters.element());
List<Element> result = expr.evaluate(doc);
while (iterator.hasNext()) {
Element nextElement= iterator.next();
searchTagBelow(nextElement, tagName, resultList);
}
return resultList;
return result;
}
/**
* @param args
*/
......@@ -80,27 +58,39 @@ public class Adapter {
Document FeatureModel = saxBuilder.build(srcFeatureModel);
Document GazeboModel = saxBuilder.build(srcGazeboModel);
//TODO operate on featuremodel.xml
Element specification = FeatureModel.getRootElement();
List<Element> modules = specification.getChildren("module");
//TODO
//######### Operate on featuremodel.xml #########
Element fmRoot = FeatureModel.getRootElement();
List<Element> modules = fmRoot.getChildren("module");
//###############################################
//TODO operate on .gazebo.xacro
Element test = GazeboModel.getRootElement();
List<Element> jointListTest = searchTagBelow(test, "min");
for(int i = 0; i < jointListTest.size(); i++) {
System.out.println(jointListTest.get(i));
}
//TODO
//######### Operate on .gazebo.xacro ############
Element gmRoot = GazeboModel.getRootElement();
//XPathExamples
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expr = xFactory.compile("robot/gazebo/sensor/ray/range/min", Filters.element());
Element test = expr.evaluateFirst(GazeboModel);
List<Element> test2 = queryAllElements(GazeboModel, "min");
List<Element> test3 = queryAllElements(GazeboModel, "max");
//###############################################
FileOutputStream dest = new FileOutputStream("resources/output/turtlebot3_burger.gazebo.xacro");
XMLOutputter xmlOutput = new XMLOutputter();
//xmlOutput.output(GazeboModel, System.out);
//TODO
//######### Output result #######################
xmlOutput.output(GazeboModel, dest);
//XPathExamples
if(test != null) xmlOutput.output(test, System.out);
System.out.println();
xmlOutput.output(test2, System.out);
System.out.println();
xmlOutput.output(test3, System.out);
//###############################################
} catch (JDOMException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment