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

Automatically generate sensorconfigs from gazebo.xacro files

parent 00e97573
Branches
No related merge requests found
Showing
with 342 additions and 52 deletions
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>turtlebots</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>de.ovgu.featureide.core.extensibleFeatureProjectBuilder</name>
<arguments>
<dictionary>
<key>build</key>
<value>src</value>
</dictionary>
<dictionary>
<key>composer</key>
<value>de.ovgu.featureide.composer.ahead</value>
</dictionary>
<dictionary>
<key>equations</key>
<value>configs</value>
</dictionary>
<dictionary>
<key>source</key>
<value>features</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>de.ovgu.featureide.core.featureProjectNature</nature>
</natures>
</projectDescription>
......@@ -14,4 +14,17 @@
<feature automatic="unselected" name="imu"/>
<feature automatic="unselected" name="lds_lfcd_sensor"/>
<feature automatic="unselected" name="realsense_R200"/>
<feature automatic="unselected" name="Pi_Camera___turtlebot3_burger_for_autorace"/>
<feature automatic="unselected" name="Pi_Camera___turtlebot3_waffle_pi"/>
<feature automatic="unselected" name="head_rplidar_sensor___turtlebot3_burgertest1"/>
<feature automatic="unselected" name="imu___turtlebot3_burger"/>
<feature automatic="unselected" name="imu___turtlebot3_burger_for_autorace"/>
<feature automatic="unselected" name="imu___turtlebot3_burgertest1"/>
<feature automatic="unselected" name="imu___turtlebot3_waffle"/>
<feature automatic="unselected" name="imu___turtlebot3_waffle_pi"/>
<feature automatic="unselected" name="lds_lfcd_sensor___turtlebot3_burger"/>
<feature automatic="unselected" name="lds_lfcd_sensor___turtlebot3_burger_for_autorace"/>
<feature automatic="unselected" name="lds_lfcd_sensor___turtlebot3_waffle"/>
<feature automatic="unselected" name="lds_lfcd_sensor___turtlebot3_waffle_pi"/>
<feature automatic="unselected" name="realsense_R200___turtlebot3_waffle"/>
</configuration>
......@@ -52,7 +52,7 @@ public class Adapter extends XMLHelper {
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 = "";
......@@ -60,6 +60,9 @@ public class Adapter extends XMLHelper {
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");
......@@ -88,22 +91,44 @@ public class Adapter extends XMLHelper {
case "Custom":
List<Attribute> sensorList = xQueryAttributes(featureModel, "//sensor/@name");
List<String> scList = getFileNames(in_scPath);
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) {
boolean inDirectory = false;
for(String fileName : scList) {
if(fileName.equals(sensor.getValue()+SC_ENDING)) {
inDirectory = true;
}
}
if(!inDirectory) {
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);
}
}
for(Attribute sensor : sensorList) {
sensorConfigList.add(readXml(in_scPath+sensor.getValue()+SC_ENDING));
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:
......
......@@ -83,6 +83,80 @@ public class XMLHelper {
return directoryNames;
}
/**
* Check whether the given directory exists and if not, create it.
*
* @param path Path to directory as String
* @return false if directory denoted by path does not exist and could not be created; true otherwise
*/
public static boolean checkDirectory(String path) {
File directory = new File(path);
if(!directory.exists()) {
boolean created = directory.mkdir();
if(!created) {
System.err.println("Error: Directory \'"+directory.getPath()+"\' does not exist and could not be created.");
return false;
}
}
return true;
}
/**
* Recursively delete a directory and its contents.
*
* @param path Path to directory as String
*/
public static void deleteDirectory(String path) {
File element = new File(path);
File[] content = element.listFiles();
if(content != null) {
for(File file : content) {
deleteDirectory(file.getPath());
}
}
if(!element.delete()) {
System.err.println("Error: Could not delete file/ directory: \'"+element.getPath()+"\'.");
}
}
/**
* Finds a file by recursive search in the directory given by path.
*
* @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)
*/
public static List<String> findFile(String name, String path) {
List<String> accumulator = new ArrayList<String>();
return findFile(name, path, accumulator);
}
/**
* Executes file search for findFile(String name, String path).
*
* @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)
*/
private static List<String> findFile(String name, String path, List<String> result) {
File element = new File(path);
File[] content = element.listFiles();
if(content != null) {
for(File file : content) {
List<String> subResult = findFile(name, path+"/"+file.getName(), result);
result.addAll(subResult);
}
}
if(element.getName().equals(name)) {
result.add(element.getName());
}
return result;
}
/**
* Executes given XPath expression for elements with JDOM Document as source.
*
......
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("Pi_Camera___turtlebot3_burger_for_autorace");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("Pi_Camera___turtlebot3_waffle_pi");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("head_rplidar_sensor___turtlebot3_burgertest1");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("imu___turtlebot3_burger");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("imu___turtlebot3_burger_for_autorace");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("imu___turtlebot3_burgertest1");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("imu___turtlebot3_waffle");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("imu___turtlebot3_waffle_pi");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("lds_lfcd_sensor___turtlebot3_burger");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("lds_lfcd_sensor___turtlebot3_burger_for_autorace");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("lds_lfcd_sensor___turtlebot3_waffle");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("lds_lfcd_sensor___turtlebot3_waffle_pi");
Super().save();
}
}
\ No newline at end of file
/**
* TODO description
*/
public refines class Configurator {
public void save() {
Super().addToModuleList("realsense_R200___turtlebot3_waffle");
Super().save();
}
}
\ No newline at end of file
......@@ -27,6 +27,19 @@
<feature name="imu" />
<feature name="lds_lfcd_sensor" />
<feature name="realsense_R200" />
<feature name="Pi_Camera___turtlebot3_burger_for_autorace" />
<feature name="Pi_Camera___turtlebot3_waffle_pi" />
<feature name="head_rplidar_sensor___turtlebot3_burgertest1" />
<feature name="imu___turtlebot3_burger" />
<feature name="imu___turtlebot3_burger_for_autorace" />
<feature name="imu___turtlebot3_burgertest1" />
<feature name="imu___turtlebot3_waffle" />
<feature name="imu___turtlebot3_waffle_pi" />
<feature name="lds_lfcd_sensor___turtlebot3_burger" />
<feature name="lds_lfcd_sensor___turtlebot3_burger_for_autorace" />
<feature name="lds_lfcd_sensor___turtlebot3_waffle" />
<feature name="lds_lfcd_sensor___turtlebot3_waffle_pi" />
<feature name="realsense_R200___turtlebot3_waffle" />
</and>
</alt>
</and>
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<gazebo reference="camera_rgb_frame">
<sensor type="camera" name="Pi Camera">
<always_on>true</always_on>
<visualize>false</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>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<gazebo reference="camera_rgb_frame">
<sensor type="camera" name="Pi Camera">
<always_on>true</always_on>
<visualize>false</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>
</configuration>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment