15 from scipy.interpolate
import splrep, splev
17 from copy
import deepcopy
18 from uuv_waypoints
import Waypoint, WaypointSet
19 from visualization_msgs.msg
import MarkerArray
21 quaternion_about_axis, quaternion_conjugate, \
22 quaternion_from_matrix, euler_from_matrix
24 from ..trajectory_point
import TrajectoryPoint
25 from .line_segment
import LineSegment
26 from .bezier_curve
import BezierCurve
27 from .path_generator
import PathGenerator
31 """Simple interpolator that generates a parametric 32 line connecting the input waypoints. 37 from uuv_waypoints import Waypoint, WaypointSet 38 from uuv_trajectory_generator import LinearInterpolator 40 # Some sample 3D points 41 q_x = [0, 1, 2, 4, 5, 6] 42 q_y = [0, 2, 3, 3, 2, 0] 43 q_z = [0, 1, 0, 0, 2, 2] 45 q = np.vstack((q_x, q_y, q_z)).T 48 waypoints = WaypointSet() 49 for i in range(q.shape[0]): 50 waypoints.add_waypoint(Waypoint(q[i, 0], q[i, 1], q[i, 2], max_forward_speed=0.5)) 52 interpolator = LinearInterpolator() 53 interpolator.init_waypoints(waypoints) 54 interpolator.init_interpolator() 56 # Use get_samples to retrieve points interpolated 57 # using a fixed step, step being represented in the line's 59 pnts = interpolator.get_samples(max_time=None, step=0.01) 61 # Or use the following to retrieve a position vector on the 63 pos = interpolator.generate_pos(s=0.2) 69 super(LinearInterpolator, self).
__init__(self)
79 """Initialize the interpolator. To have the path segments generated, 80 `init_waypoints()` must be called beforehand by providing a set of 81 waypoints as `uuv_waypoints.WaypointSet` type. 85 `True` if the path segments were successfully generated. 87 if self._waypoints
is None:
90 if self._waypoints.num_waypoints < 2:
100 for i
in range(1, self._waypoints.num_waypoints):
102 LineSegment(self._waypoints.get_waypoint(i - 1).pos,
103 self._waypoints.get_waypoint(i).pos))
106 lengths = [seg.get_length()
for seg
in self.
_interp_fcns[
'pos']]
107 lengths = [0] + lengths
108 self.
_s = np.cumsum(lengths) / np.sum(lengths)
110 [self._waypoints.get_waypoint(k).max_forward_speed
for k
in range(self._waypoints.num_waypoints)])
117 heading = [self._waypoints.get_waypoint(k).heading_offset
for k
in range(self._waypoints.num_waypoints)]
124 """Not implemented for this interpolator.""" 128 """Sample the full path for position and quaternion vectors. 129 `step` is represented in the path's parametric space. 133 * `step` (*type:* `float`, *default:* `0.001`): Parameter description 137 List of `uuv_trajectory_generator.TrajectoryPoint`. 139 if self._waypoints
is None:
143 s = np.arange(0, 1 + step, step)
147 pnt = TrajectoryPoint()
154 """Generate a position vector for the path sampled point 155 interpolated on the position related to `s`, `s` being 156 represented in the curve's parametric space. 160 * `s` (*type:* `float`): Curve's parametric input expressed in the 165 3D position vector as a `numpy.array`. 169 idx = self.get_segment_idx(s)
174 u_k = (s - self.
_s[idx - 1]) / (self.
_s[idx] - self.
_s[idx - 1])
175 pos = self.
_interp_fcns[
'pos'][idx - 1].interpolate(u_k)
179 """Compute a point that belongs to the path on the 180 interpolated space related to `s`, `s` being represented 181 in the curve's parametric space. 185 * `s` (*type:* `float`): Curve's parametric input expressed in the 187 * `t` (*type:* `float`): Trajectory point's timestamp 191 `uuv_trajectory_generator.TrajectoryPoint` including position 192 and quaternion vectors. 194 pnt = TrajectoryPoint()
204 """Compute the quaternion of the path reference for a interpolated 205 point related to `s`, `s` being represented in the curve's parametric 207 The quaternion is computed assuming the heading follows the direction 208 of the path towards the target. Roll and pitch can also be computed 209 in case the `full_dof` is set to `True`. 213 * `s` (*type:* `float`): Curve's parametric input expressed in the 218 Rotation quaternion as a `numpy.array` as `(x, y, z, w)` 225 return self._init_rot
227 last_s = max(0, s - self._s_step)
232 dx = this_pos[0] - last_pos[0]
233 dy = this_pos[1] - last_pos[1]
234 dz = this_pos[2] - last_pos[2]
236 rotq = self._compute_rot_quat(dx, dy, dz)
239 q_step = quaternion_about_axis(
243 rotq = quaternion_multiply(rotq, q_step)
def init_interpolator(self)
def generate_pos(self, s)
def generate_pnt(self, s, t, args)
def generate_quat(self, s)
def set_parameters(self, params)
def get_samples(self, max_time, step=0.001)