yaml2launch.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import yaml
00004 import sys
00005 
00006 def main():
00007     argv = sys.argv
00008     base_file_names = argv[1:]
00009     for base_file_name in base_file_names:
00010         yaml_file_name = base_file_name + ".yaml"
00011         launch_file_name = base_file_name + ".launch.xml"
00012         
00013         with open(yaml_file_name, "r") as yaml_file:
00014             yaml_data = yaml_file.read()
00015             yaml_dict = yaml.load(yaml_data)
00016             print("yaml_dict:", yaml_dict)
00017             is_robot = yaml_dict["machine"] == "robot"
00018 
00019             topics = []
00020             if "topics" in yaml_dict:
00021                 topics = yaml_dict["topics"]
00022 
00023             with open(launch_file_name, "w") as launch_file:
00024                 launch_file.write("<launch>\n")
00025 
00026                 launch_file.write("  <!-- Required arguments -->\n")
00027                 launch_file.write("  <arg name=\"robot_platform\" />\n")
00028                 launch_file.write("    <!--robot_platform: The robot platform (e.g. 'loki'.) -->\n")
00029                 if is_robot:
00030                     launch_file.write("  <arg name=\"robot_host\" />\n")
00031                     launch_file.write("    <!--robot_host: The robot host address. -->\n")
00032                 launch_file.write("  <arg name=\"robot_user\" />\n")
00033                 launch_file.write("    <!--robot_host: The robot user name. -->\n")
00034                 launch_file.write("\n")
00035 
00036                 launch_file.write("  <!-- Optional arguments -->\n")
00037                 for topic in topics:
00038                     launch_file.write("  <arg name=\"{0}_topic\" default=\"{1}\" />\n".
00039                       format(topic, topic))
00040                     launch_file.write("    <!--{0}: more here -->\n".format(topic))
00041                 launch_file.write("\n")
00042 
00043                 if is_robot:
00044                     launch_file.write("  <!-- Robot machine declaration -->\n")
00045                     launch_file.write("  <machine name=\"robot\"\n")
00046                     launch_file.write("   address=\"$(arg robot_host)\"\n")
00047                     launch_file.write("   user=\"$(arg robot_user)\"\n")
00048                     launch_file.write("   env-loader=\"/tmp/env_loader.sh\" />\n")
00049                     launch_file.write("\n")
00050 
00051                 # Write out the <node ... >:
00052                 launch_file.write("  <node name=\"{0}\"\n".format(yaml_dict["name"]))
00053                 if is_robot:
00054                     launch_file.write("   machine=\"robot\"\n")
00055                 launch_file.write("   pkg=\"{0}\"\n".format(yaml_dict["package"]))
00056                 launch_file.write("   type=\"{0}\" >\n".format(yaml_dict["bin"]))
00057 
00058                 for topic in topics:
00059                     launch_file.write("    <remap from=\"{0}\" to=\"$(arg {0}_topic)\" />\n".
00060                       format(topic))
00061 
00062                 launch_file.write("  </node>\n")
00063                 launch_file.write("</launch>\n")
00064 
00065                 
00066 
00067 if __name__ == "__main__":
00068     main()


ubiquity_launches
Author(s): Wayne Gramlich
autogenerated on Thu Jun 6 2019 18:36:40