From 9df72f6db4b3738bf67de49b4a5aede3101a8766 Mon Sep 17 00:00:00 2001 From: marvin <marvin@marvin-TERRA-MOBILE-1529H> Date: Thu, 19 Mar 2020 16:25:28 +0100 Subject: [PATCH] Refactoring of Adapter, ModelSetup, SensorconfigSetup (and bugfix in XMLHelper.findFile) --- .../urdf/turtlebot3_burger.gazebo.xacro | 2 +- .../urdf/turtlebot3_burger.urdf.xacro | 3 +- .../urdf/turtlebot3_waffle.urdf.xacro | 2 +- .../urdf/turtlebot3_waffle_pi.urdf.xacro | 2 +- .../common_properties.xacro | 44 --- .../turtlebot3_burger.gazebo.xacro | 135 ------- .../turtlebot3_burger.gazeboSafety.xacro | 135 ------- .../turtlebot3_burger.urdf.xacro | 166 -------- .../turtlebot3_burgerSafety.urdf.xacro | 165 -------- ...urtlebot3_burger_for_autorace.gazebo.xacro | 169 -------- .../turtlebot3_burger_for_autorace.urdf.xacro | 194 ---------- .../turtlebot3_burgertest1.gazebo.xacro | 135 ------- .../turtlebot3_burgertest1.urdf.xacro | 162 -------- .../turtlebot3_waffle.gazebo.xacro | 190 --------- .../turtlebot3_waffle.urdf.xacro | 251 ------------ ...ot3_waffle_for_open_manipulator.urdf.xacro | 251 ------------ .../turtlebot3_waffle_pi.gazebo.xacro | 180 --------- .../turtlebot3_waffle_pi.urdf.xacro | 217 ----------- ..._waffle_pi_for_open_manipulator.urdf.xacro | 217 ----------- .../features/ConfiguratorMain/Adapter.java | 360 ++++-------------- .../ConfiguratorMain/BotNameAdapter.java | 67 ++++ .../ConfiguratorMain/Configurator.jak | 15 +- .../ConfiguratorMain/GazeboAdapter.java | 155 ++++++++ .../ConfiguratorMain/UrdfAdapter.java | 136 +++++++ .../ConfiguratorMain/UserSetIOReader.java | 88 +++++ .../features/ConfiguratorMain/XMLHelper.java | 27 +- .../lds_lfcd_sensor___turtlebot3_burger.xml | 2 +- .../FeatureModelConfigurator/src/Adapter.java | 360 ++++-------------- .../src/BotNameAdapter.java | 67 ++++ .../src/Configurator.jak | 15 +- .../src/Configurator.java | 15 +- .../src/GazeboAdapter.java | 155 ++++++++ .../src/UrdfAdapter.java | 136 +++++++ .../src/UserSetIOReader.java | 88 +++++ .../src/XMLHelper.java | 27 +- .../modelsetup.config | 19 - .../src/Adapter.java | 360 ++++-------------- .../src/BotNameAdapter.java | 67 ++++ .../src/GazeboAdapter.java | 155 ++++++++ .../src/ImplGenerator.java | 69 ++-- .../src/ModelSetup.java | 330 ++++++++-------- .../src/SensorConfigSetup.java | 275 ++++++------- .../FeatureModelImplGenerator/src/Setup.java | 30 ++ .../src/UrdfAdapter.java | 136 +++++++ .../src/UserSetIOReader.java | 88 +++++ .../src/XMLHelper.java | 27 +- .../template/Main.jak | 15 +- .../adapter.config => usersetio.config} | 17 +- 48 files changed, 2048 insertions(+), 3873 deletions(-) delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/common_properties.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazebo.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazeboSafety.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.urdf.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgerSafety.urdf.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.gazebo.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.urdf.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.gazebo.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.urdf.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.gazebo.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.urdf.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_for_open_manipulator.urdf.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.gazebo.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.urdf.xacro delete mode 100644 src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi_for_open_manipulator.urdf.xacro create mode 100644 src/var/FeatureModelConfigurator/features/ConfiguratorMain/BotNameAdapter.java create mode 100644 src/var/FeatureModelConfigurator/features/ConfiguratorMain/GazeboAdapter.java create mode 100644 src/var/FeatureModelConfigurator/features/ConfiguratorMain/UrdfAdapter.java create mode 100644 src/var/FeatureModelConfigurator/features/ConfiguratorMain/UserSetIOReader.java create mode 100644 src/var/FeatureModelConfigurator/src/BotNameAdapter.java create mode 100644 src/var/FeatureModelConfigurator/src/GazeboAdapter.java create mode 100644 src/var/FeatureModelConfigurator/src/UrdfAdapter.java create mode 100644 src/var/FeatureModelConfigurator/src/UserSetIOReader.java delete mode 100644 src/var/FeatureModelImplGenerator/modelsetup.config create mode 100644 src/var/FeatureModelImplGenerator/src/BotNameAdapter.java create mode 100644 src/var/FeatureModelImplGenerator/src/GazeboAdapter.java create mode 100644 src/var/FeatureModelImplGenerator/src/Setup.java create mode 100644 src/var/FeatureModelImplGenerator/src/UrdfAdapter.java create mode 100644 src/var/FeatureModelImplGenerator/src/UserSetIOReader.java rename src/var/{FeatureModelConfigurator/adapter.config => usersetio.config} (62%) diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.gazebo.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.gazebo.xacro index 79722dd..817e798 100644 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.gazebo.xacro +++ b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.gazebo.xacro @@ -116,7 +116,7 @@ </scan> <range> <min>0.120</min> - <max>16</max> + <max>3.5</max> <resolution>0.015</resolution> </range> <noise> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.urdf.xacro index c8b1e55..c63d8c6 100644 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.urdf.xacro +++ b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.urdf.xacro @@ -1,7 +1,8 @@ <?xml version="1.0" ?> <robot name="turtlebot3_burger" xmlns:xacro="http://ros.org/wiki/xacro"> <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find sim)/bot.gazebo.xacro"/> + <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_burger.gazebo.xacro"/> + <link name="base_footprint"/> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle.urdf.xacro index 351b1b4..ee23268 100644 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle.urdf.xacro +++ b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle.urdf.xacro @@ -1,7 +1,7 @@ <?xml version="1.0" ?> <robot name="turtlebot3_waffle" xmlns:xacro="http://ros.org/wiki/xacro"> <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find sim)/bot.gazebo.xacro"/> + <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_waffle.gazebo.xacro"/> <xacro:property name="r200_cam_rgb_px" value="0.005"/> <xacro:property name="r200_cam_rgb_py" value="0.018"/> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle_pi.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle_pi.urdf.xacro index e9995c5..46cf4a9 100644 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle_pi.urdf.xacro +++ b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle_pi.urdf.xacro @@ -1,7 +1,7 @@ <?xml version="1.0" ?> <robot name="turtlebot3_waffle_pi" xmlns:xacro="http://ros.org/wiki/xacro"> <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find sim)/bot.gazebo.xacro"/> + <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_waffle_pi.gazebo.xacro"/> <link name="base_footprint"/> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/common_properties.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/common_properties.xacro deleted file mode 100644 index b26a853..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/common_properties.xacro +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" ?> - -<robot name="xacro_properties" xmlns:xacro="http://ros.org/wiki/xacro"> - - <!-- Init colour --> - <material name="black"> - <color rgba="0.0 0.0 0.0 1.0"/> - </material> - - <material name="dark"> - <color rgba="0.3 0.3 0.3 1.0"/> - </material> - <material name="light_black"> - <color rgba="0.4 0.4 0.4 1.0"/> - </material> - - <material name="blue"> - <color rgba="0.0 0.0 0.8 1.0"/> - </material> - - <material name="green"> - <color rgba="0.0 0.8 0.0 1.0"/> - </material> - - <material name="grey"> - <color rgba="0.5 0.5 0.5 1.0"/> - </material> - - <material name="orange"> - <color rgba="${255/255} ${108/255} ${10/255} 1.0"/> - </material> - - <material name="brown"> - <color rgba="${222/255} ${207/255} ${195/255} 1.0"/> - </material> - - <material name="red"> - <color rgba="0.8 0.0 0.0 1.0"/> - </material> - - <material name="white"> - <color rgba="1.0 1.0 1.0 1.0"/> - </material> -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazebo.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazebo.xacro deleted file mode 100644 index 817e798..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazebo.xacro +++ /dev/null @@ -1,135 +0,0 @@ -<?xml version="1.0"?> -<robot name="turtlebot3_burger_sim" xmlns:xacro="http://ros.org/wiki/xacro"> - <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> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazeboSafety.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazeboSafety.xacro deleted file mode 100644 index ca205cd..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.gazeboSafety.xacro +++ /dev/null @@ -1,135 +0,0 @@ -<?xml version="1.0"?> -<robot name="turtlebot3_burger_sim" xmlns:xacro="http://ros.org/wiki/xacro"> - <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>8</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> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.urdf.xacro deleted file mode 100644 index c63d8c6..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger.urdf.xacro +++ /dev/null @@ -1,166 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_burger" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_burger.gazebo.xacro"/> - - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link"/> - <origin xyz="0.0 0.0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.032 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/burger_base.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.032 0 0.070" rpy="0 0 0"/> - <geometry> - <box size="0.140 0.140 0.143"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="8.2573504e-01"/> - <inertia ixx="2.2124416e-03" ixy="-1.2294101e-05" ixz="3.4938785e-05" - iyy="2.1193702e-03" iyz="-5.0120904e-06" - izz="2.0064271e-03" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.08 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.080 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_link"/> - <origin xyz="-0.081 0 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="-0.032 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.032 0 0.172" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/> - <geometry> - <cylinder length="0.0315" radius="0.055"/> - </geometry> - </collision> - - <inertial> - <mass value="0.114" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgerSafety.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgerSafety.urdf.xacro deleted file mode 100644 index d066759..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgerSafety.urdf.xacro +++ /dev/null @@ -1,165 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_burger" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_burger.gazebo.xacro"/> - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link"/> - <origin xyz="0.0 0.0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.032 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/burger_base.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.032 0 0.070" rpy="0 0 0"/> - <geometry> - <box size="0.140 0.140 0.143"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="8.2573504e-01"/> - <inertia ixx="2.2124416e-03" ixy="-1.2294101e-05" ixz="3.4938785e-05" - iyy="2.1193702e-03" iyz="-5.0120904e-06" - izz="2.0064271e-03" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.08 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.080 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_link"/> - <origin xyz="-0.081 0 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="-0.032 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.032 0 0.172" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/> - <geometry> - <cylinder length="0.0315" radius="0.055"/> - </geometry> - </collision> - - <inertial> - <mass value="0.114" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.gazebo.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.gazebo.xacro deleted file mode 100644 index 9ea2980..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.gazebo.xacro +++ /dev/null @@ -1,169 +0,0 @@ -<?xml version="1.0"?> -<robot name="turtlebot3_burger_for_autorace_sim" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:arg name="laser_visual" default="false"/> - <xacro:arg name="camera_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> - <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> - - <!--link : https://www.raspberrypi.org/documentation/hardware/camera/--> - <gazebo reference="camera_rgb_frame"> - <sensor type="camera" name="Pi Camera"> - <always_on>true</always_on> - <visualize>$(arg camera_visual)</visualize> - <camera> - <horizontal_fov>1.085595</horizontal_fov> - <image> - <width>320</width> - <height>240</height> - <format>R8G8B8</format> - </image> - <clip> - <near>0.03</near> - <far>100</far> - </clip> - </camera> - <plugin name="camera_controller" filename="libgazebo_ros_camera.so"> - <alwaysOn>true</alwaysOn> - <updateRate>30.0</updateRate> - <cameraName>camera</cameraName> - <frameName>camera_rgb_optical_frame</frameName> - <imageTopicName>image</imageTopicName> - <cameraInfoTopicName>camera_info</cameraInfoTopicName> - <hackBaseline>0.07</hackBaseline> - <distortionK1>0.0</distortionK1> - <distortionK2>0.0</distortionK2> - <distortionK3>0.0</distortionK3> - <distortionT1>0.0</distortionT1> - <distortionT2>0.0</distortionT2> - </plugin> - </sensor> - </gazebo> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.urdf.xacro deleted file mode 100644 index e647f37..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burger_for_autorace.urdf.xacro +++ /dev/null @@ -1,194 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_burger_for_autorace" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_burger_for_autorace.gazebo.xacro"/> - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link"/> - <origin xyz="0.0 0.0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.032 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/burger_base.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.032 0 0.070" rpy="0 0 0"/> - <geometry> - <box size="0.140 0.140 0.143"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="8.2573504e-01"/> - <inertia ixx="2.2124416e-03" ixy="-1.2294101e-05" ixz="3.4938785e-05" - iyy="2.1193702e-03" iyz="-5.0120904e-06" - izz="2.0064271e-03" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.08 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.080 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_link"/> - <origin xyz="-0.081 0 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="-0.032 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.032 0 0.172" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/> - <geometry> - <cylinder length="0.0315" radius="0.055"/> - </geometry> - </collision> - - <inertial> - <mass value="0.114" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="camera_joint" type="fixed"> - <origin xyz="0.040 -0.011 0.130" rpy="0 0.174 0"/> - <parent link="base_link"/> - <child link="camera_link"/> - </joint> - - <link name="camera_link"> - <collision> - <origin xyz="0.005 0.011 0.013" rpy="0 0 0"/> - <geometry> - <box size="0.015 0.030 0.027"/> - </geometry> - </collision> - </link> - - <joint name="camera_rgb_joint" type="fixed"> - <origin xyz="0.003 0.011 0.009" rpy="0 0 0"/> - <parent link="camera_link"/> - <child link="camera_rgb_frame"/> - </joint> - <link name="camera_rgb_frame"/> - - <joint name="camera_rgb_optical_joint" type="fixed"> - <origin xyz="0 0 0" rpy="-1.57 0 -1.57"/> - <parent link="camera_rgb_frame"/> - <child link="camera_rgb_optical_frame"/> - </joint> - <link name="camera_rgb_optical_frame"/> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.gazebo.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.gazebo.xacro deleted file mode 100644 index a014212..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.gazebo.xacro +++ /dev/null @@ -1,135 +0,0 @@ -<?xml version="1.0"?> -<robot name="turtlebot3_burger_sim" xmlns:xacro="http://ros.org/wiki/xacro"> - <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="gpu_ray" name="head_rplidar_sensor"> - <pose>0 0 0.06 0 0 0</pose> - <visualize>false</visualize> - <update_rate>40</update_rate> - <ray> - <scan> - <horizontal> - <samples>720</samples> - <resolution>1</resolution> - <min_angle>-3.14159265</min_angle> - <max_angle>3.14159265</max_angle> - </horizontal> - </scan> - <range> - <min>0.2</min> - <max>30.0</max> - <resolution>0.01</resolution> - </range> - <noise> - <type>gaussian</type> - <mean>0.0</mean> - <stddev>0.01</stddev> - </noise> - </ray> - <plugin name="gazebo_ros_head_rplidar_controller" filename="libgazebo_ros_gpu_laser.so"> - <topicName>scan</topicName> - <frameName>laser</frameName> - </plugin> - </sensor> - </gazebo> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.urdf.xacro deleted file mode 100644 index aa785c9..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_burgertest1.urdf.xacro +++ /dev/null @@ -1,162 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_burger" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_burger.gazebo.xacro"/> - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link"/> - <origin xyz="0.0 0.0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.032 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/burger_base.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.032 0 0.070" rpy="0 0 0"/> - <geometry> - <box size="0.140 0.140 0.143"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="8.2573504e-01"/> - <inertia ixx="2.2124416e-03" ixy="-1.2294101e-05" ixz="3.4938785e-05" - iyy="2.1193702e-03" iyz="-5.0120904e-06" - izz="2.0064271e-03" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.08 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.080 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_link"/> - <origin xyz="-0.081 0 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="-0.032 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.032 0 0.172" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0.058" rpy="1.5707 0 4.71"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/rplidar.dae" scale="0.001 0.001 0.001" /> - </geometry> - </visual> - - <collision> - <origin xyz="0 0 0.058" rpy="1.5707 0 4.71"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/rplidar.dae" scale="0.001 0.001 0.001" /> - </geometry> - </collision> - - <inertial> - <mass value="1e-5" /> - <origin xyz="0 0 0.058" rpy="1.5707 0 4.71"/> - <inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0" /> - </inertial> - </link> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.gazebo.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.gazebo.xacro deleted file mode 100644 index 3eef193..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.gazebo.xacro +++ /dev/null @@ -1,190 +0,0 @@ -<?xml version="1.0"?> -<robot name="turtlebot3_waffle_sim" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:arg name="laser_visual" default="false"/> - <xacro:arg name="camera_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_right_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="caster_back_left_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/Grey</material> - </gazebo> - - <gazebo> - <plugin name="turtlebot3_waffle_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.287</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> - - <gazebo reference="camera_rgb_frame"> - <sensor type="depth" name="realsense_R200"> - <always_on>true</always_on> - <visualize>$(arg camera_visual)</visualize> - <camera> - <horizontal_fov>1.3439</horizontal_fov> - <image> - <width>1920</width> - <height>1080</height> - <format>R8G8B8</format> - </image> - <depth_camera></depth_camera> - <clip> - <near>0.03</near> - <far>100</far> - </clip> - </camera> - <plugin name="camera_controller" filename="libgazebo_ros_openni_kinect.so"> - <baseline>0.2</baseline> - <alwaysOn>true</alwaysOn> - <updateRate>30.0</updateRate> - <cameraName>camera</cameraName> - <frameName>camera_rgb_optical_frame</frameName> - <imageTopicName>rgb/image_raw</imageTopicName> - <depthImageTopicName>depth/image_raw</depthImageTopicName> - <pointCloudTopicName>depth/points</pointCloudTopicName> - <cameraInfoTopicName>rgb/camera_info</cameraInfoTopicName> - <depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName> - <pointCloudCutoff>0.4</pointCloudCutoff> - <hackBaseline>0.07</hackBaseline> - <distortionK1>0.0</distortionK1> - <distortionK2>0.0</distortionK2> - <distortionK3>0.0</distortionK3> - <distortionT1>0.0</distortionT1> - <distortionT2>0.0</distortionT2> - <CxPrime>0.0</CxPrime> - <Cx>0.0</Cx> - <Cy>0.0</Cy> - <focalLength>0</focalLength> - <hackBaseline>0</hackBaseline> - </plugin> - </sensor> - </gazebo> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.urdf.xacro deleted file mode 100644 index ee23268..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle.urdf.xacro +++ /dev/null @@ -1,251 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_waffle" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_waffle.gazebo.xacro"/> - - <xacro:property name="r200_cam_rgb_px" value="0.005"/> - <xacro:property name="r200_cam_rgb_py" value="0.018"/> - <xacro:property name="r200_cam_rgb_pz" value="0.013"/> - <xacro:property name="r200_cam_depth_offset" value="0.01"/> - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link" /> - <origin xyz="0 0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.064 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/waffle_base.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.064 0 0.047" rpy="0 0 0"/> - <geometry> - <box size="0.266 0.266 0.094"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="1.3729096e+00"/> - <inertia ixx="8.7002718e-03" ixy="-4.7576583e-05" ixz="1.1160499e-04" - iyy="8.6195418e-03" iyz="-3.5422299e-06" - izz="1.4612727e-02" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_right_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_right_link"/> - <origin xyz="-0.177 -0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_right_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="caster_back_left_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_left_link"/> - <origin xyz="-0.177 0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_left_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="0.0 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.064 0 0.122" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/> - <geometry> - <cylinder length="0.0315" radius="0.055"/> - </geometry> - </collision> - - <inertial> - <mass value="0.114" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="camera_joint" type="fixed"> - <origin xyz="0.064 -0.065 0.094" rpy="0 0 0"/> - <parent link="base_link"/> - <child link="camera_link"/> - </joint> - - <link name="camera_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 1.57"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/r200.dae" /> - </geometry> - </visual> - <collision> - <origin xyz="0.003 0.065 0.007" rpy="0 0 0"/> - <geometry> - <box size="0.012 0.132 0.020"/> - </geometry> - </collision> - - <!-- This inertial field needs doesn't contain reliable data!! --> -<!-- <inertial> - <mass value="0.564" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.003881243" ixy="0.0" ixz="0.0" - iyy="0.000498940" iyz="0.0" - izz="0.003879257" /> - </inertial>--> - </link> - - <joint name="camera_rgb_joint" type="fixed"> - <origin xyz="${r200_cam_rgb_px} ${r200_cam_rgb_py} ${r200_cam_rgb_pz}" rpy="0 0 0"/> - <parent link="camera_link"/> - <child link="camera_rgb_frame"/> - </joint> - <link name="camera_rgb_frame"/> - - <joint name="camera_rgb_optical_joint" type="fixed"> - <origin xyz="0 0 0" rpy="-1.57 0 -1.57"/> - <parent link="camera_rgb_frame"/> - <child link="camera_rgb_optical_frame"/> - </joint> - <link name="camera_rgb_optical_frame"/> - - <joint name="camera_depth_joint" type="fixed"> - <origin xyz="${r200_cam_rgb_px} ${r200_cam_rgb_py + r200_cam_depth_offset} ${r200_cam_rgb_pz}" rpy="0 0 0"/> - <parent link="camera_link"/> - <child link="camera_depth_frame"/> - </joint> - <link name="camera_depth_frame"/> - - <joint name="camera_depth_optical_joint" type="fixed"> - <origin xyz="0 0 0" rpy="-1.57 0 -1.57"/> - <parent link="camera_depth_frame"/> - <child link="camera_depth_optical_frame"/> - </joint> - <link name="camera_depth_optical_frame"/> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_for_open_manipulator.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_for_open_manipulator.urdf.xacro deleted file mode 100644 index cd4044c..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_for_open_manipulator.urdf.xacro +++ /dev/null @@ -1,251 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_waffle_for_open_manipulator" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_waffle.gazebo.xacro"/> - - <xacro:property name="r200_cam_rgb_px" value="0.005"/> - <xacro:property name="r200_cam_rgb_py" value="0.018"/> - <xacro:property name="r200_cam_rgb_pz" value="0.013"/> - <xacro:property name="r200_cam_depth_offset" value="0.01"/> - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link" /> - <origin xyz="0 0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.064 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/waffle_base_for_open_manipulator.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.064 0 0.047" rpy="0 0 0"/> - <geometry> - <box size="0.266 0.266 0.094"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="1.3729096e+00"/> - <inertia ixx="8.7002718e-03" ixy="-4.7576583e-05" ixz="1.1160499e-04" - iyy="8.6195418e-03" iyz="-3.5422299e-06" - izz="1.4612727e-02" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_right_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_right_link"/> - <origin xyz="-0.177 -0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_right_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="caster_back_left_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_left_link"/> - <origin xyz="-0.177 0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_left_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="0.0 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.024 0 0.122" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/> - <geometry> - <cylinder length="0.0315" radius="0.045"/> - </geometry> - </collision> - - <inertial> - <mass value="0.114" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="camera_joint" type="fixed"> - <origin xyz="0.064 -0.065 0.094" rpy="0 0 0"/> - <parent link="base_link"/> - <child link="camera_link"/> - </joint> - - <link name="camera_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 1.57"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/r200.dae" /> - </geometry> - </visual> - <collision> - <origin xyz="0.003 0.065 0.010" rpy="0 0 0"/> - <geometry> - <box size="0.012 0.132 0.022"/> - </geometry> - </collision> - - <!-- This inertial field needs doesn't contain reliable data!! --> -<!-- <inertial> - <mass value="0.564" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.003881243" ixy="0.0" ixz="0.0" - iyy="0.000498940" iyz="0.0" - izz="0.003879257" /> - </inertial>--> - </link> - - <joint name="camera_rgb_joint" type="fixed"> - <origin xyz="${r200_cam_rgb_px} ${r200_cam_rgb_py} ${r200_cam_rgb_pz}" rpy="0 0 0"/> - <parent link="camera_link"/> - <child link="camera_rgb_frame"/> - </joint> - <link name="camera_rgb_frame"/> - - <joint name="camera_rgb_optical_joint" type="fixed"> - <origin xyz="0 0 0" rpy="-1.57 0 -1.57"/> - <parent link="camera_rgb_frame"/> - <child link="camera_rgb_optical_frame"/> - </joint> - <link name="camera_rgb_optical_frame"/> - - <joint name="camera_depth_joint" type="fixed"> - <origin xyz="${r200_cam_rgb_px} ${r200_cam_rgb_py + r200_cam_depth_offset} ${r200_cam_rgb_pz}" rpy="0 0 0"/> - <parent link="camera_link"/> - <child link="camera_depth_frame"/> - </joint> - <link name="camera_depth_frame"/> - - <joint name="camera_depth_optical_joint" type="fixed"> - <origin xyz="0 0 0" rpy="-1.57 0 -1.57"/> - <parent link="camera_depth_frame"/> - <child link="camera_depth_optical_frame"/> - </joint> - <link name="camera_depth_optical_frame"/> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.gazebo.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.gazebo.xacro deleted file mode 100644 index 191daa8..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.gazebo.xacro +++ /dev/null @@ -1,180 +0,0 @@ -<?xml version="1.0"?> -<robot name="turtlebot3_waffle_pi_sim" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:arg name="laser_visual" default="false"/> - <xacro:arg name="camera_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_right_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="caster_back_left_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/Grey</material> - </gazebo> - - <gazebo> - <plugin name="turtlebot3_waffle_pi_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.287</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> - -<!--link : https://www.raspberrypi.org/documentation/hardware/camera/--> - <gazebo reference="camera_rgb_frame"> - <sensor type="camera" name="Pi Camera"> - <always_on>true</always_on> - <visualize>$(arg camera_visual)</visualize> - <camera> - <horizontal_fov>1.085595</horizontal_fov> - <image> - <width>640</width> - <height>480</height> - <format>R8G8B8</format> - </image> - <clip> - <near>0.03</near> - <far>100</far> - </clip> - </camera> - <plugin name="camera_controller" filename="libgazebo_ros_camera.so"> - <alwaysOn>true</alwaysOn> - <updateRate>30.0</updateRate> - <cameraName>camera</cameraName> - <frameName>camera_rgb_optical_frame</frameName> - <imageTopicName>rgb/image_raw</imageTopicName> - <cameraInfoTopicName>rgb/camera_info</cameraInfoTopicName> - <hackBaseline>0.07</hackBaseline> - <distortionK1>0.0</distortionK1> - <distortionK2>0.0</distortionK2> - <distortionK3>0.0</distortionK3> - <distortionT1>0.0</distortionT1> - <distortionT2>0.0</distortionT2> - </plugin> - </sensor> - </gazebo> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.urdf.xacro deleted file mode 100644 index 46cf4a9..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi.urdf.xacro +++ /dev/null @@ -1,217 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_waffle_pi" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_waffle_pi.gazebo.xacro"/> - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link" /> - <origin xyz="0 0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.064 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/waffle_pi_base.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.064 0 0.047" rpy="0 0 0"/> - <geometry> - <box size="0.266 0.266 0.094"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="1.3729096e+00"/> - <inertia ixx="8.7002718e-03" ixy="-4.7576583e-05" ixz="1.1160499e-04" - iyy="8.6195418e-03" iyz="-3.5422299e-06" - izz="1.4612727e-02" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_right_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_right_link"/> - <origin xyz="-0.177 -0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_right_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="caster_back_left_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_left_link"/> - <origin xyz="-0.177 0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_left_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="0.0 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.064 0 0.122" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/> - <geometry> - <cylinder length="0.0315" radius="0.055"/> - </geometry> - </collision> - - <inertial> - <mass value="0.114" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="camera_joint" type="fixed"> - <origin xyz="0.073 -0.011 0.084" rpy="0 0 0"/> - <parent link="base_link"/> - <child link="camera_link"/> - </joint> - - <link name="camera_link"> - <collision> - <origin xyz="0.005 0.011 0.013" rpy="0 0 0"/> - <geometry> - <box size="0.015 0.030 0.027"/> - </geometry> - </collision> - </link> - - <joint name="camera_rgb_joint" type="fixed"> - <origin xyz="0.003 0.011 0.009" rpy="0 0 0"/> - <parent link="camera_link"/> - <child link="camera_rgb_frame"/> - </joint> - <link name="camera_rgb_frame"/> - - <joint name="camera_rgb_optical_joint" type="fixed"> - <origin xyz="0 0 0" rpy="-1.57 0 -1.57"/> - <parent link="camera_rgb_frame"/> - <child link="camera_rgb_optical_frame"/> - </joint> - <link name="camera_rgb_optical_frame"/> - -</robot> diff --git a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi_for_open_manipulator.urdf.xacro b/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi_for_open_manipulator.urdf.xacro deleted file mode 100644 index f3c2b80..0000000 --- a/src/sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/turtlebot3_waffle_pi_for_open_manipulator.urdf.xacro +++ /dev/null @@ -1,217 +0,0 @@ -<?xml version="1.0" ?> -<robot name="turtlebot3_waffle_pi_for_open_manipulator" xmlns:xacro="http://ros.org/wiki/xacro"> - <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/> - <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_waffle_pi.gazebo.xacro"/> - - <link name="base_footprint"/> - - <joint name="base_joint" type="fixed"> - <parent link="base_footprint"/> - <child link="base_link" /> - <origin xyz="0 0 0.010" rpy="0 0 0"/> - </joint> - - <link name="base_link"> - <visual> - <origin xyz="-0.064 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/bases/waffle_pi_base_for_open_manipulator.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="light_black"/> - </visual> - - <collision> - <origin xyz="-0.064 0 0.047" rpy="0 0 0"/> - <geometry> - <box size="0.266 0.266 0.094"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" rpy="0 0 0"/> - <mass value="1.3729096e+00"/> - <inertia ixx="8.7002718e-03" ixy="-4.7576583e-05" ixz="1.1160499e-04" - iyy="8.6195418e-03" iyz="-3.5422299e-06" - izz="1.4612727e-02" /> - </inertial> - </link> - - <joint name="wheel_left_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_left_link"/> - <origin xyz="0.0 0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_left_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="wheel_right_joint" type="continuous"> - <parent link="base_link"/> - <child link="wheel_right_link"/> - <origin xyz="0.0 -0.144 0.023" rpy="-1.57 0 0"/> - <axis xyz="0 0 1"/> - </joint> - - <link name="wheel_right_link"> - <visual> - <origin xyz="0 0 0" rpy="1.57 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <cylinder length="0.018" radius="0.033"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="2.8498940e-02" /> - <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09" - iyy="1.1192413e-05" iyz="-1.4400107e-11" - izz="2.0712558e-05" /> - </inertial> - </link> - - <joint name="caster_back_right_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_right_link"/> - <origin xyz="-0.177 -0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_right_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="caster_back_left_joint" type="fixed"> - <parent link="base_link"/> - <child link="caster_back_left_link"/> - <origin xyz="-0.177 0.064 -0.004" rpy="-1.57 0 0"/> - </joint> - - <link name="caster_back_left_link"> - <collision> - <origin xyz="0 0.001 0" rpy="0 0 0"/> - <geometry> - <box size="0.030 0.009 0.020"/> - </geometry> - </collision> - - <inertial> - <origin xyz="0 0 0" /> - <mass value="0.005" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="imu_joint" type="fixed"> - <parent link="base_link"/> - <child link="imu_link"/> - <origin xyz="0.0 0 0.068" rpy="0 0 0"/> - </joint> - - <link name="imu_link"/> - - <joint name="scan_joint" type="fixed"> - <parent link="base_link"/> - <child link="base_scan"/> - <origin xyz="-0.024 0 0.122" rpy="0 0 0"/> - </joint> - - <link name="base_scan"> - <visual> - <origin xyz="0 0 0.0" rpy="0 0 0"/> - <geometry> - <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/> - </geometry> - <material name="dark"/> - </visual> - - <collision> - <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/> - <geometry> - <cylinder length="0.0315" radius="0.045"/> - </geometry> - </collision> - - <inertial> - <mass value="0.114" /> - <origin xyz="0 0 0" /> - <inertia ixx="0.001" ixy="0.0" ixz="0.0" - iyy="0.001" iyz="0.0" - izz="0.001" /> - </inertial> - </link> - - <joint name="camera_joint" type="fixed"> - <origin xyz="0.073 -0.011 0.084" rpy="0 0 0"/> - <parent link="base_link"/> - <child link="camera_link"/> - </joint> - - <link name="camera_link"> - <collision> - <origin xyz="0.005 0.011 0.013" rpy="0 0 0"/> - <geometry> - <box size="0.015 0.030 0.027"/> - </geometry> - </collision> - </link> - - <joint name="camera_rgb_joint" type="fixed"> - <origin xyz="0.003 0.011 0.009" rpy="0 0 0"/> - <parent link="camera_link"/> - <child link="camera_rgb_frame"/> - </joint> - <link name="camera_rgb_frame"/> - - <joint name="camera_rgb_optical_joint" type="fixed"> - <origin xyz="0 0 0" rpy="-1.57 0 -1.57"/> - <parent link="camera_rgb_frame"/> - <child link="camera_rgb_optical_frame"/> - </joint> - <link name="camera_rgb_optical_frame"/> - -</robot> diff --git a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Adapter.java b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Adapter.java index f10e1a1..97f7018 100644 --- a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Adapter.java +++ b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Adapter.java @@ -1,302 +1,98 @@ -import java.io.*; -import java.util.*; - -import org.jdom2.*; +import java.util.ArrayList; +import java.util.List; +import java.io.IOException; +import org.jdom2.Document; +import org.jdom2.Attribute; +import org.jdom2.JDOMException; /** - * Takes a featuremodel.xml file generated using FeatureModelConfigurator and a given .gazebo.xacro and urdf.xacro file. - * The .gazebo.xacro and .urdf.xacro files are modified to support the features specified in the featuremodel.xml file. + * Class that provides input/ output info and other variables an adapter may use + * by reading from featuremodel generated using FeatureModelConfigurator. */ -public class Adapter extends XMLHelper { +public class Adapter extends UserSetIOReader { + //Hard coded input/ output (because the project directory is designed like this) + public final String in_fmName = "featuremodel.xml"; + public final String in_fmPath = "./resources/output/"; + + private final String in_scPath = "./resources/input/sensorconfig/"; + public final String scAutoPath = in_scPath+"autogenerated/"; + public final String scOtherPath = in_scPath+"other/"; + + //Variables used exclusively by adapters + public final String mode; + public final List<Document> sensorConfigList; + public final String botName; /** - * Obtains an attribute value of the input/ output entries specified in adapter.config. + * Constructor defining a general adapter. * - * @param doc The JDOM Document (adapter.config) - * @param entry String formed as "{input or output}/{entity}" - * @param val Attribute name as String - * @return path as specified in adapter.config + * When reading input, scAutoPath, scOtherPath and in_fmPath may contain other + * files that will be filtered out. + * + * @throws IOException + * @throws JDOMException */ - private static String getConfigVal(Document doc, String str, String val) { - List<Attribute> valList = xQueryAttributes(doc, "//"+str+"/@"+val); - if(valList.size()!=1) { - System.err.println("Error while reading input/ output "+val+" value from adapter.config."); + public Adapter() throws JDOMException, IOException { + super(); + + Document featureModel = XMLHelper.readXml(in_fmPath+in_fmName); + + //Get the selected mode (either NO_CHANGE or Custom) as String + List<Attribute> modeList = XMLHelper.xQueryAttributes(featureModel, "//mode/@param"); + if(modeList.size()!=1) { + System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); System.exit(-1); } - - return valList.get(0).getValue(); - } - - /** - * Call this to run Adapter. - */ - //public static void main(String[] args) { - public Adapter() { - System.out.println("Adapter started."); - try { - final String SC_ENDING = ".xml"; - final String GX_ENDING = ".gazebo.xacro"; - final String UX_ENDING = ".urdf.xacro"; - - //######### Input ############################### - Document adapterConfig = readXml("./adapter.config"); - - //Get adapter.config values. - String in_fmPath = getConfigVal(adapterConfig, "input/featuremodel", "path"); - String in_scPath = getConfigVal(adapterConfig, "input/sensorconfig", "path"); - String in_gxPath = getConfigVal(adapterConfig, "input/gazebo_xacro", "path"); - String in_uxPath = getConfigVal(adapterConfig, "input/urdf_xacro", "path"); - String out_gxPath = getConfigVal(adapterConfig, "output/gazebo_xacro", "path"); - String out_uxPath = getConfigVal(adapterConfig, "output/urdf_xacro", "path"); - String out_bnPath = getConfigVal(adapterConfig, "output/botname", "path"); - - String in_fmName = getConfigVal(adapterConfig, "input/featuremodel", "name"); - String in_gxName = ""; - String in_uxName = ""; - String out_gxName = getConfigVal(adapterConfig, "output/gazebo_xacro", "name"); - String out_uxName = getConfigVal(adapterConfig, "output/urdf_xacro", "name"); - String out_bnName = getConfigVal(adapterConfig, "output/botname", "name"); - - String scAutoPath = in_scPath+"autogenerated/"; - String scOtherPath = in_scPath+"other/"; - - String unwantedPrefix = getConfigVal(adapterConfig, "output/botname", "remove_prefix"); - String unwantedSuffix = getConfigVal(adapterConfig, "output/botname", "remove_suffix"); - - //Declare Documents. - Document featureModel = readXml(in_fmPath+in_fmName); - List<Document> sensorConfigList = new ArrayList<Document>(); - Document gazeboModel = null; - Document urdfModel = null; - - //Get the selected mode (either NO_CHANGE or Custom) as String. - String mode = ""; - - List<Attribute> modeList = xQueryAttributes(featureModel, "//mode/@param"); - if(modeList.size()==1) { - mode = modeList.get(0).getValue(); - } - else { - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); - System.exit(-1); - } - - //Get all selected sensorconfig files as List<Document>. - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - List<Attribute> sensorList = xQueryAttributes(featureModel, "//sensor/@name"); - -// List<String> scAutoList = getFileNames(scAutoPath); -// List<String> scOtherList = getFileNames(scOtherPath); -// List<String> scList = new ArrayList<String>(); -// scList.addAll(scAutoList); -// scList.addAll(scOtherList); -// -// for(Attribute sensor : sensorList) { -// boolean inDirectory = false; -// for(String fileName : scList) { -// if(fileName.equals(sensor.getValue()+SC_ENDING)) { -// inDirectory = true; -// } -// } -// if(!inDirectory) { -// System.err.println("Cannot handle \'"+sensor.getValue()+"\': No input file known."); -// System.exit(-1); -// } -// } - - for(Attribute sensor : sensorList) { - String fileName = sensor.getValue()+SC_ENDING; - List<String> fileMatches= findFile(fileName, in_scPath); - - if(fileMatches.isEmpty()) { - System.err.println("Cannot handle \'"+sensor.getValue()+"\': No input file known."); - System.exit(-1); - } - - if(fileMatches.size()==1) { - sensorConfigList.add(readXml(fileMatches.get(0))); - } - else { - System.err.println("Cannot handle \'"+sensor.getValue()+"\': Multiple input files found:"); - for(String match : fileMatches) { - System.err.println("\'"+match+"\'"); - } - System.exit(-1); - } - } - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + mode = modeList.get(0).getValue(); + + //Get the name of the selected bot as String + List<Attribute> botList = XMLHelper.xQueryAttributes(featureModel, "//templates/@name"); + if(botList.size()!=1) { + System.err.println("Invalid input in \'"+in_fmName+"\': No or multiple bots selected."); + System.exit(-1); + } + + botName = botList.get(0).getValue(); + + //Get all selected sensorconfig files as List<Document> + sensorConfigList = new ArrayList<Document>(); + + switch(mode) { + case "NO_CHANGE": + break; + case "Custom": + List<Attribute> selectedSensorList = XMLHelper.xQueryAttributes(featureModel, "//sensor/@name"); + + for(Attribute selectedSensor : selectedSensorList) { + String fileName = selectedSensor.getValue()+SC_ENDING; + + List<String> fileMatchAutoList = XMLHelper.findFile(fileName, scAutoPath); + List<String> fileMatchOtherList = XMLHelper.findFile(fileName, scOtherPath); + List<String> fileMatchList = new ArrayList<String>(); + fileMatchList.addAll(fileMatchAutoList); + fileMatchList.addAll(fileMatchOtherList); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+fileName+"\': No input file known."); System.exit(-1); - } - - //Get the name of the selected bot as String. - String botName = ""; - - List<Attribute> botList = xQueryAttributes(featureModel, "//templates/@name"); - if(botList.size()==1) { - botName = botList.get(0).getValue(); - } - else { - System.err.println("Invalid input in \'"+in_fmName+"\': No or multiple bots selected."); - System.exit(-1); - } - - //Get the selected .gazebo.xacro file as Document. - in_gxName = botName+GX_ENDING; - - List<String> gxList = getFileNames(in_gxPath); - boolean inDirectory = false; - for(String fileName : gxList) { - if(fileName.equals(in_gxName)) { - inDirectory = true; } - } - if(!inDirectory) { - System.err.println("Cannot handle \'"+botName+"\': No \'"+GX_ENDING+"\' input file known."); - System.exit(-1); - } - - gazeboModel = readXml(in_gxPath+in_gxName); - - //Get the corresponding .urdf.xacro file as Document. - in_uxName = botName+UX_ENDING; - - List<String> urdfList = getFileNames(in_uxPath); - inDirectory = false; - for(String fileName : urdfList) { - if(fileName.equals(in_uxName)) { - inDirectory = true; - } - } - if(!inDirectory) { - System.err.println("Cannot handle \'"+botName+"\': No \'"+UX_ENDING+"\' input file known."); - System.exit(-1); - } - - urdfModel = readXml(in_uxPath+in_uxName); - //############################################### - - - //######### Operate on .gazebo.xacro ############ - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - //Remove all existing sensors in template. - List<Element> removableSensorsList = xQueryElements(gazeboModel, "//sensor"); - - for(Element sensor : removableSensorsList) { - Element entry = sensor.getParentElement(); - if(entry.getName().equals("gazebo")) { - entry.detach(); - } - else { - System.out.println("Found a <sensor> element in \'"+in_gxName+ - "\' that does not have a <gazebo> element as immediate parent. It was not removed, as this input is unexpected."); - } - } - - //Insert selected sensors into template. - for(Document sensorConfig : sensorConfigList) { - List<Element> sensorList = xQueryElements(sensorConfig, "//gazebo"); - if(sensorList.size()==1) { - Element sensor = sensorList.get(0); - - //Warn if a sensor still contains $(arg ...) values. - List<Element> tagList = xQueryElements(sensor, "//*"); - for(Element tag : tagList) { - String text = tag.getText(); - if(text.contains("$")) { - System.out.println("Warning: a sensorconfig file still contains an abstract value: \'"+text+ - "\'. It should be replaced with a set value, or the output .gazebo.xacro will likely be broken."); - } - } - - sensor.detach(); - gazeboModel.getRootElement().addContent(sensor); - } - else { - System.err.println("Invalid input. At least one sensorconfig file contains no or multiple <gazebo> entries."); - System.exit(-1); - } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+fileName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); } - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); System.exit(-1); + } + + sensorConfigList.add(XMLHelper.readXml(fileMatchList.get(0))); } - //############################################### - - - //######### Operate on .urdf.xacro ############## - final Namespace NS = urdfModel.getRootElement().getNamespace("xacro"); - - //Set <xacro:include> tags - List<Element> includeList = xQueryElements(urdfModel, "//xacro:include", NS); - if(includeList.size()!=2) { - System.err.println("Invalid input in \'"+in_uxName+"\': Expected exactly 2 xacro:include tags."); - System.exit(-1); - } - String gxDestDirectoryName = (new File(out_gxPath)).getName(); - //includeList.get(0).setAttribute("filename", "$(find "+CommonPropDestDirectoryName+")/common_properties.xacro");//TODO - includeList.get(1).setAttribute("filename", "$(find "+gxDestDirectoryName+")/"+out_gxName); - - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - //TODO - //If the urdf.xacro would be modified (to have an accurate visual model with the sensors attached to it), - //this needs to happen here. (Delete or Insert <link>/ <joint> tags.) - //This would require separate files with <link>/ <joint> tags for each sensor and bot for the Adapter to access... - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); - System.exit(-1); - } - //############################################### - - - //######### Output result ####################### - //Output model files. - saveAsXml(gazeboModel, out_gxPath+out_gxName); - - saveAsXml(urdfModel, out_uxPath+out_uxName); - - //Output botName. - String alteredBotName = botName; - if(alteredBotName.startsWith(unwantedPrefix)) { - alteredBotName = alteredBotName.substring(unwantedPrefix.length(), alteredBotName.length()); - } - else { - System.out.println("Warning: Prefix \'"+unwantedPrefix+"\' could not be removed from bot name."); - } - if(alteredBotName.endsWith(unwantedSuffix)) { - alteredBotName = alteredBotName.substring(0, alteredBotName.length() - unwantedSuffix.length()); - } - else { - System.out.println("Warning: Suffix \'"+unwantedSuffix+"\' could not be removed from bot name."); - } - - BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(out_bnPath+out_bnName)); - bufferedWriter.write(alteredBotName); - bufferedWriter.close(); - //############################################### - } - catch (Exception e) { - e.printStackTrace(); + break; + default: + System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); } - - System.out.println("Adapter finished."); } } - - - diff --git a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/BotNameAdapter.java b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/BotNameAdapter.java new file mode 100644 index 0000000..56b91a9 --- /dev/null +++ b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/BotNameAdapter.java @@ -0,0 +1,67 @@ +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting the selected bots name. + */ +public class BotNameAdapter extends Adapter { + //Variables used exclusively by botName adapter + public final String alteredBotName; + + /** + * Creates a runnable Adapter for the "botname.txt"(out_bnName) output file. + * + * @throws IOException + * @throws JDOMException + */ + public BotNameAdapter() throws JDOMException, IOException { + super(); + + //Get the altered botName (botName with unwantedPrefix and unwantedSuffix removed) + String tmp = botName; + if(tmp.startsWith(unwantedPrefix)) { + tmp = tmp.substring(unwantedPrefix.length(), tmp.length()); + } + else { + System.out.println("Warning: Prefix \'"+unwantedPrefix+"\' could not be removed from bot name."); + } + if(tmp.endsWith(unwantedSuffix)) { + tmp = tmp.substring(0, tmp.length() - unwantedSuffix.length()); + } + else { + System.out.println("Warning: Suffix \'"+unwantedSuffix+"\' could not be removed from bot name."); + } + + alteredBotName = tmp; + } + + /** + * Run the Adapter for the "botname.txt"(out_bnName) output file. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("BotNameAdapter started."); + + //Output alteredBotName + this.output(); + + System.out.println("BotNameAdapter finished."); + } + + /** + * Output alteredBotName as "botname.txt"(out_bnName) file. + * + * @throws IOException + */ + private void output() throws IOException { + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(this.out_bnPath+this.out_bnName)); + bufferedWriter.write(this.alteredBotName); + bufferedWriter.close(); + } + +} diff --git a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Configurator.jak b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Configurator.jak index 8cf93aa..e241cc6 100644 --- a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Configurator.jak +++ b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/Configurator.jak @@ -104,8 +104,19 @@ public class Configurator { return; } - //create and launch Adapter - new Adapter(); + //create and launch adapters + try { + GazeboAdapter oGazeboAdapter = new GazeboAdapter(); + oGazeboAdapter.run(); + UrdfAdapter oUrdfAdapter = new UrdfAdapter(); + oUrdfAdapter.run(); + BotNameAdapter oBotNameAdapter = new BotNameAdapter(); + oBotNameAdapter.run(); + } + catch (Exception oEx) { + System.out.println(oEx); + return; + } } //get all parents of a given module from the Feature Model file diff --git a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/GazeboAdapter.java b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/GazeboAdapter.java new file mode 100644 index 0000000..87237c3 --- /dev/null +++ b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/GazeboAdapter.java @@ -0,0 +1,155 @@ +import java.util.List; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting a .gazebo.xacro file based on + * featuremodel info. + */ +public class GazeboAdapter extends Adapter { + //Variables used exclusively by .gazebo.xacro adapter + public final String in_gxName; + public final Document gazeboModel; + + /** + * Creates a runnable Adapter for .gazebo.xacro files. + * + * When reading input in_gxPath may contain other files that will be filtered out. + * + * @throws IOException + * @throws JDOMException + */ + public GazeboAdapter() throws JDOMException, IOException { + super(); + + //Get the selected .gazebo.xacro file name as String + in_gxName = botName+GX_ENDING; + + //Get the selected .gazebo.xacro file as Document + List<String> fileMatchList = XMLHelper.findFile(in_gxName, in_gxPath); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+in_gxName+"\': No input file known."); + System.exit(-1); + } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+in_gxName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); + } + System.exit(-1); + } + + gazeboModel = XMLHelper.readXml(fileMatchList.get(0)); + } + + /** + * Run the Adapter for .gazebo.xacro files. + * Depending on the selected mode, this Adapter will either: + * (NO_CHANGE) - Do nothing. + * + * (Custom) - Remove all existing sensors in gazeboModel template. + * - Insert only the selected sensors. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("GazeboAdapter started."); + + switch(this.mode) { + case "NO_CHANGE": + break; + case "Custom": + //Remove all existing sensors in template + this.removeExistingSensors(); + + //Insert selected sensors into template + this.insertSelectedSensors(); + break; + default: + System.err.println("Invalid input in \'"+this.in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); + } + + //Output gazeboModel + this.output(); + + System.out.println("GazeboAdapter finished."); + } + + /** + * Removes all existing sensors (with its enclosing {@code <gazebo>} tag) from gazeboModel. + */ + private void removeExistingSensors() { + List<Element> removableSensorsList = XMLHelper.xQueryElements(this.gazeboModel, "//sensor"); + + for(Element sensor : removableSensorsList) { + Element entry = sensor.getParentElement(); + if(entry.getName().equals("gazebo")) { + entry.detach(); + } + else { + System.out.println("Warning: Found a <sensor> element in \'"+this.in_gxName+ + "\' that does not have a <gazebo> element as immediate parent. It was not removed, as this input is unexpected."); + } + } + } + + /** + * Inserts all selected sensors (with its enclosing {@code <gazebo>} tag) into gazeboModel. + */ + private void insertSelectedSensors() { + for(Document sensorConfig : this.sensorConfigList) { + List<Element> sensorList = XMLHelper.xQueryElements(sensorConfig, "//gazebo"); + + if(sensorList.size()!=1) { + System.err.println("Invalid input. At least one sensorconfig file contains no or multiple <gazebo> entries."); + System.exit(-1); + } + + Element sensor = sensorList.get(0); + + //Warn if a sensor still contains $(arg ...) values + checkForArg(sensor); + + sensor.detach(); + this.gazeboModel.getRootElement().addContent(sensor); + + + } + } + + /** + * Checks if an Element still contains $(arg ...) values. + * Only exists because because someone might manually create a sensorconfig by copying + * from a .gazebo.xacro template and forget that $(arg ...) values are still inside. + */ + private static boolean checkForArg(Element element) { + boolean detected = false; + List<Element> tagList = XMLHelper.xQueryElements(element, "//*"); + + for(Element tag : tagList) { + String text = tag.getText(); + if(text.contains("$")) { + System.out.println("Warning: A sensorconfig file still contains an abstract value: \'"+text+ + "\'. It should be replaced with a set value, or the output .gazebo.xacro will likely be broken."); + detected = true; + } + } + + return detected; + } + + /** + * Output the gazeboModel as XML file. + * + * @throws IOException + */ + private void output() throws IOException { + XMLHelper.saveAsXml(this.gazeboModel, this.out_gxPath+this.out_gxName); + } +} diff --git a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/UrdfAdapter.java b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/UrdfAdapter.java new file mode 100644 index 0000000..5006bb5 --- /dev/null +++ b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/UrdfAdapter.java @@ -0,0 +1,136 @@ +import java.util.List; +import java.io.File; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting a .urdf.xacro file based on + * featuremodel info. + */ +public class UrdfAdapter extends Adapter { + //Variables used exclusively by .urdf.xacro adapter + public final String in_uxName; + public final Document urdfModel; + public final Namespace NS; + + /** + * Creates a runnable Adapter for .urdf.xacro files. + * + * When reading input in_uxPath may contain other files that will be filtered out. + * + * @throws IOException + * @throws JDOMException + */ + public UrdfAdapter() throws JDOMException, IOException { + super(); + + //Get the selected .urdf.xacro file name as String + in_uxName = botName+UX_ENDING; + + //Get the selected .urdf.xacro file as Document + List<String> fileMatchList = XMLHelper.findFile(in_uxName, in_uxPath); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+in_uxName+"\': No input file known."); + System.exit(-1); + } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+in_uxName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); + } + System.exit(-1); + } + + urdfModel = XMLHelper.readXml(fileMatchList.get(0)); + + //Get the "xacro" namespace of the .urdf.xacro document as Namespace + NS = urdfModel.getRootElement().getNamespace("xacro"); + } + + /** + * Run the Adapter for .urdf.xacro files. + * + * Sets the {@code <xacro:include>} tags. + * The links/ joints are not edited, as the precise visual bot representation is not + * important for this project. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("UrdfAdapter started."); + + //Set <xacro:include> tags + this.setInclude(); + + switch(this.mode) { + case "NO_CHANGE": + break; + case "Custom": + /** + * If the urdf.xacro would be modified (to have an accurate visual model with the sensors attached to it), + * this needs to happen here. (Delete or Insert <link> and <joint> tags.) + * This would require separate files with <link> and <joint> tags for each bot and sensor for the Adapter to access. + * + * For example, like this: + * The "autogenerated"/"other" directory gets one child directory for each bot. + * Each of these new directories contains one file for each sensorconfig with the building blocks + * to be inserted in .urdf.xacro, just like the sensorconfigs contain building blocks + * for the .gazebo.xacro files. + */ + break; + default: + System.err.println("Invalid input in \'"+this.in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); + } + + //Output urdfModel + this.output(); + + System.out.println("UrdfAdapter finished."); + } + + /** + * Sets {@code <xacro:include>} tags in urdfModel to correctly point to the files to be included. + */ + private void setInclude() { + List<Element> includeList = XMLHelper.xQueryElements(this.urdfModel, "//xacro:include", this.NS); + + if(includeList.size()!=2) { + System.err.println("Unexpected input in \'"+this.in_uxName+"\': Expected exactly 2 <xacro:include> tags."); + System.exit(-1); + } + + int gxIndex; + int commonPropIndex; + if(includeList.get(0).getAttributeValue("filename").endsWith(GX_ENDING)) { + gxIndex = 0; + commonPropIndex = 1; + } + else { + gxIndex = 1; + commonPropIndex = 0; + } + + String gxDestDirectoryName = (new File(this.out_gxPath)).getName(); + includeList.get(gxIndex).setAttribute("filename", "$(find "+gxDestDirectoryName+")/"+this.out_gxName); + + //The common_properties.xacro stays in its original directory, so this is not edited + //String commonPropDestDirectoryName = ; + //includeList.get(commonPropIndex).setAttribute("filename", "$(find "+commonPropDestDirectoryName+")/common_properties.xacro"); + } + + /** + * Output the urdfModel as XML file. + * + * @throws IOException + */ + private void output() throws IOException { + XMLHelper.saveAsXml(this.urdfModel, this.out_uxPath+this.out_uxName); + } +} diff --git a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/UserSetIOReader.java b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/UserSetIOReader.java new file mode 100644 index 0000000..409a517 --- /dev/null +++ b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/UserSetIOReader.java @@ -0,0 +1,88 @@ +import java.util.List; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Attribute; +import org.jdom2.JDOMException; + + +/** + * Class that allows for reading input from usersetio.config. + */ +public class UserSetIOReader { + //File endings + public static final String SC_ENDING = ".xml"; + public static final String GX_ENDING = ".gazebo.xacro"; + public static final String UX_ENDING = ".urdf.xacro"; + + //Input/ output as defined by user + public final String in_gxPath; + + public final String in_uxPath; + + public final String out_gxName; + public final String out_gxPath; + + public final String out_uxName; + public final String out_uxPath; + + public final String out_bnName; + public final String out_bnPath; + public final String unwantedPrefix; + public final String unwantedSuffix; + + /** + * Constructor reading from default usersetio.config location. + * + * @throws IOException + * @throws JDOMException + */ + public UserSetIOReader() throws JDOMException, IOException { + this("./../usersetio.config"); + } + + /** + * Constructor reading all values from usersetio.config. + * io.config contains all values that the user will want to set manually. + * + * @param path Location of usersetio.config. + * @throws IOException + * @throws JDOMException + */ + private UserSetIOReader(String path) throws JDOMException, IOException { + Document config = XMLHelper.readXml(path); + + in_gxPath = getConfigVal(config, "input/gazebo_xacro", "path"); + + in_uxPath = getConfigVal(config, "input/urdf_xacro", "path"); + + out_gxName = getConfigVal(config, "output/gazebo_xacro", "name"); + out_gxPath = getConfigVal(config, "output/gazebo_xacro", "path"); + + out_uxName = getConfigVal(config, "output/urdf_xacro", "name"); + out_uxPath = getConfigVal(config, "output/urdf_xacro", "path"); + + out_bnName = getConfigVal(config, "output/botname", "name"); + out_bnPath = getConfigVal(config, "output/botname", "path"); + unwantedPrefix = getConfigVal(config, "output/botname", "remove_prefix"); + unwantedSuffix = getConfigVal(config, "output/botname", "remove_suffix"); + } + + /** + * Obtains an attribute value of the input/ output entries specified in *.config. + * + * @param doc The JDOM Document (*.config) + * @param entry String formed as "{input or output}/{entity}" + * @param val Attribute name as String + * @return XML-attribute specified in entry of doc (*.config) as String + */ + public static String getConfigVal(Document doc, String entry, String val) { + List<Attribute> valList = XMLHelper.xQueryAttributes(doc, "//"+entry+"/@"+val); + if(valList.size()!=1) { + System.err.println("Error while reading input/ output \'"+val+"\' value from *.config."); + System.exit(-1); + } + + return valList.get(0).getValue(); + } +} diff --git a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/XMLHelper.java b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/XMLHelper.java index 08c3067..36f589c 100644 --- a/src/var/FeatureModelConfigurator/features/ConfiguratorMain/XMLHelper.java +++ b/src/var/FeatureModelConfigurator/features/ConfiguratorMain/XMLHelper.java @@ -9,7 +9,6 @@ import org.jdom2.output.XMLOutputter; import org.jdom2.xpath.*; - /** * Contains methods based on JDOM and Jaxen library that help processing XML files and other misc ones. */ @@ -126,12 +125,13 @@ public class XMLHelper { * * @param name Name of the file including file ending as String * @param path Path to directory to be searched as String - * @return path to all file matches as List<String> (e.g. .../sensorconfig/other/imu.xml) + * @return path to all file matches as {@code List<String>} (e.g. .../sensorconfig/other/imu.xml) */ public static List<String> findFile(String name, String path) { List<String> accumulator = new ArrayList<String>(); + findFile(name, path, accumulator); - return findFile(name, path, accumulator); + return accumulator; } /** @@ -139,23 +139,20 @@ public class XMLHelper { * * @param name Name of the file including file ending as String * @param path Path to directory to be searched as String - * @param result Accumulator for all file matches as List<String> - * @return path to all file matches as list<String> (e.g. .../sensorconfig/other/imu.xml) + * @param result Accumulator for all file matches as {@code List<String>} */ - private static List<String> findFile(String name, String path, List<String> result) { + private static void findFile(String name, String path, List<String> result) { File element = new File(path); File[] content = element.listFiles(); + //content==null if it is not a directory if(content != null) { for(File file : content) { - List<String> subResult = findFile(name, path+"/"+file.getName(), result); - result.addAll(subResult); + findFile(name, path+"/"+file.getName(), result); } } if(element.getName().equals(name)) { - result.add(element.getName()); + result.add(element.getPath()); } - - return result; } /** @@ -455,12 +452,4 @@ public class XMLHelper { return false; } - - /** - * @param args - */ - public static void main(String[] args) { - - } } - diff --git a/src/var/FeatureModelConfigurator/resources/input/sensorconfig/autogenerated/lds_lfcd_sensor___turtlebot3_burger.xml b/src/var/FeatureModelConfigurator/resources/input/sensorconfig/autogenerated/lds_lfcd_sensor___turtlebot3_burger.xml index 8383bdc..d45c61c 100644 --- a/src/var/FeatureModelConfigurator/resources/input/sensorconfig/autogenerated/lds_lfcd_sensor___turtlebot3_burger.xml +++ b/src/var/FeatureModelConfigurator/resources/input/sensorconfig/autogenerated/lds_lfcd_sensor___turtlebot3_burger.xml @@ -17,7 +17,7 @@ </scan> <range> <min>0.120</min> - <max>16</max> + <max>3.5</max> <resolution>0.015</resolution> </range> <noise> diff --git a/src/var/FeatureModelConfigurator/src/Adapter.java b/src/var/FeatureModelConfigurator/src/Adapter.java index f10e1a1..97f7018 100644 --- a/src/var/FeatureModelConfigurator/src/Adapter.java +++ b/src/var/FeatureModelConfigurator/src/Adapter.java @@ -1,302 +1,98 @@ -import java.io.*; -import java.util.*; - -import org.jdom2.*; +import java.util.ArrayList; +import java.util.List; +import java.io.IOException; +import org.jdom2.Document; +import org.jdom2.Attribute; +import org.jdom2.JDOMException; /** - * Takes a featuremodel.xml file generated using FeatureModelConfigurator and a given .gazebo.xacro and urdf.xacro file. - * The .gazebo.xacro and .urdf.xacro files are modified to support the features specified in the featuremodel.xml file. + * Class that provides input/ output info and other variables an adapter may use + * by reading from featuremodel generated using FeatureModelConfigurator. */ -public class Adapter extends XMLHelper { +public class Adapter extends UserSetIOReader { + //Hard coded input/ output (because the project directory is designed like this) + public final String in_fmName = "featuremodel.xml"; + public final String in_fmPath = "./resources/output/"; + + private final String in_scPath = "./resources/input/sensorconfig/"; + public final String scAutoPath = in_scPath+"autogenerated/"; + public final String scOtherPath = in_scPath+"other/"; + + //Variables used exclusively by adapters + public final String mode; + public final List<Document> sensorConfigList; + public final String botName; /** - * Obtains an attribute value of the input/ output entries specified in adapter.config. + * Constructor defining a general adapter. * - * @param doc The JDOM Document (adapter.config) - * @param entry String formed as "{input or output}/{entity}" - * @param val Attribute name as String - * @return path as specified in adapter.config + * When reading input, scAutoPath, scOtherPath and in_fmPath may contain other + * files that will be filtered out. + * + * @throws IOException + * @throws JDOMException */ - private static String getConfigVal(Document doc, String str, String val) { - List<Attribute> valList = xQueryAttributes(doc, "//"+str+"/@"+val); - if(valList.size()!=1) { - System.err.println("Error while reading input/ output "+val+" value from adapter.config."); + public Adapter() throws JDOMException, IOException { + super(); + + Document featureModel = XMLHelper.readXml(in_fmPath+in_fmName); + + //Get the selected mode (either NO_CHANGE or Custom) as String + List<Attribute> modeList = XMLHelper.xQueryAttributes(featureModel, "//mode/@param"); + if(modeList.size()!=1) { + System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); System.exit(-1); } - - return valList.get(0).getValue(); - } - - /** - * Call this to run Adapter. - */ - //public static void main(String[] args) { - public Adapter() { - System.out.println("Adapter started."); - try { - final String SC_ENDING = ".xml"; - final String GX_ENDING = ".gazebo.xacro"; - final String UX_ENDING = ".urdf.xacro"; - - //######### Input ############################### - Document adapterConfig = readXml("./adapter.config"); - - //Get adapter.config values. - String in_fmPath = getConfigVal(adapterConfig, "input/featuremodel", "path"); - String in_scPath = getConfigVal(adapterConfig, "input/sensorconfig", "path"); - String in_gxPath = getConfigVal(adapterConfig, "input/gazebo_xacro", "path"); - String in_uxPath = getConfigVal(adapterConfig, "input/urdf_xacro", "path"); - String out_gxPath = getConfigVal(adapterConfig, "output/gazebo_xacro", "path"); - String out_uxPath = getConfigVal(adapterConfig, "output/urdf_xacro", "path"); - String out_bnPath = getConfigVal(adapterConfig, "output/botname", "path"); - - String in_fmName = getConfigVal(adapterConfig, "input/featuremodel", "name"); - String in_gxName = ""; - String in_uxName = ""; - String out_gxName = getConfigVal(adapterConfig, "output/gazebo_xacro", "name"); - String out_uxName = getConfigVal(adapterConfig, "output/urdf_xacro", "name"); - String out_bnName = getConfigVal(adapterConfig, "output/botname", "name"); - - String scAutoPath = in_scPath+"autogenerated/"; - String scOtherPath = in_scPath+"other/"; - - String unwantedPrefix = getConfigVal(adapterConfig, "output/botname", "remove_prefix"); - String unwantedSuffix = getConfigVal(adapterConfig, "output/botname", "remove_suffix"); - - //Declare Documents. - Document featureModel = readXml(in_fmPath+in_fmName); - List<Document> sensorConfigList = new ArrayList<Document>(); - Document gazeboModel = null; - Document urdfModel = null; - - //Get the selected mode (either NO_CHANGE or Custom) as String. - String mode = ""; - - List<Attribute> modeList = xQueryAttributes(featureModel, "//mode/@param"); - if(modeList.size()==1) { - mode = modeList.get(0).getValue(); - } - else { - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); - System.exit(-1); - } - - //Get all selected sensorconfig files as List<Document>. - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - List<Attribute> sensorList = xQueryAttributes(featureModel, "//sensor/@name"); - -// List<String> scAutoList = getFileNames(scAutoPath); -// List<String> scOtherList = getFileNames(scOtherPath); -// List<String> scList = new ArrayList<String>(); -// scList.addAll(scAutoList); -// scList.addAll(scOtherList); -// -// for(Attribute sensor : sensorList) { -// boolean inDirectory = false; -// for(String fileName : scList) { -// if(fileName.equals(sensor.getValue()+SC_ENDING)) { -// inDirectory = true; -// } -// } -// if(!inDirectory) { -// System.err.println("Cannot handle \'"+sensor.getValue()+"\': No input file known."); -// System.exit(-1); -// } -// } - - for(Attribute sensor : sensorList) { - String fileName = sensor.getValue()+SC_ENDING; - List<String> fileMatches= findFile(fileName, in_scPath); - - if(fileMatches.isEmpty()) { - System.err.println("Cannot handle \'"+sensor.getValue()+"\': No input file known."); - System.exit(-1); - } - - if(fileMatches.size()==1) { - sensorConfigList.add(readXml(fileMatches.get(0))); - } - else { - System.err.println("Cannot handle \'"+sensor.getValue()+"\': Multiple input files found:"); - for(String match : fileMatches) { - System.err.println("\'"+match+"\'"); - } - System.exit(-1); - } - } - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + mode = modeList.get(0).getValue(); + + //Get the name of the selected bot as String + List<Attribute> botList = XMLHelper.xQueryAttributes(featureModel, "//templates/@name"); + if(botList.size()!=1) { + System.err.println("Invalid input in \'"+in_fmName+"\': No or multiple bots selected."); + System.exit(-1); + } + + botName = botList.get(0).getValue(); + + //Get all selected sensorconfig files as List<Document> + sensorConfigList = new ArrayList<Document>(); + + switch(mode) { + case "NO_CHANGE": + break; + case "Custom": + List<Attribute> selectedSensorList = XMLHelper.xQueryAttributes(featureModel, "//sensor/@name"); + + for(Attribute selectedSensor : selectedSensorList) { + String fileName = selectedSensor.getValue()+SC_ENDING; + + List<String> fileMatchAutoList = XMLHelper.findFile(fileName, scAutoPath); + List<String> fileMatchOtherList = XMLHelper.findFile(fileName, scOtherPath); + List<String> fileMatchList = new ArrayList<String>(); + fileMatchList.addAll(fileMatchAutoList); + fileMatchList.addAll(fileMatchOtherList); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+fileName+"\': No input file known."); System.exit(-1); - } - - //Get the name of the selected bot as String. - String botName = ""; - - List<Attribute> botList = xQueryAttributes(featureModel, "//templates/@name"); - if(botList.size()==1) { - botName = botList.get(0).getValue(); - } - else { - System.err.println("Invalid input in \'"+in_fmName+"\': No or multiple bots selected."); - System.exit(-1); - } - - //Get the selected .gazebo.xacro file as Document. - in_gxName = botName+GX_ENDING; - - List<String> gxList = getFileNames(in_gxPath); - boolean inDirectory = false; - for(String fileName : gxList) { - if(fileName.equals(in_gxName)) { - inDirectory = true; } - } - if(!inDirectory) { - System.err.println("Cannot handle \'"+botName+"\': No \'"+GX_ENDING+"\' input file known."); - System.exit(-1); - } - - gazeboModel = readXml(in_gxPath+in_gxName); - - //Get the corresponding .urdf.xacro file as Document. - in_uxName = botName+UX_ENDING; - - List<String> urdfList = getFileNames(in_uxPath); - inDirectory = false; - for(String fileName : urdfList) { - if(fileName.equals(in_uxName)) { - inDirectory = true; - } - } - if(!inDirectory) { - System.err.println("Cannot handle \'"+botName+"\': No \'"+UX_ENDING+"\' input file known."); - System.exit(-1); - } - - urdfModel = readXml(in_uxPath+in_uxName); - //############################################### - - - //######### Operate on .gazebo.xacro ############ - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - //Remove all existing sensors in template. - List<Element> removableSensorsList = xQueryElements(gazeboModel, "//sensor"); - - for(Element sensor : removableSensorsList) { - Element entry = sensor.getParentElement(); - if(entry.getName().equals("gazebo")) { - entry.detach(); - } - else { - System.out.println("Found a <sensor> element in \'"+in_gxName+ - "\' that does not have a <gazebo> element as immediate parent. It was not removed, as this input is unexpected."); - } - } - - //Insert selected sensors into template. - for(Document sensorConfig : sensorConfigList) { - List<Element> sensorList = xQueryElements(sensorConfig, "//gazebo"); - if(sensorList.size()==1) { - Element sensor = sensorList.get(0); - - //Warn if a sensor still contains $(arg ...) values. - List<Element> tagList = xQueryElements(sensor, "//*"); - for(Element tag : tagList) { - String text = tag.getText(); - if(text.contains("$")) { - System.out.println("Warning: a sensorconfig file still contains an abstract value: \'"+text+ - "\'. It should be replaced with a set value, or the output .gazebo.xacro will likely be broken."); - } - } - - sensor.detach(); - gazeboModel.getRootElement().addContent(sensor); - } - else { - System.err.println("Invalid input. At least one sensorconfig file contains no or multiple <gazebo> entries."); - System.exit(-1); - } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+fileName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); } - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); System.exit(-1); + } + + sensorConfigList.add(XMLHelper.readXml(fileMatchList.get(0))); } - //############################################### - - - //######### Operate on .urdf.xacro ############## - final Namespace NS = urdfModel.getRootElement().getNamespace("xacro"); - - //Set <xacro:include> tags - List<Element> includeList = xQueryElements(urdfModel, "//xacro:include", NS); - if(includeList.size()!=2) { - System.err.println("Invalid input in \'"+in_uxName+"\': Expected exactly 2 xacro:include tags."); - System.exit(-1); - } - String gxDestDirectoryName = (new File(out_gxPath)).getName(); - //includeList.get(0).setAttribute("filename", "$(find "+CommonPropDestDirectoryName+")/common_properties.xacro");//TODO - includeList.get(1).setAttribute("filename", "$(find "+gxDestDirectoryName+")/"+out_gxName); - - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - //TODO - //If the urdf.xacro would be modified (to have an accurate visual model with the sensors attached to it), - //this needs to happen here. (Delete or Insert <link>/ <joint> tags.) - //This would require separate files with <link>/ <joint> tags for each sensor and bot for the Adapter to access... - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); - System.exit(-1); - } - //############################################### - - - //######### Output result ####################### - //Output model files. - saveAsXml(gazeboModel, out_gxPath+out_gxName); - - saveAsXml(urdfModel, out_uxPath+out_uxName); - - //Output botName. - String alteredBotName = botName; - if(alteredBotName.startsWith(unwantedPrefix)) { - alteredBotName = alteredBotName.substring(unwantedPrefix.length(), alteredBotName.length()); - } - else { - System.out.println("Warning: Prefix \'"+unwantedPrefix+"\' could not be removed from bot name."); - } - if(alteredBotName.endsWith(unwantedSuffix)) { - alteredBotName = alteredBotName.substring(0, alteredBotName.length() - unwantedSuffix.length()); - } - else { - System.out.println("Warning: Suffix \'"+unwantedSuffix+"\' could not be removed from bot name."); - } - - BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(out_bnPath+out_bnName)); - bufferedWriter.write(alteredBotName); - bufferedWriter.close(); - //############################################### - } - catch (Exception e) { - e.printStackTrace(); + break; + default: + System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); } - - System.out.println("Adapter finished."); } } - - - diff --git a/src/var/FeatureModelConfigurator/src/BotNameAdapter.java b/src/var/FeatureModelConfigurator/src/BotNameAdapter.java new file mode 100644 index 0000000..56b91a9 --- /dev/null +++ b/src/var/FeatureModelConfigurator/src/BotNameAdapter.java @@ -0,0 +1,67 @@ +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting the selected bots name. + */ +public class BotNameAdapter extends Adapter { + //Variables used exclusively by botName adapter + public final String alteredBotName; + + /** + * Creates a runnable Adapter for the "botname.txt"(out_bnName) output file. + * + * @throws IOException + * @throws JDOMException + */ + public BotNameAdapter() throws JDOMException, IOException { + super(); + + //Get the altered botName (botName with unwantedPrefix and unwantedSuffix removed) + String tmp = botName; + if(tmp.startsWith(unwantedPrefix)) { + tmp = tmp.substring(unwantedPrefix.length(), tmp.length()); + } + else { + System.out.println("Warning: Prefix \'"+unwantedPrefix+"\' could not be removed from bot name."); + } + if(tmp.endsWith(unwantedSuffix)) { + tmp = tmp.substring(0, tmp.length() - unwantedSuffix.length()); + } + else { + System.out.println("Warning: Suffix \'"+unwantedSuffix+"\' could not be removed from bot name."); + } + + alteredBotName = tmp; + } + + /** + * Run the Adapter for the "botname.txt"(out_bnName) output file. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("BotNameAdapter started."); + + //Output alteredBotName + this.output(); + + System.out.println("BotNameAdapter finished."); + } + + /** + * Output alteredBotName as "botname.txt"(out_bnName) file. + * + * @throws IOException + */ + private void output() throws IOException { + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(this.out_bnPath+this.out_bnName)); + bufferedWriter.write(this.alteredBotName); + bufferedWriter.close(); + } + +} diff --git a/src/var/FeatureModelConfigurator/src/Configurator.jak b/src/var/FeatureModelConfigurator/src/Configurator.jak index 4e48e00..b8dfb6a 100644 --- a/src/var/FeatureModelConfigurator/src/Configurator.jak +++ b/src/var/FeatureModelConfigurator/src/Configurator.jak @@ -106,8 +106,19 @@ abstract class Configurator$$ConfiguratorMain { return; } - //create and launch Adapter - new Adapter(); + //create and launch adapters + try { + GazeboAdapter oGazeboAdapter = new GazeboAdapter(); + oGazeboAdapter.run(); + UrdfAdapter oUrdfAdapter = new UrdfAdapter(); + oUrdfAdapter.run(); + BotNameAdapter oBotNameAdapter = new BotNameAdapter(); + oBotNameAdapter.run(); + } + catch (Exception oEx) { + System.out.println(oEx); + return; + } } //get all parents of a given module from the Feature Model file diff --git a/src/var/FeatureModelConfigurator/src/Configurator.java b/src/var/FeatureModelConfigurator/src/Configurator.java index ee822aa..3c33295 100644 --- a/src/var/FeatureModelConfigurator/src/Configurator.java +++ b/src/var/FeatureModelConfigurator/src/Configurator.java @@ -106,8 +106,19 @@ abstract class Configurator$$ConfiguratorMain { return; } - //create and launch Adapter - new Adapter(); + //create and launch adapters + try { + GazeboAdapter oGazeboAdapter = new GazeboAdapter(); + oGazeboAdapter.run(); + UrdfAdapter oUrdfAdapter = new UrdfAdapter(); + oUrdfAdapter.run(); + BotNameAdapter oBotNameAdapter = new BotNameAdapter(); + oBotNameAdapter.run(); + } + catch (Exception oEx) { + System.out.println(oEx); + return; + } } //get all parents of a given module from the Feature Model file diff --git a/src/var/FeatureModelConfigurator/src/GazeboAdapter.java b/src/var/FeatureModelConfigurator/src/GazeboAdapter.java new file mode 100644 index 0000000..87237c3 --- /dev/null +++ b/src/var/FeatureModelConfigurator/src/GazeboAdapter.java @@ -0,0 +1,155 @@ +import java.util.List; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting a .gazebo.xacro file based on + * featuremodel info. + */ +public class GazeboAdapter extends Adapter { + //Variables used exclusively by .gazebo.xacro adapter + public final String in_gxName; + public final Document gazeboModel; + + /** + * Creates a runnable Adapter for .gazebo.xacro files. + * + * When reading input in_gxPath may contain other files that will be filtered out. + * + * @throws IOException + * @throws JDOMException + */ + public GazeboAdapter() throws JDOMException, IOException { + super(); + + //Get the selected .gazebo.xacro file name as String + in_gxName = botName+GX_ENDING; + + //Get the selected .gazebo.xacro file as Document + List<String> fileMatchList = XMLHelper.findFile(in_gxName, in_gxPath); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+in_gxName+"\': No input file known."); + System.exit(-1); + } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+in_gxName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); + } + System.exit(-1); + } + + gazeboModel = XMLHelper.readXml(fileMatchList.get(0)); + } + + /** + * Run the Adapter for .gazebo.xacro files. + * Depending on the selected mode, this Adapter will either: + * (NO_CHANGE) - Do nothing. + * + * (Custom) - Remove all existing sensors in gazeboModel template. + * - Insert only the selected sensors. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("GazeboAdapter started."); + + switch(this.mode) { + case "NO_CHANGE": + break; + case "Custom": + //Remove all existing sensors in template + this.removeExistingSensors(); + + //Insert selected sensors into template + this.insertSelectedSensors(); + break; + default: + System.err.println("Invalid input in \'"+this.in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); + } + + //Output gazeboModel + this.output(); + + System.out.println("GazeboAdapter finished."); + } + + /** + * Removes all existing sensors (with its enclosing {@code <gazebo>} tag) from gazeboModel. + */ + private void removeExistingSensors() { + List<Element> removableSensorsList = XMLHelper.xQueryElements(this.gazeboModel, "//sensor"); + + for(Element sensor : removableSensorsList) { + Element entry = sensor.getParentElement(); + if(entry.getName().equals("gazebo")) { + entry.detach(); + } + else { + System.out.println("Warning: Found a <sensor> element in \'"+this.in_gxName+ + "\' that does not have a <gazebo> element as immediate parent. It was not removed, as this input is unexpected."); + } + } + } + + /** + * Inserts all selected sensors (with its enclosing {@code <gazebo>} tag) into gazeboModel. + */ + private void insertSelectedSensors() { + for(Document sensorConfig : this.sensorConfigList) { + List<Element> sensorList = XMLHelper.xQueryElements(sensorConfig, "//gazebo"); + + if(sensorList.size()!=1) { + System.err.println("Invalid input. At least one sensorconfig file contains no or multiple <gazebo> entries."); + System.exit(-1); + } + + Element sensor = sensorList.get(0); + + //Warn if a sensor still contains $(arg ...) values + checkForArg(sensor); + + sensor.detach(); + this.gazeboModel.getRootElement().addContent(sensor); + + + } + } + + /** + * Checks if an Element still contains $(arg ...) values. + * Only exists because because someone might manually create a sensorconfig by copying + * from a .gazebo.xacro template and forget that $(arg ...) values are still inside. + */ + private static boolean checkForArg(Element element) { + boolean detected = false; + List<Element> tagList = XMLHelper.xQueryElements(element, "//*"); + + for(Element tag : tagList) { + String text = tag.getText(); + if(text.contains("$")) { + System.out.println("Warning: A sensorconfig file still contains an abstract value: \'"+text+ + "\'. It should be replaced with a set value, or the output .gazebo.xacro will likely be broken."); + detected = true; + } + } + + return detected; + } + + /** + * Output the gazeboModel as XML file. + * + * @throws IOException + */ + private void output() throws IOException { + XMLHelper.saveAsXml(this.gazeboModel, this.out_gxPath+this.out_gxName); + } +} diff --git a/src/var/FeatureModelConfigurator/src/UrdfAdapter.java b/src/var/FeatureModelConfigurator/src/UrdfAdapter.java new file mode 100644 index 0000000..5006bb5 --- /dev/null +++ b/src/var/FeatureModelConfigurator/src/UrdfAdapter.java @@ -0,0 +1,136 @@ +import java.util.List; +import java.io.File; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting a .urdf.xacro file based on + * featuremodel info. + */ +public class UrdfAdapter extends Adapter { + //Variables used exclusively by .urdf.xacro adapter + public final String in_uxName; + public final Document urdfModel; + public final Namespace NS; + + /** + * Creates a runnable Adapter for .urdf.xacro files. + * + * When reading input in_uxPath may contain other files that will be filtered out. + * + * @throws IOException + * @throws JDOMException + */ + public UrdfAdapter() throws JDOMException, IOException { + super(); + + //Get the selected .urdf.xacro file name as String + in_uxName = botName+UX_ENDING; + + //Get the selected .urdf.xacro file as Document + List<String> fileMatchList = XMLHelper.findFile(in_uxName, in_uxPath); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+in_uxName+"\': No input file known."); + System.exit(-1); + } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+in_uxName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); + } + System.exit(-1); + } + + urdfModel = XMLHelper.readXml(fileMatchList.get(0)); + + //Get the "xacro" namespace of the .urdf.xacro document as Namespace + NS = urdfModel.getRootElement().getNamespace("xacro"); + } + + /** + * Run the Adapter for .urdf.xacro files. + * + * Sets the {@code <xacro:include>} tags. + * The links/ joints are not edited, as the precise visual bot representation is not + * important for this project. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("UrdfAdapter started."); + + //Set <xacro:include> tags + this.setInclude(); + + switch(this.mode) { + case "NO_CHANGE": + break; + case "Custom": + /** + * If the urdf.xacro would be modified (to have an accurate visual model with the sensors attached to it), + * this needs to happen here. (Delete or Insert <link> and <joint> tags.) + * This would require separate files with <link> and <joint> tags for each bot and sensor for the Adapter to access. + * + * For example, like this: + * The "autogenerated"/"other" directory gets one child directory for each bot. + * Each of these new directories contains one file for each sensorconfig with the building blocks + * to be inserted in .urdf.xacro, just like the sensorconfigs contain building blocks + * for the .gazebo.xacro files. + */ + break; + default: + System.err.println("Invalid input in \'"+this.in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); + } + + //Output urdfModel + this.output(); + + System.out.println("UrdfAdapter finished."); + } + + /** + * Sets {@code <xacro:include>} tags in urdfModel to correctly point to the files to be included. + */ + private void setInclude() { + List<Element> includeList = XMLHelper.xQueryElements(this.urdfModel, "//xacro:include", this.NS); + + if(includeList.size()!=2) { + System.err.println("Unexpected input in \'"+this.in_uxName+"\': Expected exactly 2 <xacro:include> tags."); + System.exit(-1); + } + + int gxIndex; + int commonPropIndex; + if(includeList.get(0).getAttributeValue("filename").endsWith(GX_ENDING)) { + gxIndex = 0; + commonPropIndex = 1; + } + else { + gxIndex = 1; + commonPropIndex = 0; + } + + String gxDestDirectoryName = (new File(this.out_gxPath)).getName(); + includeList.get(gxIndex).setAttribute("filename", "$(find "+gxDestDirectoryName+")/"+this.out_gxName); + + //The common_properties.xacro stays in its original directory, so this is not edited + //String commonPropDestDirectoryName = ; + //includeList.get(commonPropIndex).setAttribute("filename", "$(find "+commonPropDestDirectoryName+")/common_properties.xacro"); + } + + /** + * Output the urdfModel as XML file. + * + * @throws IOException + */ + private void output() throws IOException { + XMLHelper.saveAsXml(this.urdfModel, this.out_uxPath+this.out_uxName); + } +} diff --git a/src/var/FeatureModelConfigurator/src/UserSetIOReader.java b/src/var/FeatureModelConfigurator/src/UserSetIOReader.java new file mode 100644 index 0000000..409a517 --- /dev/null +++ b/src/var/FeatureModelConfigurator/src/UserSetIOReader.java @@ -0,0 +1,88 @@ +import java.util.List; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Attribute; +import org.jdom2.JDOMException; + + +/** + * Class that allows for reading input from usersetio.config. + */ +public class UserSetIOReader { + //File endings + public static final String SC_ENDING = ".xml"; + public static final String GX_ENDING = ".gazebo.xacro"; + public static final String UX_ENDING = ".urdf.xacro"; + + //Input/ output as defined by user + public final String in_gxPath; + + public final String in_uxPath; + + public final String out_gxName; + public final String out_gxPath; + + public final String out_uxName; + public final String out_uxPath; + + public final String out_bnName; + public final String out_bnPath; + public final String unwantedPrefix; + public final String unwantedSuffix; + + /** + * Constructor reading from default usersetio.config location. + * + * @throws IOException + * @throws JDOMException + */ + public UserSetIOReader() throws JDOMException, IOException { + this("./../usersetio.config"); + } + + /** + * Constructor reading all values from usersetio.config. + * io.config contains all values that the user will want to set manually. + * + * @param path Location of usersetio.config. + * @throws IOException + * @throws JDOMException + */ + private UserSetIOReader(String path) throws JDOMException, IOException { + Document config = XMLHelper.readXml(path); + + in_gxPath = getConfigVal(config, "input/gazebo_xacro", "path"); + + in_uxPath = getConfigVal(config, "input/urdf_xacro", "path"); + + out_gxName = getConfigVal(config, "output/gazebo_xacro", "name"); + out_gxPath = getConfigVal(config, "output/gazebo_xacro", "path"); + + out_uxName = getConfigVal(config, "output/urdf_xacro", "name"); + out_uxPath = getConfigVal(config, "output/urdf_xacro", "path"); + + out_bnName = getConfigVal(config, "output/botname", "name"); + out_bnPath = getConfigVal(config, "output/botname", "path"); + unwantedPrefix = getConfigVal(config, "output/botname", "remove_prefix"); + unwantedSuffix = getConfigVal(config, "output/botname", "remove_suffix"); + } + + /** + * Obtains an attribute value of the input/ output entries specified in *.config. + * + * @param doc The JDOM Document (*.config) + * @param entry String formed as "{input or output}/{entity}" + * @param val Attribute name as String + * @return XML-attribute specified in entry of doc (*.config) as String + */ + public static String getConfigVal(Document doc, String entry, String val) { + List<Attribute> valList = XMLHelper.xQueryAttributes(doc, "//"+entry+"/@"+val); + if(valList.size()!=1) { + System.err.println("Error while reading input/ output \'"+val+"\' value from *.config."); + System.exit(-1); + } + + return valList.get(0).getValue(); + } +} diff --git a/src/var/FeatureModelConfigurator/src/XMLHelper.java b/src/var/FeatureModelConfigurator/src/XMLHelper.java index 08c3067..36f589c 100644 --- a/src/var/FeatureModelConfigurator/src/XMLHelper.java +++ b/src/var/FeatureModelConfigurator/src/XMLHelper.java @@ -9,7 +9,6 @@ import org.jdom2.output.XMLOutputter; import org.jdom2.xpath.*; - /** * Contains methods based on JDOM and Jaxen library that help processing XML files and other misc ones. */ @@ -126,12 +125,13 @@ public class XMLHelper { * * @param name Name of the file including file ending as String * @param path Path to directory to be searched as String - * @return path to all file matches as List<String> (e.g. .../sensorconfig/other/imu.xml) + * @return path to all file matches as {@code List<String>} (e.g. .../sensorconfig/other/imu.xml) */ public static List<String> findFile(String name, String path) { List<String> accumulator = new ArrayList<String>(); + findFile(name, path, accumulator); - return findFile(name, path, accumulator); + return accumulator; } /** @@ -139,23 +139,20 @@ public class XMLHelper { * * @param name Name of the file including file ending as String * @param path Path to directory to be searched as String - * @param result Accumulator for all file matches as List<String> - * @return path to all file matches as list<String> (e.g. .../sensorconfig/other/imu.xml) + * @param result Accumulator for all file matches as {@code List<String>} */ - private static List<String> findFile(String name, String path, List<String> result) { + private static void findFile(String name, String path, List<String> result) { File element = new File(path); File[] content = element.listFiles(); + //content==null if it is not a directory if(content != null) { for(File file : content) { - List<String> subResult = findFile(name, path+"/"+file.getName(), result); - result.addAll(subResult); + findFile(name, path+"/"+file.getName(), result); } } if(element.getName().equals(name)) { - result.add(element.getName()); + result.add(element.getPath()); } - - return result; } /** @@ -455,12 +452,4 @@ public class XMLHelper { return false; } - - /** - * @param args - */ - public static void main(String[] args) { - - } } - diff --git a/src/var/FeatureModelImplGenerator/modelsetup.config b/src/var/FeatureModelImplGenerator/modelsetup.config deleted file mode 100644 index dc02769..0000000 --- a/src/var/FeatureModelImplGenerator/modelsetup.config +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0"?> -<!-- ModelSetup configuration file. --> -<!-- Path (relative path to ModelSetup.java location) and name value can be changed. --> -<modelsetup> - <input> - <!-- Path to and name of model template for Feature IDE. --> - <model type="file" name="modelTemplate.xml" path="./template/" /> - <!-- Path to all available sensor configuration .xml files. --> - <!-- Files with other endings are allowed and will be ignored. --> - <sensorconfig type="directory" path="./../FeatureModelConfigurator/resources/input/sensorconfig/" /> - <!-- Path to all available .gazebo.xacro files. --> - <!-- Files with other endings are allowed and will be ignored. --> - <gazebo_xacro type="directory" path="./../../sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/" /> - </input> - <output> - <!-- Path to and name of the generated Feature IDE model file. --> - <model type="file" name="model.xml" path="./../FeatureModelConfigurator/" /> - </output> -</modelsetup> diff --git a/src/var/FeatureModelImplGenerator/src/Adapter.java b/src/var/FeatureModelImplGenerator/src/Adapter.java index f10e1a1..97f7018 100644 --- a/src/var/FeatureModelImplGenerator/src/Adapter.java +++ b/src/var/FeatureModelImplGenerator/src/Adapter.java @@ -1,302 +1,98 @@ -import java.io.*; -import java.util.*; - -import org.jdom2.*; +import java.util.ArrayList; +import java.util.List; +import java.io.IOException; +import org.jdom2.Document; +import org.jdom2.Attribute; +import org.jdom2.JDOMException; /** - * Takes a featuremodel.xml file generated using FeatureModelConfigurator and a given .gazebo.xacro and urdf.xacro file. - * The .gazebo.xacro and .urdf.xacro files are modified to support the features specified in the featuremodel.xml file. + * Class that provides input/ output info and other variables an adapter may use + * by reading from featuremodel generated using FeatureModelConfigurator. */ -public class Adapter extends XMLHelper { +public class Adapter extends UserSetIOReader { + //Hard coded input/ output (because the project directory is designed like this) + public final String in_fmName = "featuremodel.xml"; + public final String in_fmPath = "./resources/output/"; + + private final String in_scPath = "./resources/input/sensorconfig/"; + public final String scAutoPath = in_scPath+"autogenerated/"; + public final String scOtherPath = in_scPath+"other/"; + + //Variables used exclusively by adapters + public final String mode; + public final List<Document> sensorConfigList; + public final String botName; /** - * Obtains an attribute value of the input/ output entries specified in adapter.config. + * Constructor defining a general adapter. * - * @param doc The JDOM Document (adapter.config) - * @param entry String formed as "{input or output}/{entity}" - * @param val Attribute name as String - * @return path as specified in adapter.config + * When reading input, scAutoPath, scOtherPath and in_fmPath may contain other + * files that will be filtered out. + * + * @throws IOException + * @throws JDOMException */ - private static String getConfigVal(Document doc, String str, String val) { - List<Attribute> valList = xQueryAttributes(doc, "//"+str+"/@"+val); - if(valList.size()!=1) { - System.err.println("Error while reading input/ output "+val+" value from adapter.config."); + public Adapter() throws JDOMException, IOException { + super(); + + Document featureModel = XMLHelper.readXml(in_fmPath+in_fmName); + + //Get the selected mode (either NO_CHANGE or Custom) as String + List<Attribute> modeList = XMLHelper.xQueryAttributes(featureModel, "//mode/@param"); + if(modeList.size()!=1) { + System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); System.exit(-1); } - - return valList.get(0).getValue(); - } - - /** - * Call this to run Adapter. - */ - //public static void main(String[] args) { - public Adapter() { - System.out.println("Adapter started."); - try { - final String SC_ENDING = ".xml"; - final String GX_ENDING = ".gazebo.xacro"; - final String UX_ENDING = ".urdf.xacro"; - - //######### Input ############################### - Document adapterConfig = readXml("./adapter.config"); - - //Get adapter.config values. - String in_fmPath = getConfigVal(adapterConfig, "input/featuremodel", "path"); - String in_scPath = getConfigVal(adapterConfig, "input/sensorconfig", "path"); - String in_gxPath = getConfigVal(adapterConfig, "input/gazebo_xacro", "path"); - String in_uxPath = getConfigVal(adapterConfig, "input/urdf_xacro", "path"); - String out_gxPath = getConfigVal(adapterConfig, "output/gazebo_xacro", "path"); - String out_uxPath = getConfigVal(adapterConfig, "output/urdf_xacro", "path"); - String out_bnPath = getConfigVal(adapterConfig, "output/botname", "path"); - - String in_fmName = getConfigVal(adapterConfig, "input/featuremodel", "name"); - String in_gxName = ""; - String in_uxName = ""; - String out_gxName = getConfigVal(adapterConfig, "output/gazebo_xacro", "name"); - String out_uxName = getConfigVal(adapterConfig, "output/urdf_xacro", "name"); - String out_bnName = getConfigVal(adapterConfig, "output/botname", "name"); - - String scAutoPath = in_scPath+"autogenerated/"; - String scOtherPath = in_scPath+"other/"; - - String unwantedPrefix = getConfigVal(adapterConfig, "output/botname", "remove_prefix"); - String unwantedSuffix = getConfigVal(adapterConfig, "output/botname", "remove_suffix"); - - //Declare Documents. - Document featureModel = readXml(in_fmPath+in_fmName); - List<Document> sensorConfigList = new ArrayList<Document>(); - Document gazeboModel = null; - Document urdfModel = null; - - //Get the selected mode (either NO_CHANGE or Custom) as String. - String mode = ""; - - List<Attribute> modeList = xQueryAttributes(featureModel, "//mode/@param"); - if(modeList.size()==1) { - mode = modeList.get(0).getValue(); - } - else { - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); - System.exit(-1); - } - - //Get all selected sensorconfig files as List<Document>. - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - List<Attribute> sensorList = xQueryAttributes(featureModel, "//sensor/@name"); - -// List<String> scAutoList = getFileNames(scAutoPath); -// List<String> scOtherList = getFileNames(scOtherPath); -// List<String> scList = new ArrayList<String>(); -// scList.addAll(scAutoList); -// scList.addAll(scOtherList); -// -// for(Attribute sensor : sensorList) { -// boolean inDirectory = false; -// for(String fileName : scList) { -// if(fileName.equals(sensor.getValue()+SC_ENDING)) { -// inDirectory = true; -// } -// } -// if(!inDirectory) { -// System.err.println("Cannot handle \'"+sensor.getValue()+"\': No input file known."); -// System.exit(-1); -// } -// } - - for(Attribute sensor : sensorList) { - String fileName = sensor.getValue()+SC_ENDING; - List<String> fileMatches= findFile(fileName, in_scPath); - - if(fileMatches.isEmpty()) { - System.err.println("Cannot handle \'"+sensor.getValue()+"\': No input file known."); - System.exit(-1); - } - - if(fileMatches.size()==1) { - sensorConfigList.add(readXml(fileMatches.get(0))); - } - else { - System.err.println("Cannot handle \'"+sensor.getValue()+"\': Multiple input files found:"); - for(String match : fileMatches) { - System.err.println("\'"+match+"\'"); - } - System.exit(-1); - } - } - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + mode = modeList.get(0).getValue(); + + //Get the name of the selected bot as String + List<Attribute> botList = XMLHelper.xQueryAttributes(featureModel, "//templates/@name"); + if(botList.size()!=1) { + System.err.println("Invalid input in \'"+in_fmName+"\': No or multiple bots selected."); + System.exit(-1); + } + + botName = botList.get(0).getValue(); + + //Get all selected sensorconfig files as List<Document> + sensorConfigList = new ArrayList<Document>(); + + switch(mode) { + case "NO_CHANGE": + break; + case "Custom": + List<Attribute> selectedSensorList = XMLHelper.xQueryAttributes(featureModel, "//sensor/@name"); + + for(Attribute selectedSensor : selectedSensorList) { + String fileName = selectedSensor.getValue()+SC_ENDING; + + List<String> fileMatchAutoList = XMLHelper.findFile(fileName, scAutoPath); + List<String> fileMatchOtherList = XMLHelper.findFile(fileName, scOtherPath); + List<String> fileMatchList = new ArrayList<String>(); + fileMatchList.addAll(fileMatchAutoList); + fileMatchList.addAll(fileMatchOtherList); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+fileName+"\': No input file known."); System.exit(-1); - } - - //Get the name of the selected bot as String. - String botName = ""; - - List<Attribute> botList = xQueryAttributes(featureModel, "//templates/@name"); - if(botList.size()==1) { - botName = botList.get(0).getValue(); - } - else { - System.err.println("Invalid input in \'"+in_fmName+"\': No or multiple bots selected."); - System.exit(-1); - } - - //Get the selected .gazebo.xacro file as Document. - in_gxName = botName+GX_ENDING; - - List<String> gxList = getFileNames(in_gxPath); - boolean inDirectory = false; - for(String fileName : gxList) { - if(fileName.equals(in_gxName)) { - inDirectory = true; } - } - if(!inDirectory) { - System.err.println("Cannot handle \'"+botName+"\': No \'"+GX_ENDING+"\' input file known."); - System.exit(-1); - } - - gazeboModel = readXml(in_gxPath+in_gxName); - - //Get the corresponding .urdf.xacro file as Document. - in_uxName = botName+UX_ENDING; - - List<String> urdfList = getFileNames(in_uxPath); - inDirectory = false; - for(String fileName : urdfList) { - if(fileName.equals(in_uxName)) { - inDirectory = true; - } - } - if(!inDirectory) { - System.err.println("Cannot handle \'"+botName+"\': No \'"+UX_ENDING+"\' input file known."); - System.exit(-1); - } - - urdfModel = readXml(in_uxPath+in_uxName); - //############################################### - - - //######### Operate on .gazebo.xacro ############ - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - //Remove all existing sensors in template. - List<Element> removableSensorsList = xQueryElements(gazeboModel, "//sensor"); - - for(Element sensor : removableSensorsList) { - Element entry = sensor.getParentElement(); - if(entry.getName().equals("gazebo")) { - entry.detach(); - } - else { - System.out.println("Found a <sensor> element in \'"+in_gxName+ - "\' that does not have a <gazebo> element as immediate parent. It was not removed, as this input is unexpected."); - } - } - - //Insert selected sensors into template. - for(Document sensorConfig : sensorConfigList) { - List<Element> sensorList = xQueryElements(sensorConfig, "//gazebo"); - if(sensorList.size()==1) { - Element sensor = sensorList.get(0); - - //Warn if a sensor still contains $(arg ...) values. - List<Element> tagList = xQueryElements(sensor, "//*"); - for(Element tag : tagList) { - String text = tag.getText(); - if(text.contains("$")) { - System.out.println("Warning: a sensorconfig file still contains an abstract value: \'"+text+ - "\'. It should be replaced with a set value, or the output .gazebo.xacro will likely be broken."); - } - } - - sensor.detach(); - gazeboModel.getRootElement().addContent(sensor); - } - else { - System.err.println("Invalid input. At least one sensorconfig file contains no or multiple <gazebo> entries."); - System.exit(-1); - } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+fileName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); } - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); System.exit(-1); + } + + sensorConfigList.add(XMLHelper.readXml(fileMatchList.get(0))); } - //############################################### - - - //######### Operate on .urdf.xacro ############## - final Namespace NS = urdfModel.getRootElement().getNamespace("xacro"); - - //Set <xacro:include> tags - List<Element> includeList = xQueryElements(urdfModel, "//xacro:include", NS); - if(includeList.size()!=2) { - System.err.println("Invalid input in \'"+in_uxName+"\': Expected exactly 2 xacro:include tags."); - System.exit(-1); - } - String gxDestDirectoryName = (new File(out_gxPath)).getName(); - //includeList.get(0).setAttribute("filename", "$(find "+CommonPropDestDirectoryName+")/common_properties.xacro");//TODO - includeList.get(1).setAttribute("filename", "$(find "+gxDestDirectoryName+")/"+out_gxName); - - switch(mode) { - case "NO_CHANGE": - break; - case "Custom": - //TODO - //If the urdf.xacro would be modified (to have an accurate visual model with the sensors attached to it), - //this needs to happen here. (Delete or Insert <link>/ <joint> tags.) - //This would require separate files with <link>/ <joint> tags for each sensor and bot for the Adapter to access... - break; - default: - System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); - System.exit(-1); - } - //############################################### - - - //######### Output result ####################### - //Output model files. - saveAsXml(gazeboModel, out_gxPath+out_gxName); - - saveAsXml(urdfModel, out_uxPath+out_uxName); - - //Output botName. - String alteredBotName = botName; - if(alteredBotName.startsWith(unwantedPrefix)) { - alteredBotName = alteredBotName.substring(unwantedPrefix.length(), alteredBotName.length()); - } - else { - System.out.println("Warning: Prefix \'"+unwantedPrefix+"\' could not be removed from bot name."); - } - if(alteredBotName.endsWith(unwantedSuffix)) { - alteredBotName = alteredBotName.substring(0, alteredBotName.length() - unwantedSuffix.length()); - } - else { - System.out.println("Warning: Suffix \'"+unwantedSuffix+"\' could not be removed from bot name."); - } - - BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(out_bnPath+out_bnName)); - bufferedWriter.write(alteredBotName); - bufferedWriter.close(); - //############################################### - } - catch (Exception e) { - e.printStackTrace(); + break; + default: + System.err.println("Invalid input in \'"+in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); } - - System.out.println("Adapter finished."); } } - - - diff --git a/src/var/FeatureModelImplGenerator/src/BotNameAdapter.java b/src/var/FeatureModelImplGenerator/src/BotNameAdapter.java new file mode 100644 index 0000000..56b91a9 --- /dev/null +++ b/src/var/FeatureModelImplGenerator/src/BotNameAdapter.java @@ -0,0 +1,67 @@ +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting the selected bots name. + */ +public class BotNameAdapter extends Adapter { + //Variables used exclusively by botName adapter + public final String alteredBotName; + + /** + * Creates a runnable Adapter for the "botname.txt"(out_bnName) output file. + * + * @throws IOException + * @throws JDOMException + */ + public BotNameAdapter() throws JDOMException, IOException { + super(); + + //Get the altered botName (botName with unwantedPrefix and unwantedSuffix removed) + String tmp = botName; + if(tmp.startsWith(unwantedPrefix)) { + tmp = tmp.substring(unwantedPrefix.length(), tmp.length()); + } + else { + System.out.println("Warning: Prefix \'"+unwantedPrefix+"\' could not be removed from bot name."); + } + if(tmp.endsWith(unwantedSuffix)) { + tmp = tmp.substring(0, tmp.length() - unwantedSuffix.length()); + } + else { + System.out.println("Warning: Suffix \'"+unwantedSuffix+"\' could not be removed from bot name."); + } + + alteredBotName = tmp; + } + + /** + * Run the Adapter for the "botname.txt"(out_bnName) output file. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("BotNameAdapter started."); + + //Output alteredBotName + this.output(); + + System.out.println("BotNameAdapter finished."); + } + + /** + * Output alteredBotName as "botname.txt"(out_bnName) file. + * + * @throws IOException + */ + private void output() throws IOException { + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(this.out_bnPath+this.out_bnName)); + bufferedWriter.write(this.alteredBotName); + bufferedWriter.close(); + } + +} diff --git a/src/var/FeatureModelImplGenerator/src/GazeboAdapter.java b/src/var/FeatureModelImplGenerator/src/GazeboAdapter.java new file mode 100644 index 0000000..87237c3 --- /dev/null +++ b/src/var/FeatureModelImplGenerator/src/GazeboAdapter.java @@ -0,0 +1,155 @@ +import java.util.List; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting a .gazebo.xacro file based on + * featuremodel info. + */ +public class GazeboAdapter extends Adapter { + //Variables used exclusively by .gazebo.xacro adapter + public final String in_gxName; + public final Document gazeboModel; + + /** + * Creates a runnable Adapter for .gazebo.xacro files. + * + * When reading input in_gxPath may contain other files that will be filtered out. + * + * @throws IOException + * @throws JDOMException + */ + public GazeboAdapter() throws JDOMException, IOException { + super(); + + //Get the selected .gazebo.xacro file name as String + in_gxName = botName+GX_ENDING; + + //Get the selected .gazebo.xacro file as Document + List<String> fileMatchList = XMLHelper.findFile(in_gxName, in_gxPath); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+in_gxName+"\': No input file known."); + System.exit(-1); + } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+in_gxName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); + } + System.exit(-1); + } + + gazeboModel = XMLHelper.readXml(fileMatchList.get(0)); + } + + /** + * Run the Adapter for .gazebo.xacro files. + * Depending on the selected mode, this Adapter will either: + * (NO_CHANGE) - Do nothing. + * + * (Custom) - Remove all existing sensors in gazeboModel template. + * - Insert only the selected sensors. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("GazeboAdapter started."); + + switch(this.mode) { + case "NO_CHANGE": + break; + case "Custom": + //Remove all existing sensors in template + this.removeExistingSensors(); + + //Insert selected sensors into template + this.insertSelectedSensors(); + break; + default: + System.err.println("Invalid input in \'"+this.in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); + } + + //Output gazeboModel + this.output(); + + System.out.println("GazeboAdapter finished."); + } + + /** + * Removes all existing sensors (with its enclosing {@code <gazebo>} tag) from gazeboModel. + */ + private void removeExistingSensors() { + List<Element> removableSensorsList = XMLHelper.xQueryElements(this.gazeboModel, "//sensor"); + + for(Element sensor : removableSensorsList) { + Element entry = sensor.getParentElement(); + if(entry.getName().equals("gazebo")) { + entry.detach(); + } + else { + System.out.println("Warning: Found a <sensor> element in \'"+this.in_gxName+ + "\' that does not have a <gazebo> element as immediate parent. It was not removed, as this input is unexpected."); + } + } + } + + /** + * Inserts all selected sensors (with its enclosing {@code <gazebo>} tag) into gazeboModel. + */ + private void insertSelectedSensors() { + for(Document sensorConfig : this.sensorConfigList) { + List<Element> sensorList = XMLHelper.xQueryElements(sensorConfig, "//gazebo"); + + if(sensorList.size()!=1) { + System.err.println("Invalid input. At least one sensorconfig file contains no or multiple <gazebo> entries."); + System.exit(-1); + } + + Element sensor = sensorList.get(0); + + //Warn if a sensor still contains $(arg ...) values + checkForArg(sensor); + + sensor.detach(); + this.gazeboModel.getRootElement().addContent(sensor); + + + } + } + + /** + * Checks if an Element still contains $(arg ...) values. + * Only exists because because someone might manually create a sensorconfig by copying + * from a .gazebo.xacro template and forget that $(arg ...) values are still inside. + */ + private static boolean checkForArg(Element element) { + boolean detected = false; + List<Element> tagList = XMLHelper.xQueryElements(element, "//*"); + + for(Element tag : tagList) { + String text = tag.getText(); + if(text.contains("$")) { + System.out.println("Warning: A sensorconfig file still contains an abstract value: \'"+text+ + "\'. It should be replaced with a set value, or the output .gazebo.xacro will likely be broken."); + detected = true; + } + } + + return detected; + } + + /** + * Output the gazeboModel as XML file. + * + * @throws IOException + */ + private void output() throws IOException { + XMLHelper.saveAsXml(this.gazeboModel, this.out_gxPath+this.out_gxName); + } +} diff --git a/src/var/FeatureModelImplGenerator/src/ImplGenerator.java b/src/var/FeatureModelImplGenerator/src/ImplGenerator.java index d115a04..135d89d 100644 --- a/src/var/FeatureModelImplGenerator/src/ImplGenerator.java +++ b/src/var/FeatureModelImplGenerator/src/ImplGenerator.java @@ -11,6 +11,7 @@ import java.util.List; import org.jdom2.Attribute; import org.jdom2.Document; import org.jdom2.Element; +import org.jdom2.JDOMException; /** * A simple program that automatically generates implementations @@ -32,14 +33,23 @@ public class ImplGenerator { String m_sMainTemplatePath = "./template/Main.jak"; //input path for the module template String m_sModuleTemplatePath = "./template/Module.jak"; - //input path for the adapter - String m_sAdapterPath = "./src/Adapter.java"; - //input path for the adapter + //input path for all files needed for complete adapter functionality String m_sHelperPath = "./src/XMLHelper.java"; - //path to the resources dir + String m_sUserIOPath = "./src/UserSetIOReader.java"; + String m_sAdapterPath = "./src/Adapter.java"; + String m_sGazeboAdapterPath = "./src/GazeboAdapter.java"; + String m_sUrdfAdapterPath = "./src/UrdfAdapter.java"; + String m_sBotNameAdapterPath = "./src/BotNameAdapter.java"; + //path to the resources dirs String m_sResourcesDirPath = "../FeatureModelConfigurator/resources"; + String m_sResourcesDirInPath = m_sResourcesDirPath+"/input"; + String m_sResourcesDirOutPath = m_sResourcesDirPath+"/output"; //path to the features dir String m_sFeatureDirPath = "../FeatureModelConfigurator/features"; + //paths to the sensorcofig dirs + String m_sSenConfPath = "../FeatureModelConfigurator/resources/input/sensorconfig"; + String m_sSenConfAutoPath = m_sSenConfPath+"/autogenerated"; + String m_sSenConfOtherPath = m_sSenConfPath+"/other"; //path to the src dir String m_sSrcDirPath = "../FeatureModelConfigurator/src"; //path to the bin dir @@ -47,26 +57,35 @@ public class ImplGenerator { private ImplGenerator() { - //check if resources directory exists and if not, create it - if(!XMLHelper.checkDirectory(m_sResourcesDirPath)) { - return; - } - - //check if resources/input directory exists and if not, create it - if(!XMLHelper.checkDirectory(m_sResourcesDirPath+"/input")) { + //check if directories exist and if not, create them + boolean bCreated = true; + bCreated = XMLHelper.checkDirectory(m_sResourcesDirPath); + bCreated = XMLHelper.checkDirectory(m_sResourcesDirInPath); + bCreated = XMLHelper.checkDirectory(m_sResourcesDirOutPath); + bCreated = XMLHelper.checkDirectory(m_sSenConfPath); + bCreated = XMLHelper.checkDirectory(m_sSenConfAutoPath); + bCreated = XMLHelper.checkDirectory(m_sSenConfOtherPath); + if(!bCreated) { return; } - //check if resources/output directory exists and if not, create it - if(!XMLHelper.checkDirectory(m_sResourcesDirPath+"/output")) { + //autogenerate sensorconfig files + try { + SensorConfigSetup oScSetup = new SensorConfigSetup(); + oScSetup.run(); + } catch (JDOMException | IOException e) { + e.printStackTrace(); return; } - //autogenerate sensor config files - SensorConfigSetup oScSetup = new SensorConfigSetup(); - //set up the feature model - ModelSetup oMSetup = new ModelSetup(); + try { + ModelSetup oMSetup = new ModelSetup(); + oMSetup.run(); + } catch (JDOMException | IOException e) { + e.printStackTrace(); + return; + } //delete everything in the features directory DeleteDir(new File(m_sFeatureDirPath)); @@ -94,13 +113,19 @@ public class ImplGenerator { List<Element> aModules = XMLHelper.xQueryElements(oFeatureModelDoc, "//*[@name= 'ConfiguratorMain']").get(0).getChildren(); FindNonAbstractModules(aModules); - //copy adapter file - sDestPath = m_sFeatureDirPath + "/ConfiguratorMain/Adapter.java"; - CopyFile(m_sAdapterPath, sDestPath); - - //copy xml helper file + //copy files to FeatureModelConfigurator sDestPath = m_sFeatureDirPath + "/ConfiguratorMain/XMLHelper.java"; CopyFile(m_sHelperPath, sDestPath); + sDestPath = m_sFeatureDirPath + "/ConfiguratorMain/UserSetIOReader.java"; + CopyFile(m_sUserIOPath, sDestPath); + sDestPath = m_sFeatureDirPath + "/ConfiguratorMain/Adapter.java"; + CopyFile(m_sAdapterPath, sDestPath); + sDestPath = m_sFeatureDirPath + "/ConfiguratorMain/GazeboAdapter.java"; + CopyFile(m_sGazeboAdapterPath, sDestPath); + sDestPath = m_sFeatureDirPath + "/ConfiguratorMain/UrdfAdapter.java"; + CopyFile(m_sUrdfAdapterPath, sDestPath); + sDestPath = m_sFeatureDirPath + "/ConfiguratorMain/BotNameAdapter.java"; + CopyFile(m_sBotNameAdapterPath, sDestPath); } //recursively delete a dir and it's contents diff --git a/src/var/FeatureModelImplGenerator/src/ModelSetup.java b/src/var/FeatureModelImplGenerator/src/ModelSetup.java index 0ead627..ca62cbc 100644 --- a/src/var/FeatureModelImplGenerator/src/ModelSetup.java +++ b/src/var/FeatureModelImplGenerator/src/ModelSetup.java @@ -1,180 +1,192 @@ -import java.io.*; -import java.util.*; - -import org.jdom2.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Collections; +import java.io.IOException; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; /** - * Takes the specified template for a Feature IDE model file and adds all available - * sensorconfig/ gazebo.xacro model files. + * Class that allows for generating a model to be used with FeatureIDE based + * on available gazebomodels and sensorconfigs. */ -public class ModelSetup extends XMLHelper{ - +public class ModelSetup extends Setup { + //Variables used exclusively by ModelSetup + public final Document model; + public final List<String> scAutoList; + public final List<String> scOtherList; + public final List<String> gazeboModelNamesList; + /** - * Obtains an attribute value of the input/ output entries specified in modelsetup.config. + * Creates a runnable ModelSetup. * - * @param doc The JDOM Document (modelsetup.config) - * @param entry String formed as "{input or output}/{entity}" - * @param val Attribute name as String - * @return path as specified in modelsetup.config + * When reading input, scAutoPath, scOtherPath and in_gxPath may contain other + * files that will be filtered out. + * + * @throws IOException + * @throws JDOMException */ - private static String getConfigVal(Document doc, String str, String val) { - List<Attribute> valList = xQueryAttributes(doc, "//"+str+"/@"+val); - if(valList.size()!=1) { - System.err.println("Error while reading input/ output "+val+" value from modelsetup.config."); - System.exit(-1); + public ModelSetup() throws JDOMException, IOException { + super(); + + //Get the model template file as Document + model = XMLHelper.readXml(in_mPath+in_mName); + + //Get all available sensorconfig file names from .../autogenerated/ directory + scAutoList = new ArrayList<String>(); + + List<String> scAutoDirectoryFilesList = XMLHelper.getFileNames(scAutoPath); + for(String s : scAutoDirectoryFilesList) { + if(s.endsWith(SC_ENDING)) { + scAutoList.add(s); + } + } + + //Get all available sensorconfig file names from .../other/ directory + scOtherList = new ArrayList<String>(); + + List<String> scOtherDirectoryFilesList = XMLHelper.getFileNames(scOtherPath); + for(String s : scOtherDirectoryFilesList) { + if(s.endsWith(SC_ENDING)) { + scOtherList.add(s); + } + } + + //Get all available gazeboModel file names + gazeboModelNamesList = new ArrayList<String>(); + + List<String> gxDirectoryFilesList = XMLHelper.getFileNames(in_gxPath); + for(String s : gxDirectoryFilesList) { + if(s.endsWith(GX_ENDING)) { + gazeboModelNamesList.add(s); + } } - - return valList.get(0).getValue(); } /** - * Call this to run ModelSetup. + * Run the ModelSetup. + * + * @throws IOException */ - public ModelSetup() { + public void run() throws IOException { System.out.println("ModelSetup started."); - try { - final String SC_ENDING = ".xml"; - final String GX_ENDING = ".gazebo.xacro"; - - //######### Input ############################### - Document ModelSetupConfig = readXml("./modelsetup.config"); - - //Get modelsetup.config values. - String in_mPath = getConfigVal(ModelSetupConfig, "input/model", "path"); - String in_scPath = getConfigVal(ModelSetupConfig, "input/sensorconfig", "path"); - String in_gxPath = getConfigVal(ModelSetupConfig, "input/gazebo_xacro", "path"); - String out_mPath = getConfigVal(ModelSetupConfig, "output/model", "path"); - - String in_mName = getConfigVal(ModelSetupConfig, "input/model", "name"); - String out_mName = getConfigVal(ModelSetupConfig, "output/model", "name"); - - String scAutoPath = in_scPath+"autogenerated/"; - String scOtherPath = in_scPath+"other/"; - - //Declare Document. - Document model = readXml(in_mPath+in_mName); - - //Get sensorconfig- and gazebomodel file names. - //scAutoPath, scOtherPath and in_gxPath may contain other files that will be filtered out! - List<String> scAutoDirectoryFilesList = getFileNames(scAutoPath); - List<String> scAutoList = new ArrayList<String>(); - for(String s : scAutoDirectoryFilesList) { - if(s.endsWith(SC_ENDING)) { - scAutoList.add(s); - } - } - - List<String> scOtherDirectoryFilesList = getFileNames(scOtherPath); - List<String> scOtherList = new ArrayList<String>(); - for(String s : scOtherDirectoryFilesList) { - if(s.endsWith(SC_ENDING)) { - scOtherList.add(s); - } - } - - List<String> gxDirectoryFilesList = getFileNames(in_gxPath); - List<String> gxList = new ArrayList<String>(); - for(String s : gxDirectoryFilesList) { - if(s.endsWith(GX_ENDING)) { - gxList.add(s); - } - } - - //Check whether feature input was empty. - //It is possible to have no sensors (so you can build a custom bot with no sensors), - //but at least one bot template is required! - if(scAutoList.isEmpty()) { - System.out.println("Warning: No sensorconfig \'"+SC_ENDING+"\' files found in \'"+scAutoPath+"\'."); - } - if(scOtherList.isEmpty()) { - System.out.println("Warning: No sensorconfig \'"+SC_ENDING+"\' files found in \'"+scOtherPath+"\'."); - } - if(gxList.isEmpty()) { - System.err.println("Error: No gazebo model \'"+GX_ENDING+"\' files found in \'"+in_gxPath+"\'."); - System.exit(-1); - } - - //Check whether sensorconfigs in .../autogenerated/ and .../other/ have distinct names. - //FeatureIDE does not allow for duplicate feature names. - List<String> testList = new ArrayList<String>(); - testList.addAll(scAutoList); - testList.addAll(scOtherList); - Collections.sort(testList); - if(!testList.isEmpty()) { - for(int i = 0; i < testList.size()-1; i++) { - String name1 = testList.get(i); - String name2 = testList.get(i+1); - if(name1.equals(name2)) { - System.err.println("Error: At least two sensorconfig files have the same name: \'"+name1+"\'"); - System.exit(-1); - } + //Check for empty feature input + this.checkIfEmpty(); + + //Check whether there are no duplicate sensorconfig names + this.checkForDistinctSensorConfigNames(); + + //Sort features alphabetically + this.sortFeatures(); + + //Add features to model + this.addFeatures(); + + //Output model + this.output(); + + System.out.println("ModelSetup finished."); + } + + /** + * Check whether feature input was empty. + * It is possible to have no sensors (so you can build a custom bot with no sensors), + * but at least one bot template is required! + */ + private void checkIfEmpty() { + if(this.scAutoList.isEmpty()) { + System.out.println("Warning: No sensorconfig \'"+SC_ENDING+"\' files found in \'"+this.scAutoPath+"\'."); + } + if(this.scOtherList.isEmpty()) { + System.out.println("Warning: No sensorconfig \'"+SC_ENDING+"\' files found in \'"+this.scOtherPath+"\'."); + } + if(this.gazeboModelNamesList.isEmpty()) { + System.err.println("Error: No gazebo model \'"+GX_ENDING+"\' files found in \'"+this.in_gxPath+"\'."); + System.exit(-1); + } + } + + /** + * Checks whether sensorconfigs in .../autogenerated/ and .../other/ have distinct names. + * Thid could happen because we read from two directories. + * FeatureIDE does not allow for duplicate feature names. + */ + private void checkForDistinctSensorConfigNames() { + List<String> testList = new ArrayList<String>(); + testList.addAll(this.scAutoList); + testList.addAll(this.scOtherList); + Collections.sort(testList); + + if(!testList.isEmpty()) { + for(int i = 0; i < testList.size()-1; i++) { + String name1 = testList.get(i); + String name2 = testList.get(i+1); + if(name1.equals(name2)) { + System.err.println("Error: At least two sensorconfig files have the same name: \'"+name1+"\'"); + System.exit(-1); } } - - //Sort features alphabetically (ascending order; upper case first; then lower case). - Collections.sort(scAutoList); - Collections.sort(scOtherList); - Collections.sort(gxList); - //############################################### - - - //######### Operate on model #################### - //Get Elements in model where features are to be added. - Element templates = null; - List<Element> templatesList = xQueryElements(model, "//*[@name='Templates']"); - if(templatesList.size()==1) { - templates = templatesList.get(0); - } - else { - System.err.println("Error when parsing for \'Templates\' in \'"+in_mName+"\'."); - System.exit(-1); - } - - Element custom = null; - List<Element> customList = xQueryElements(model, "//*[@name='Custom']"); - if(customList.size()==1) { - custom = customList.get(0); - } - else { - System.err.println("Error when parsing for \'Custom\' in \'"+in_mName+"\'."); - System.exit(-1); - } - - //Add features to model. - for(String gx : gxList) { - String featureName = gx.substring(0, gx.length() - GX_ENDING.length()); - Element feature = new Element("feature").setAttribute("name", featureName); - templates.addContent(feature); - } - - for(String sc : scOtherList) { - String featureName = sc.substring(0, sc.length() - SC_ENDING.length()); - Element feature = new Element("feature").setAttribute("name", featureName); - custom.addContent(feature); - } - - for(String sc : scAutoList) { - String featureName = sc.substring(0, sc.length() - SC_ENDING.length()); - Element feature = new Element("feature").setAttribute("name", featureName); - custom.addContent(feature); - } - //############################################### - - - //######### Output result ####################### - saveAsXml(model, out_mPath+out_mName); - //############################################### } - catch (JDOMException | IOException e) { - e.printStackTrace(); + } + + /** + * Sorts scAutoList, scOtherList, gazeboModelNamesList alphabetically. + * (ascending order; upper case first; then lower case) + */ + private void sortFeatures() { + Collections.sort(this.scAutoList); + Collections.sort(this.scOtherList); + Collections.sort(this.gazeboModelNamesList); + } + + /** + * Adds all features in gazeboModelNamesList, scOtherList, scAutoList to model. + */ + private void addFeatures() { + //Get Elements in model where features are to be added + List<Element> templatesList = XMLHelper.xQueryElements(this.model, "//*[@name='Templates']"); + if(templatesList.size()!=1) { + System.err.println("Error when parsing for \'Templates\' in \'"+this.in_mName+"\'."); + System.exit(-1); } - - System.out.println("ModelSetup finished."); + Element templates = templatesList.get(0); + + List<Element> customList = XMLHelper.xQueryElements(this.model, "//*[@name='Custom']"); + if(customList.size()!=1) { + System.err.println("Error when parsing for \'Custom\' in \'"+this.in_mName+"\'."); + System.exit(-1); + } + Element custom = customList.get(0); + + //Add features to model + for(String gm : this.gazeboModelNamesList) { + String featureName = gm.substring(0, gm.length() - GX_ENDING.length()); + Element feature = new Element("feature").setAttribute("name", featureName); + templates.addContent(feature); + } + + for(String sc : this.scOtherList) { + String featureName = sc.substring(0, sc.length() - SC_ENDING.length()); + Element feature = new Element("feature").setAttribute("name", featureName); + custom.addContent(feature); + } + + for(String sc : this.scAutoList) { + String featureName = sc.substring(0, sc.length() - SC_ENDING.length()); + Element feature = new Element("feature").setAttribute("name", featureName); + custom.addContent(feature); + } + } + + /** + * Output model as XML file to be used by FeatureIDE. + * + * @throws IOException + */ + private void output() throws IOException { + XMLHelper.saveAsXml(this.model, this.out_mPath+this.out_mName); } } - - - diff --git a/src/var/FeatureModelImplGenerator/src/SensorConfigSetup.java b/src/var/FeatureModelImplGenerator/src/SensorConfigSetup.java index 2e29aef..1e69400 100644 --- a/src/var/FeatureModelImplGenerator/src/SensorConfigSetup.java +++ b/src/var/FeatureModelImplGenerator/src/SensorConfigSetup.java @@ -1,162 +1,167 @@ -import java.io.*; -import java.util.*; - -import org.jdom2.*; +import java.util.ArrayList; +import java.util.List; +import java.io.File; +import java.io.IOException; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; +import org.jdom2.JDOMException; /** - * Takes all given .gazebo.xacro files, extracts their sensors and creates sensorconfig files. + * Class that allows for generating sensorconfigs to be used with Adapter based + * on available gazebomodels. */ -public class SensorConfigSetup extends XMLHelper{ - +public class SensorConfigSetup extends Setup{ + //Variables used exclusively by SensorConfigSetup + public final List<Document> gazeboModelList; + public final List<String> gazeboModelNamesList; + public final List<Document> sensorConfigList = new ArrayList<Document>(); + public final List<String> sensorConfigNamesList = new ArrayList<String>(); + /** - * Obtains an attribute value of the input/ output entries specified in modelsetup.config. + * Creates a runnable SensorConfigSetup. * - * @param doc The JDOM Document (modelsetup.config) - * @param entry String formed as "{input or output}/{entity}" - * @param val Attribute name as String - * @return path as specified in modelsetup.config + * When reading input, in_gxPath may contain other files that will be filtered out. + * + * @throws IOException + * @throws JDOMException */ - private static String getConfigVal(Document doc, String str, String val) { - List<Attribute> valList = xQueryAttributes(doc, "//"+str+"/@"+val); - if(valList.size()!=1) { - System.err.println("Error while reading input/ output "+val+" value from modelsetup.config."); - System.exit(-1); + public SensorConfigSetup() throws JDOMException, IOException { + super(); + + //Get all gazeboModel files and file names + gazeboModelList = new ArrayList<Document>(); + gazeboModelNamesList = new ArrayList<String>(); + + List<String> gxList = new ArrayList<String>(); + List<String> gxDirectoryFilesList = XMLHelper.getFileNames(in_gxPath); + for(String s : gxDirectoryFilesList) { + if(s.endsWith(GX_ENDING)) { + gxList.add(s); + } + } + + if(gxList.isEmpty()) { + System.out.println("Warning: No gazebo model \'"+GX_ENDING+"\' files found in \'"+in_gxPath+ + "\'. Could not autogenerate sensorconfig files"); + } + + for(String gx : gxList) { + gazeboModelList.add(XMLHelper.readXml(in_gxPath+gx)); + gazeboModelNamesList.add(gx.substring(0, gx.length() - GX_ENDING.length())); } - - return valList.get(0).getValue(); } /** - * Takes a file name and alters it so a FeatureIDE model will accept it. - * FeatureIDE says it only takes the following regex as valid feature names: ^[a-zA-Z]+\w*$ - * This function will replace all \W characters (no word character) with '_'. + * Run the SensorConfigSetup. * - * @param name Name to be changes as String. - * @return Corrected name + * @throws IOException */ - private static String fixName(String name) { - return name.replaceAll("\\W", "_"); + public void run() throws IOException { + System.out.println("SensorConfigSetup started."); + + //Remove old autogenerated sensorconfigs and create directories + //checkDirectory(in_scPath); TODO + if((new File(scAutoPath)).exists()) { + XMLHelper.deleteDirectory(scAutoPath); + } + XMLHelper.checkDirectory(scAutoPath); + XMLHelper.checkDirectory(scOtherPath); + + //Compute sensorconfigs for each gazeboModel + for(int i = 0; i < gazeboModelList.size(); i++) { + Document gazeboModel = gazeboModelList.get(i); + String gazeboModelName = gazeboModelNamesList.get(i); + Namespace NS = gazeboModel.getRootElement().getNamespace("xacro"); + + //Replace all $(arg ...) variables + this.replaceArg(gazeboModel, NS); + + //Generate sensorconfigs from gazeboModel + this.generateSensorConfigs(gazeboModel, gazeboModelName); + } + + //Output sensorconfigs + this.output(); + + System.out.println("SensorConfigSetup finished."); } /** - * Call this to run SensorConfigSetup. + * Replace all $(arg ...) variables with their concrete values. + * + * @param gazeboModel model to be operated on as Document + * @param NS Namespace of gazeboModel as Namespace */ - public SensorConfigSetup() { - System.out.println("SensorConfigSetup started."); + private void replaceArg(Document gazeboModel, Namespace NS) { + List<Element> argList = XMLHelper.xQueryElements(gazeboModel, "//xacro:arg", NS); - try { - final String SC_ENDING = ".xml"; - final String GX_ENDING = ".gazebo.xacro"; - - //######### Input ############################### - Document ModelSetupConfig = readXml("./modelsetup.config"); - - //Get modelsetup.config values. - String in_scPath = getConfigVal(ModelSetupConfig, "input/sensorconfig", "path");///TODO - String in_gxPath = getConfigVal(ModelSetupConfig, "input/gazebo_xacro", "path"); - - String scAutoPath = in_scPath+"autogenerated/"; - String scOtherPath = in_scPath+"other/"; - - //Declare Documents and their corresponding file names. - List<Document> gazeboModelList = new ArrayList<Document>(); - List<String> gazeboModelNamesList = new ArrayList<String>(); - List<Document> sensorConfigList = new ArrayList<Document>(); - List<String> sensorConfigNamesList = new ArrayList<String>(); - - //Get gazebomodel file names. - //in_gxPath may contain other files that will be filtered out! - List<String> gxDirectoryFilesList = getFileNames(in_gxPath); - List<String> gxList = new ArrayList<String>(); - for(String s : gxDirectoryFilesList) { - if(s.endsWith(GX_ENDING)) { - gxList.add(s); - } + for(Element arg : argList) { + String variable = "$(arg "+arg.getAttributeValue("name")+")"; + String concreteValue = arg.getAttributeValue("default"); + List<Element> occurrenceList = XMLHelper.xQueryElements(gazeboModel, "//*[text()='"+variable+"']"); + for(Element occurrence : occurrenceList) { + occurrence.setText(concreteValue); } - - //Check whether input was empty. - if(gxList.isEmpty()) { - System.out.println("Warning: No gazebo model \'"+GX_ENDING+"\' files found in \'"+in_gxPath+"\'. Could not autogenerate sensorconfig files"); - } - - //Get all gazebomodel files as List<Document>. - for(String gx : gxList) { - gazeboModelList.add(readXml(in_gxPath+gx)); - gazeboModelNamesList.add(gx.substring(0, gx.length() - GX_ENDING.length())); - } - //############################################### - - - //######### Check directories ################### - checkDirectory(in_scPath); - if((new File(scAutoPath)).exists()) { - deleteDirectory(scAutoPath); - } - checkDirectory(scAutoPath); - checkDirectory(scOtherPath); - //############################################### - - - //######### Generate sensorconfigs ############## - for(int i = 0; i < gazeboModelList.size(); i++) { - Document gazeboModel = gazeboModelList.get(i); - String gazeboModelName = gazeboModelNamesList.get(i); - Namespace NS = gazeboModel.getRootElement().getNamespace("xacro"); - - //Replace all $(arg ...) variables with their concrete values. - List<Element> argList = xQueryElements(gazeboModel, "//xacro:arg", NS); - for(Element arg : argList) { - String variable = "$(arg "+arg.getAttributeValue("name")+")"; - String concreteValue = arg.getAttributeValue("default"); - List<Element> occurrenceList = xQueryElements(gazeboModel, "//*[text()='"+variable+"']"); - for(Element occurrence : occurrenceList) { - occurrence.setText(concreteValue); - } - } - - //Get all existing sensors in gazebomodel. - List<Element> sensorList = xQueryElements(gazeboModel, "//sensor"); + } + } + + /** + * Generate a new sensorconfig for each sensor in gazeboModel. + * + * @param gazeboModel model to be operated on as Document + * @param gazeboModelName model name as String + */ + private void generateSensorConfigs(Document gazeboModel, String gazeboModelName) { + //Get all existing sensors in gazeboModel + List<Element> sensorList = XMLHelper.xQueryElements(gazeboModel, "//sensor"); + + //Create a new sensorconfig for each of them. + for(Element sensor : sensorList) { + Element entry = sensor.getParentElement(); + if(entry.getName().equals("gazebo")) { + entry.detach(); - //Create a new sensorconfig for each of them. - for(Element sensor : sensorList) { - Element entry = sensor.getParentElement(); - if(entry.getName().equals("gazebo")) { - entry.detach(); - - Element sensorConfigRoot = new Element("configuration"); - Document sensorConfig = new Document(sensorConfigRoot); - sensorConfig.getRootElement().addContent(entry); - - sensorConfigList.add(sensorConfig); - String sensorConfigName = fixName(sensor.getAttributeValue("name"))+"___"+fixName(gazeboModelName); - sensorConfigNamesList.add(sensorConfigName); - } - else { - System.out.println("Found a <sensor> element that does not have a <gazebo> element as immediate parent. It was ignored, as this input is unexpected."); - } - } - } - //############################################### - - - //######### Output result ####################### - for(int i = 0; i < sensorConfigList.size(); i++) { - Document sensorConfig = sensorConfigList.get(i); - String sensorConfigName = sensorConfigNamesList.get(i); + Element sensorConfigRoot = new Element("configuration"); + Document sensorConfig = new Document(sensorConfigRoot); + sensorConfig.getRootElement().addContent(entry); - saveAsXml(sensorConfig, scAutoPath+sensorConfigName+SC_ENDING); + this.sensorConfigList.add(sensorConfig); + String sensorConfigName = fixName(sensor.getAttributeValue("name"))+"___"+fixName(gazeboModelName); + this.sensorConfigNamesList.add(sensorConfigName); + } + else { + System.out.println("Found a <sensor> element that does not have a <gazebo> element as immediate parent. " + +"It was ignored, as this input is unexpected."); } - //############################################### } - catch (JDOMException | IOException e) { - e.printStackTrace(); + } + + /** + * Takes a String and alters it so a FeatureIDE model will accept it as a feature name. + * FeatureIDE says it only takes the following regex as valid feature names: ^[a-zA-Z]+\w*$ + * This function will replace all \W characters (no word character) with '_'. + * + * @param name Name to be changed as String + * @return Corrected name + */ + private static String fixName(String name) { + return name.replaceAll("\\W", "_"); + } + + /** + * Output all generated sensorconfigs as XML files. + * + * @throws IOException + */ + private void output() throws IOException { + for(int i = 0; i < this.sensorConfigList.size(); i++) { + Document sensorConfig = this.sensorConfigList.get(i); + String sensorConfigName = this.sensorConfigNamesList.get(i); + + XMLHelper.saveAsXml(sensorConfig, this.scAutoPath+sensorConfigName+SC_ENDING); } - - System.out.println("SensorConfigSetup finished."); } } - - - diff --git a/src/var/FeatureModelImplGenerator/src/Setup.java b/src/var/FeatureModelImplGenerator/src/Setup.java new file mode 100644 index 0000000..eb18e28 --- /dev/null +++ b/src/var/FeatureModelImplGenerator/src/Setup.java @@ -0,0 +1,30 @@ +import java.io.IOException; + +import org.jdom2.JDOMException; + + +/** + * Class that provides input/ output info for setups. + */ +public class Setup extends UserSetIOReader { + //Hard coded input/ output (because the project directory is designed like this) + public final String in_mName = "modelTemplate.xml"; + public final String in_mPath = "./template/"; + + private final String in_scPath = "./../FeatureModelConfigurator/resources/input/sensorconfig/"; + public final String scAutoPath = in_scPath+"autogenerated/"; + public final String scOtherPath = in_scPath+"other/"; + + public final String out_mName = "model.xml"; + public final String out_mPath = "./../FeatureModelConfigurator/"; + + /** + * Constructor defining a general setup object. + * + * @throws IOException + * @throws JDOMException + */ + public Setup() throws JDOMException, IOException { + super(); + } +} diff --git a/src/var/FeatureModelImplGenerator/src/UrdfAdapter.java b/src/var/FeatureModelImplGenerator/src/UrdfAdapter.java new file mode 100644 index 0000000..5006bb5 --- /dev/null +++ b/src/var/FeatureModelImplGenerator/src/UrdfAdapter.java @@ -0,0 +1,136 @@ +import java.util.List; +import java.io.File; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; +import org.jdom2.JDOMException; + + +/** + * Class that allows for manipulating and outputting a .urdf.xacro file based on + * featuremodel info. + */ +public class UrdfAdapter extends Adapter { + //Variables used exclusively by .urdf.xacro adapter + public final String in_uxName; + public final Document urdfModel; + public final Namespace NS; + + /** + * Creates a runnable Adapter for .urdf.xacro files. + * + * When reading input in_uxPath may contain other files that will be filtered out. + * + * @throws IOException + * @throws JDOMException + */ + public UrdfAdapter() throws JDOMException, IOException { + super(); + + //Get the selected .urdf.xacro file name as String + in_uxName = botName+UX_ENDING; + + //Get the selected .urdf.xacro file as Document + List<String> fileMatchList = XMLHelper.findFile(in_uxName, in_uxPath); + + if(fileMatchList.isEmpty()) { + System.err.println("Cannot handle \'"+in_uxName+"\': No input file known."); + System.exit(-1); + } + if(fileMatchList.size()!=1) { + System.err.println("Cannot handle \'"+in_uxName+"\': Multiple input files found:"); + for(String match : fileMatchList) { + System.err.println("\'"+match+"\'"); + } + System.exit(-1); + } + + urdfModel = XMLHelper.readXml(fileMatchList.get(0)); + + //Get the "xacro" namespace of the .urdf.xacro document as Namespace + NS = urdfModel.getRootElement().getNamespace("xacro"); + } + + /** + * Run the Adapter for .urdf.xacro files. + * + * Sets the {@code <xacro:include>} tags. + * The links/ joints are not edited, as the precise visual bot representation is not + * important for this project. + * + * @throws IOException + */ + public void run() throws IOException { + System.out.println("UrdfAdapter started."); + + //Set <xacro:include> tags + this.setInclude(); + + switch(this.mode) { + case "NO_CHANGE": + break; + case "Custom": + /** + * If the urdf.xacro would be modified (to have an accurate visual model with the sensors attached to it), + * this needs to happen here. (Delete or Insert <link> and <joint> tags.) + * This would require separate files with <link> and <joint> tags for each bot and sensor for the Adapter to access. + * + * For example, like this: + * The "autogenerated"/"other" directory gets one child directory for each bot. + * Each of these new directories contains one file for each sensorconfig with the building blocks + * to be inserted in .urdf.xacro, just like the sensorconfigs contain building blocks + * for the .gazebo.xacro files. + */ + break; + default: + System.err.println("Invalid input in \'"+this.in_fmName+"\': NO_CHANGE/ Custom parameter could not be parsed."); + System.exit(-1); + } + + //Output urdfModel + this.output(); + + System.out.println("UrdfAdapter finished."); + } + + /** + * Sets {@code <xacro:include>} tags in urdfModel to correctly point to the files to be included. + */ + private void setInclude() { + List<Element> includeList = XMLHelper.xQueryElements(this.urdfModel, "//xacro:include", this.NS); + + if(includeList.size()!=2) { + System.err.println("Unexpected input in \'"+this.in_uxName+"\': Expected exactly 2 <xacro:include> tags."); + System.exit(-1); + } + + int gxIndex; + int commonPropIndex; + if(includeList.get(0).getAttributeValue("filename").endsWith(GX_ENDING)) { + gxIndex = 0; + commonPropIndex = 1; + } + else { + gxIndex = 1; + commonPropIndex = 0; + } + + String gxDestDirectoryName = (new File(this.out_gxPath)).getName(); + includeList.get(gxIndex).setAttribute("filename", "$(find "+gxDestDirectoryName+")/"+this.out_gxName); + + //The common_properties.xacro stays in its original directory, so this is not edited + //String commonPropDestDirectoryName = ; + //includeList.get(commonPropIndex).setAttribute("filename", "$(find "+commonPropDestDirectoryName+")/common_properties.xacro"); + } + + /** + * Output the urdfModel as XML file. + * + * @throws IOException + */ + private void output() throws IOException { + XMLHelper.saveAsXml(this.urdfModel, this.out_uxPath+this.out_uxName); + } +} diff --git a/src/var/FeatureModelImplGenerator/src/UserSetIOReader.java b/src/var/FeatureModelImplGenerator/src/UserSetIOReader.java new file mode 100644 index 0000000..409a517 --- /dev/null +++ b/src/var/FeatureModelImplGenerator/src/UserSetIOReader.java @@ -0,0 +1,88 @@ +import java.util.List; +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Attribute; +import org.jdom2.JDOMException; + + +/** + * Class that allows for reading input from usersetio.config. + */ +public class UserSetIOReader { + //File endings + public static final String SC_ENDING = ".xml"; + public static final String GX_ENDING = ".gazebo.xacro"; + public static final String UX_ENDING = ".urdf.xacro"; + + //Input/ output as defined by user + public final String in_gxPath; + + public final String in_uxPath; + + public final String out_gxName; + public final String out_gxPath; + + public final String out_uxName; + public final String out_uxPath; + + public final String out_bnName; + public final String out_bnPath; + public final String unwantedPrefix; + public final String unwantedSuffix; + + /** + * Constructor reading from default usersetio.config location. + * + * @throws IOException + * @throws JDOMException + */ + public UserSetIOReader() throws JDOMException, IOException { + this("./../usersetio.config"); + } + + /** + * Constructor reading all values from usersetio.config. + * io.config contains all values that the user will want to set manually. + * + * @param path Location of usersetio.config. + * @throws IOException + * @throws JDOMException + */ + private UserSetIOReader(String path) throws JDOMException, IOException { + Document config = XMLHelper.readXml(path); + + in_gxPath = getConfigVal(config, "input/gazebo_xacro", "path"); + + in_uxPath = getConfigVal(config, "input/urdf_xacro", "path"); + + out_gxName = getConfigVal(config, "output/gazebo_xacro", "name"); + out_gxPath = getConfigVal(config, "output/gazebo_xacro", "path"); + + out_uxName = getConfigVal(config, "output/urdf_xacro", "name"); + out_uxPath = getConfigVal(config, "output/urdf_xacro", "path"); + + out_bnName = getConfigVal(config, "output/botname", "name"); + out_bnPath = getConfigVal(config, "output/botname", "path"); + unwantedPrefix = getConfigVal(config, "output/botname", "remove_prefix"); + unwantedSuffix = getConfigVal(config, "output/botname", "remove_suffix"); + } + + /** + * Obtains an attribute value of the input/ output entries specified in *.config. + * + * @param doc The JDOM Document (*.config) + * @param entry String formed as "{input or output}/{entity}" + * @param val Attribute name as String + * @return XML-attribute specified in entry of doc (*.config) as String + */ + public static String getConfigVal(Document doc, String entry, String val) { + List<Attribute> valList = XMLHelper.xQueryAttributes(doc, "//"+entry+"/@"+val); + if(valList.size()!=1) { + System.err.println("Error while reading input/ output \'"+val+"\' value from *.config."); + System.exit(-1); + } + + return valList.get(0).getValue(); + } +} diff --git a/src/var/FeatureModelImplGenerator/src/XMLHelper.java b/src/var/FeatureModelImplGenerator/src/XMLHelper.java index 08c3067..36f589c 100644 --- a/src/var/FeatureModelImplGenerator/src/XMLHelper.java +++ b/src/var/FeatureModelImplGenerator/src/XMLHelper.java @@ -9,7 +9,6 @@ import org.jdom2.output.XMLOutputter; import org.jdom2.xpath.*; - /** * Contains methods based on JDOM and Jaxen library that help processing XML files and other misc ones. */ @@ -126,12 +125,13 @@ public class XMLHelper { * * @param name Name of the file including file ending as String * @param path Path to directory to be searched as String - * @return path to all file matches as List<String> (e.g. .../sensorconfig/other/imu.xml) + * @return path to all file matches as {@code List<String>} (e.g. .../sensorconfig/other/imu.xml) */ public static List<String> findFile(String name, String path) { List<String> accumulator = new ArrayList<String>(); + findFile(name, path, accumulator); - return findFile(name, path, accumulator); + return accumulator; } /** @@ -139,23 +139,20 @@ public class XMLHelper { * * @param name Name of the file including file ending as String * @param path Path to directory to be searched as String - * @param result Accumulator for all file matches as List<String> - * @return path to all file matches as list<String> (e.g. .../sensorconfig/other/imu.xml) + * @param result Accumulator for all file matches as {@code List<String>} */ - private static List<String> findFile(String name, String path, List<String> result) { + private static void findFile(String name, String path, List<String> result) { File element = new File(path); File[] content = element.listFiles(); + //content==null if it is not a directory if(content != null) { for(File file : content) { - List<String> subResult = findFile(name, path+"/"+file.getName(), result); - result.addAll(subResult); + findFile(name, path+"/"+file.getName(), result); } } if(element.getName().equals(name)) { - result.add(element.getName()); + result.add(element.getPath()); } - - return result; } /** @@ -455,12 +452,4 @@ public class XMLHelper { return false; } - - /** - * @param args - */ - public static void main(String[] args) { - - } } - diff --git a/src/var/FeatureModelImplGenerator/template/Main.jak b/src/var/FeatureModelImplGenerator/template/Main.jak index 8cf93aa..e241cc6 100644 --- a/src/var/FeatureModelImplGenerator/template/Main.jak +++ b/src/var/FeatureModelImplGenerator/template/Main.jak @@ -104,8 +104,19 @@ public class Configurator { return; } - //create and launch Adapter - new Adapter(); + //create and launch adapters + try { + GazeboAdapter oGazeboAdapter = new GazeboAdapter(); + oGazeboAdapter.run(); + UrdfAdapter oUrdfAdapter = new UrdfAdapter(); + oUrdfAdapter.run(); + BotNameAdapter oBotNameAdapter = new BotNameAdapter(); + oBotNameAdapter.run(); + } + catch (Exception oEx) { + System.out.println(oEx); + return; + } } //get all parents of a given module from the Feature Model file diff --git a/src/var/FeatureModelConfigurator/adapter.config b/src/var/usersetio.config similarity index 62% rename from src/var/FeatureModelConfigurator/adapter.config rename to src/var/usersetio.config index 058fa03..2ea172f 100644 --- a/src/var/FeatureModelConfigurator/adapter.config +++ b/src/var/usersetio.config @@ -1,19 +1,14 @@ <?xml version="1.0"?> -<!-- Adapter configuration file. --> -<!-- Path (relative path to Adapter.java location) and name value can be changed. --> -<adapter> +<!-- IO configuration file. --> +<!-- Path (relative path to UserSetIOReader.java location) and name value can be changed. --> +<io> <input> - <!-- Path to and name of feature model generated by Feature IDE. --> - <featuremodel type="file" name="featuremodel.xml" path="./resources/output/" /> - <!-- Path to all available sensor configuration .xml files. --> - <!-- Files with other endings are allowed and will be ignored. --> - <sensorconfig type="directory" path="./resources/input/sensorconfig/" /> <!-- Path to all available .gazebo.xacro files. --> <!-- Files with other endings are allowed and will be ignored. --> - <gazebo_xacro type="directory" path="./../../sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/" /> + <gazebo_xacro type="directory" path="./../../sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/" /> <!-- Path to all available .urdf.xacro files. --> <!-- Files with other endings are allowed and will be ignored. --> - <urdf_xacro type="directory" path="./../../sim/turtlebot3/turtlebot3/turtlebot3_description/urdf_raw_for_testing/" /> + <urdf_xacro type="directory" path="./../../sim/turtlebot3/turtlebot3/turtlebot3_description/urdf/" /> </input> <output> <!-- Path to and name of the generated .gazebo.xacro file. --> @@ -24,4 +19,4 @@ <!-- Define prefix/ postfix to be removed from the bots name to be compatible with testmanager.sh. --> <botname type="file" name="botname.txt" path="./../../../build/sim/" remove_prefix="turtlebot3_" remove_suffix=""/> </output> -</adapter> +</io> -- GitLab