yaml_config.py
Go to the documentation of this file.
1 import yaml
2 import rospy
4 
5 
6 class YamlConfig:
7  """Converts between Mission and yaml files."""
8 
9  @staticmethod
10  def missionToYamlFile(filename, mission):
11  """Converts a Mission object to a yaml file.
12 
13  Parameters
14  ----------
15  filename : str
16  Full pathname for the output yaml file
17 
18  mission : Mission
19  The mission to be saved as a yaml file
20  """
21 
22  mission_yaml = {'mission': mission.toYaml()}
23  with open(filename, 'w') as file:
24  yaml.dump(mission_yaml, file)
25 
26  @staticmethod
27  def yamlFileToMission(filename):
28  """Creates a Mission object from a yaml file.
29 
30  Parameters
31  ----------
32  filename : str
33  Full pathname of the yaml file to be read
34 
35  Returns
36  -------
37  Mission
38  The created Mission object on success; None on any error
39  """
40 
41  mission_yaml = None
42  with open(filename, 'r') as file:
43  try:
44  mission_yaml = yaml.safe_load(file)
45  if 'mission' not in mission_yaml:
46  rospy.logerr("yamlFileToMission: missing 'mission' field")
47  return None
48  return Mission.fromYaml(mission_yaml['mission'])
49  except yaml.YAMLError as e:
50  rospy.logerr("Error while reading file: %s" % e)
51  return None
clearpath_onav_api_examples_lib.mission
Definition: mission.py:1
clearpath_onav_api_examples_lib.yaml_config.YamlConfig.missionToYamlFile
def missionToYamlFile(filename, mission)
Definition: yaml_config.py:10
clearpath_onav_api_examples_lib.yaml_config.YamlConfig
Definition: yaml_config.py:6
clearpath_onav_api_examples_lib.yaml_config.YamlConfig.yamlFileToMission
def yamlFileToMission(filename)
Definition: yaml_config.py:27


clearpath_onav_api_examples_lib
Author(s):
autogenerated on Sun Nov 12 2023 03:29:19