waypoint.py
Go to the documentation of this file.
1 import rospy
2 import clearpath_navigation_msgs.msg
4 
5 
6 class Waypoint:
7  """A single waypoint (part of a mission).
8 
9  Contains a name, uuid, latitude, longitude, optional tasks to run
10  at the point, and various other optional parameters related
11  to the specifics at the waypoint.
12 
13  A series of waypoints can be grouped in sequence to build a larger mission.
14  """
15 
16  def __init__(self, name, uuid, latitude, longitude, heading=-1, tasks=[],
17  position_tolerance=0.1, yaw_tolerance=0.2):
18  """Creates a Waypoint object from the given parameters.
19 
20  Parameters
21  ----------
22  name : str
23  The name or ID of the goal, used for tracking/reporting
24 
25  uuid : str
26  Unique UUID string for the waypoint
27 
28  latitude : float64
29  Latitude for the waypoint (in degrees)
30 
31  longitude : float64
32  Longitude for the waypoint (in degrees)
33 
34  heading : float64, optional
35  Heading for the waypoint (0-360 degrees)
36 
37  tasks : Task[], optional
38  A list of tasks to run at the waypoint (default is no tasks)
39 
40  position_tolerance : float64, optional
41  The pose (x,y) tolerance, in meters, to apply at the goalpoint (default is 0.1)
42 
43  yaw_tolerance : float64, optional
44  The yaw tolerance, in radians, to apply at the goalpoint (default is 0.2)
45  """
46 
47  self._waypoint_msg = clearpath_navigation_msgs.msg.Waypoint()
48  self._waypoint_msg.name = name
49  self._waypoint_msg.uuid = uuid
50  self._waypoint_msg.latitude = latitude
51  self._waypoint_msg.longitude = longitude
52  self._waypoint_msg.heading = heading
53  waypoint_tasks = []
54  for task in tasks:
55  waypoint_tasks.append(task.getTaskMsg())
56  self._waypoint_msg.tasks = waypoint_tasks
57  self._waypoint_msg.position_tolerance = position_tolerance
58  self._waypoint_msg.yaw_tolerance = yaw_tolerance
59 
60  def getName(self):
61  """Gets the name of the waypoint.
62 
63  Returns
64  -------
65  str
66  the name of the waypoint
67  """
68 
69  return self._waypoint_msg.name
70 
71  def getWaypointMsg(self):
72  """Gets the waypoint message.
73 
74  Returns
75  -------
76  clearpath_navigation_msgs.msg.Waypoint
77  the waypoint message
78  """
79 
80  return self._waypoint_msg
81 
82  def toYaml(self):
83  """Converts the waypoint to YAML format, for writing to disk.
84 
85  Returns
86  -------
87  dict
88  A YAML-compatible dictionary representation of the object.
89  """
90 
91  tasks_yaml = []
92  for task in self._waypoint_msg.tasks:
93  tasks_yaml.append({
94  'name': task.name,
95  'uuid': task.uuid,
96  'action_server_name': task.action_server_name,
97  'version': task.version,
98  'floats': task.floats,
99  'strings': task.strings
100  })
101  waypoint_yaml = {
102  'name': self._waypoint_msg.name,
103  'uuid': self._waypoint_msg.uuid,
104  'latitude': self._waypoint_msg.latitude,
105  'longitude': self._waypoint_msg.longitude,
106  'heading': self._waypoint_msg.heading,
107  'tasks': tasks_yaml,
108  'position_tolerance': self._waypoint_msg.position_tolerance,
109  'yaw_tolerance': self._waypoint_msg.yaw_tolerance,
110  }
111  return waypoint_yaml
112 
113  @staticmethod
114  def fromYaml(waypoint_yaml):
115  """Creates a Waypoint object from a YAML-compatible dictionary representation.
116 
117  Parameters
118  ----------
119  goal_yaml : dict
120  The YAML-compatible dictionary representation of a Waypoint object
121  """
122 
123  try:
124  name = waypoint_yaml['name']
125  uuid = waypoint_yaml['uuid']
126  latitude = waypoint_yaml['latitude']
127  longitude = waypoint_yaml['longitude']
128  heading = waypoint_yaml['heading']
129  position_tolerance = waypoint_yaml['position_tolerance']
130  yaw_tolerance = waypoint_yaml['yaw_tolerance']
131 
132  tasks_yaml = waypoint_yaml['tasks']
133  tasks = []
134  for task_yaml in tasks_yaml:
135  task = Task()
136  task.name = task_yaml['name']
137  task.uuid = task_yaml['uuid']
138  task.action_server_name = task_yaml['action_server_name']
139  task.version = task_yaml['version']
140  task.floats = task_yaml['floats']
141  task.strings = task_yaml['strings']
142  tasks.append(task)
143 
144  return Waypoint(name, uuid, latitude, longitude, heading, tasks,
145  position_tolerance, yaw_tolerance)
146 
147  except KeyError as e:
148  rospy.logerr('Unable to parse yaml for waypoint: %s' % e)
149  return None
clearpath_onav_api_examples_lib.waypoint.Waypoint.toYaml
def toYaml(self)
Definition: waypoint.py:82
clearpath_onav_api_examples_lib.waypoint.Waypoint.fromYaml
def fromYaml(waypoint_yaml)
Definition: waypoint.py:114
clearpath_onav_api_examples_lib.waypoint.Waypoint.__init__
def __init__(self, name, uuid, latitude, longitude, heading=-1, tasks=[], position_tolerance=0.1, yaw_tolerance=0.2)
Definition: waypoint.py:16
clearpath_onav_api_examples_lib.waypoint.Waypoint.getName
def getName(self)
Definition: waypoint.py:60
clearpath_onav_api_examples_lib.waypoint.Waypoint._waypoint_msg
_waypoint_msg
Definition: waypoint.py:46
clearpath_onav_api_examples_lib.task.Task
Definition: task.py:5
clearpath_onav_api_examples_lib.waypoint.Waypoint.getWaypointMsg
def getWaypointMsg(self)
Definition: waypoint.py:71
clearpath_onav_api_examples_lib.waypoint.Waypoint
Definition: waypoint.py:6
clearpath_onav_api_examples_lib.task
Definition: task.py:1


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