task.py
Go to the documentation of this file.
1 import rospy
2 import clearpath_navigation_msgs.msg
3 
4 
5 class Task:
6  """A single Task (part of a Waypoint).
7 
8  Contains a name, uuid, action_server_name, version, arrays of floats
9  and strings related to the specific Task.
10  """
11 
12  def __init__(self, name, uuid, action_server_name, version="",
13  floats=[], strings=[], allow_failure=False):
14  """Creates a Waypoint object from the given parameters.
15 
16  Parameters
17  ----------
18  name : str
19  The name or ID of the task, used for tracking/reporting.
20 
21  uuid : str
22  Unique UUID string for the task.
23 
24  action_server_name : str
25  The ROS action that this task executes.
26 
27  floats : floats[], optional
28  Numerical/boolean data to be passed to the action_server_name
29  The exact meaning of these values is dependent on the underlying service.
30 
31  strings : str[], optional
32  String data to be passed to the action_server_name
33  The exact meaning of these values is dependent on the underlying service.
34 
35  allow_failure : bool
36  Determines whether a mission using this task can continue if the task
37  execution were to fail.
38  """
39 
40  self._task_msg = clearpath_navigation_msgs.msg.Task()
41  self._task_msg.name = name
42  self._task_msg.uuid = uuid
43  self._task_msg.action_server_name = action_server_name
44  self._task_msg.version = version
45  self._task_msg.floats = floats
46  self._task_msg.strings = strings
47  self._task_msg.allow_failure = allow_failure
48 
49  def getName(self):
50  """Gets the name of the task.
51 
52  Returns
53  -------
54  str
55  the name of the task
56  """
57 
58  return self._task_msg.name
59 
60  def getTaskMsg(self):
61  """Gets the task message.
62 
63  Returns
64  -------
65  clearpath_navigation_msgs.msg.Task
66  the task message
67  """
68 
69  return self._task_msg
70 
71  def toYaml(self):
72  """Converts the task to YAML format, for writing to disk.
73 
74  Returns
75  -------
76  dict
77  A YAML-compatible dictionary representation of the object.
78  """
79 
80  tasks_yaml = []
81  for task in self._task_msg.tasks:
82  tasks_yaml.append({
83  'name': task.name,
84  'uuid': task.uuid,
85  'action_server_name': task.action_server_name,
86  'version': task.version,
87  'floats': task.floats,
88  'strings': task.strings,
89  'allow_failure': task.allow_failure
90  })
91  return tasks_yaml
92 
93  @staticmethod
94  def fromYaml(task_yaml):
95  """Creates a Task object from a YAML-compatible dictionary representation.
96 
97  Parameters
98  ----------
99  task_yaml : dict
100  The YAML-compatible dictionary representation of a Task object
101  """
102 
103  try:
104  name = task_yaml['name']
105  uuid = task_yaml['uuid']
106  action_server_name = task_yaml['action_server_name']
107  version = task_yaml['version']
108  floats = task_yaml['floats']
109  strings = task_yaml['strings']
110  allow_failure = task_yaml['allow_failure']
111  return Task(name, uuid, action_server_name, version, floats, strings, allow_failure)
112 
113  except KeyError as e:
114  rospy.logerr('Unable to parse yaml for tasks: %s' % e)
115  return None
clearpath_onav_api_examples_lib.task.Task.getTaskMsg
def getTaskMsg(self)
Definition: task.py:60
clearpath_onav_api_examples_lib.task.Task.getName
def getName(self)
Definition: task.py:49
clearpath_onav_api_examples_lib.task.Task.toYaml
def toYaml(self)
Definition: task.py:71
clearpath_onav_api_examples_lib.task.Task.fromYaml
def fromYaml(task_yaml)
Definition: task.py:94
clearpath_onav_api_examples_lib.task.Task
Definition: task.py:5
clearpath_onav_api_examples_lib.task.Task._task_msg
_task_msg
Definition: task.py:39
clearpath_onav_api_examples_lib.task.Task.__init__
def __init__(self, name, uuid, action_server_name, version="", floats=[], strings=[], allow_failure=False)
Definition: task.py:12


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