17 from copy
import deepcopy
18 from geometry_msgs.msg
import Vector3, PoseStamped, Quaternion
19 import uuv_control_msgs.msg
as uuv_control_msgs
20 from nav_msgs.msg
import Path
21 from uuv_waypoints
import WaypointSet
22 from .wp_trajectory_generator
import WPTrajectoryGenerator
23 from .trajectory_point
import TrajectoryPoint
25 from ._log
import get_logger
29 """Trajectory generator based on waypoint and trajectory interpolation. 33 * `full_dof` (*type:* `bool`, *default:* `False`): If `True`, generate 34 the trajectory in 6 DoFs, otherwise `roll` and `pitch` are set to zero. 35 * `stamped_pose_only` (*type:* `bool`, *default:* `False`): If `True` 36 the output trajectory will set velocity and acceleration references 39 def __init__(self, full_dof=False, stamped_pose_only=False):
48 full_dof=full_dof, stamped_pose_only=stamped_pose_only)
55 """List of `uuv_trajectory_generator.TrajectoryPoint`: List of trajectory points""" 57 return self._wp_interp.get_samples(0.001)
63 """List of `float`: List of timestamps""" 67 self._wp_interp.use_finite_diff = flag
70 return self._wp_interp.use_finite_diff
73 """Set flag to enable or disable computation of trajectory 78 * `flag` (*type:* `bool`): Parameter description 82 Description of return values 84 self._wp_interp.stamped_pose_only = flag
87 return self._wp_interp.stamped_pose_only
90 return self._wp_interp.set_interpolation_method(method)
93 return self._wp_interp.get_interpolation_method()
96 return self._wp_interp.interpolator_tags
99 return self._wp_interp.set_interpolator_parameters(method, params)
103 return self._wp_interp.get_visual_markers()
116 Return the trajectory points as a Trajectory type message. If waypoints 117 are currently in use, then sample the interpolated path and return the 123 msg = uuv_control_msgs.Trajectory()
125 msg.header.stamp = rospy.Time.now()
127 self._logger.warning(
128 'A ROS node was not initialized, no ' 129 'timestamp can be set to Trajectory message')
130 msg.header.frame_id =
'world' 133 msg.points.append(pnt.to_message())
137 """Return true if the waypoint interpolation is being used.""" 141 """Initializes the waypoint interpolator with a set of waypoints.""" 142 self._logger.info(
'Initial rotation vector (quat)=%s', str(init_rot))
143 self._logger.info(
'Initial rotation vector (rpy)=%s',
144 str(euler_from_quaternion(init_rot)))
145 if self._wp_interp.init_waypoints(waypoints, init_rot):
153 Return the waypoints used by the waypoint interpolator, 158 self._logger.info(
'NOT USING WAYPOINTS')
160 return self._wp_interp.get_waypoints()
164 Add waypoint to the current waypoint set, if one has been initialized. 168 self._wp_interp.add_waypoint(waypoint, add_to_beginning)
173 If a trajectory set is currently being used in the interpolation 174 process, add a trajectory point to the set. 182 if pnt.t <= self.
_points[-1].t:
184 self._points.append(pnt)
185 self._time.append(pnt.t)
188 self._logger.error(
'Cannot add trajectory point! Generator is in ' 189 'waypoint interpolation mode!')
194 pnt = TrajectoryPoint()
195 if pnt.from_message(msg):
199 self._logger.error(
'Error converting message to trajectory point')
202 self._logger.error(
'Cannot add trajectory point! Generator is in ' 203 'waypoint interpolation mode!')
208 self._logger.error(
'Waypoint interpolation is not activated')
211 return self._wp_interp.set_duration(t)
217 return self._wp_interp.get_max_time()
226 return self._wp_interp.started
232 return self._wp_interp.is_finished()
242 for p_msg
in msg.points:
243 t = p_msg.header.stamp.to_sec()
249 self._logger.error(
'Trajectory should be given a growing value ' 258 wp_set = WaypointSet.from_message(msg)
259 self._wp_interp.init_waypoints(wp_set)
263 wp_set = WaypointSet()
264 success = wp_set.read_from_file(filename)
266 self._wp_interp.init_waypoints(wp_set)
273 msg = uuv_control_msgs.Trajectory()
275 msg.header.stamp = rospy.Time.now()
276 set_timestamps =
True 278 set_timestamps =
False 279 self._logger.warning(
280 'ROS node was not initialized, no timestamp ' 281 'can be assigned to trajectory message')
282 msg.header.frame_id =
'world' 285 p_msg = uuv_control_msgs.TrajectoryPoint()
287 p_msg.header.stamp = rospy.Time(p.t)
288 p_msg.pose.position = Vector3(*p.p)
289 p_msg.pose.orientation = Quaternion(*p.q)
290 p_msg.velocity.linear = Vector3(*p.v)
291 p_msg.velocity.angular = Vector3(*p.w)
292 p_msg.acceleration.linear = Vector3(*p.a)
293 p_msg.acceleration.angular = Vector3(*p.alpha)
294 msg.points.append(p_msg)
296 dt = 0.05 * self._wp_interp.get_max_time()
297 for ti
in np.arange(0, self._wp_interp.get_max_time(), dt):
298 pnt = self._wp_interp.interpolate(ti)
299 p_msg = uuv_control_msgs.TrajectoryPoint()
301 p_msg.header.stamp = rospy.Time(pnt.t)
302 p_msg.pose.position = Vector3(*pnt.p)
303 p_msg.pose.orientation = Quaternion(*pnt.q)
304 p_msg.velocity.linear = Vector3(*pnt.v)
305 p_msg.velocity.angular = Vector3(*pnt.w)
306 p_msg.acceleration.linear = Vector3(*pnt.a)
307 p_msg.acceleration.angular = Vector3(*pnt.alpha)
308 msg.points.append(p_msg)
314 path_msg.header.stamp = rospy.Time.now()
315 set_timestamps =
True 317 set_timestamps =
False 318 self._logger.warning(
319 'ROS node was not initialized, no timestamp ' 320 'can be assigned to path message')
321 path_msg.header.frame_id =
'world' 322 path_msg.poses = list()
324 for point
in self._local_planner.points:
327 pose.header.stamp = rospy.Time(point.t)
328 pose.pose.position = Vector3(*point.p)
329 pose.pose.orientation = Quaternion(*point.q)
330 path_msg.poses.append(pose)
334 self._wp_interp.set_start_time(t)
340 return self._wp_interp.generate_reference(t, *args)
352 if type(self.
_time) == list:
358 self._this_pnt.pos = deepcopy(self.
_points[0].pos)
359 self._this_pnt.rotq = deepcopy(self.
_points[0].rotq)
363 self._this_pnt.pos = deepcopy(self.
_points[-1].pos)
364 self._this_pnt.rotq = deepcopy(self.
_points[-1].rotq)
370 idx = np.argmin(np.abs(self.
_time - t))
380 dt = p_this.t - p_last.t
381 w1 = (t - p_last.t) / dt
382 w0 = (p_this.t - t) / dt
383 self._this_pnt.pos = w0*p_last.pos + w1*p_this.pos
384 self._this_pnt.rotq = w0*p_last.rotq + w1*p_this.rotq
385 self._this_pnt.vel = w0*p_last.vel + w1*p_this.vel
386 self._this_pnt.acc = w0*p_last.acc + w1*p_this.acc
388 self.
_this_pnt = self._wp_interp.interpolate(t, *args)
def __init__(self, full_dof=False, stamped_pose_only=False)
def is_using_waypoints(self)
def get_interp_method(self)
def generate_reference(self, t, args)
def init_from_waypoint_message(self, msg)
def init_from_waypoint_file(self, filename)
def set_interpolator_parameters(self, method, params)
def gen_trajectory_message(self)
def set_duration(self, t)
def is_using_finite_diff(self)
def set_start_time(self, t)
def add_trajectory_point(self, pnt)
def set_stamped_pose_only(self, flag)
def use_finite_diff(self, flag)
def set_interp_method(self, method)
def add_trajectory_point_from_msg(self, msg)
def set_waypoints(self, waypoints, init_rot=(0, 0, 0, 1))
def is_using_stamped_pose_only(self)
def add_waypoint(self, waypoint, add_to_beginning=False)
def init_from_trajectory_message(self, msg)
def get_trajectory_as_message(self)
def get_path_message(self)
def get_visual_markers(self)
def get_interpolator_tags(self)
def interpolate(self, t, args)