16 from scipy.interpolate
import splrep, splev
18 from copy
import deepcopy
19 from visualization_msgs.msg
import MarkerArray
20 from uuv_waypoints
import Waypoint, WaypointSet
22 quaternion_about_axis, quaternion_conjugate, \
23 quaternion_from_matrix, euler_from_matrix
25 from ..trajectory_point
import TrajectoryPoint
26 from .line_segment
import LineSegment
27 from .bezier_curve
import BezierCurve
28 from .path_generator
import PathGenerator
32 """Interpolator that will generate [cubic Bezier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve) 33 segments for a set of waypoints. The full algorithm can 34 be seen in `Biagiotti and Melchiorri, 2008`. 38 Biagiotti, Luigi, and Claudio Melchiorri. Trajectory planning for 39 automatic machines and robots. Springer Science & Business Media, 2008. 44 super(CSInterpolator, self).
__init__(self)
54 """Initialize the interpolator. To have the path segments generated, 55 `init_waypoints()` must be called beforehand by providing a set of 56 waypoints as `uuv_waypoints.WaypointSet` type. 60 `True` if the path segments were successfully generated. 62 if self._waypoints
is None:
70 if self._waypoints.num_waypoints == 2:
72 LineSegment(self._waypoints.get_waypoint(0).pos,
73 self._waypoints.get_waypoint(1).pos))
74 self._segment_to_wp_map.append(1)
75 elif self._waypoints.num_waypoints > 2:
76 self.
_interp_fcns[
'pos'], tangents = BezierCurve.generate_cubic_curve(
77 [self._waypoints.get_waypoint(i).pos
for i
in range(self._waypoints.num_waypoints)])
82 lengths = [seg.get_length()
for seg
in self.
_interp_fcns[
'pos']]
83 lengths = [0] + lengths
84 self.
_s = np.cumsum(lengths) / np.sum(lengths)
86 [self._waypoints.get_waypoint(k).max_forward_speed
for k
in range(self._waypoints.num_waypoints)])
92 if self._waypoints.num_waypoints == 2:
93 head_offset_line = deepcopy(self._waypoints.get_waypoint(1).heading_offset)
94 self.
_interp_fcns[
'heading'] =
lambda x: head_offset_line
97 heading = [self._waypoints.get_waypoint(i).heading_offset
for i
in range(self._waypoints.num_waypoints)]
105 """Not implemented for this interpolator.""" 109 """Sample the full path for position and quaternion vectors. 110 `step` is represented in the path's parametric space. 114 * `step` (*type:* `float`, *default:* `0.001`): Parameter description 118 List of `uuv_trajectory_generator.TrajectoryPoint`. 120 if self._waypoints
is None:
124 s = np.arange(0, 1 + step, step)
128 pnt = TrajectoryPoint()
135 """Generate a position vector for the path sampled point 136 interpolated on the position related to `s`, `s` being 137 represented in the curve's parametric space. 141 * `s` (*type:* `float`): Curve's parametric input expressed in the 146 3D position vector as a `numpy.array`. 150 idx = self.get_segment_idx(s)
155 u_k = (s - self.
_s[idx - 1]) / (self.
_s[idx] - self.
_s[idx - 1])
156 pos = self.
_interp_fcns[
'pos'][idx - 1].interpolate(u_k)
160 """Compute a point that belongs to the path on the 161 interpolated space related to `s`, `s` being represented 162 in the curve's parametric space. 166 * `s` (*type:* `float`): Curve's parametric input expressed in the 168 * `t` (*type:* `float`): Trajectory point's timestamp 172 `uuv_trajectory_generator.TrajectoryPoint` including position 173 and quaternion vectors. 175 pnt = TrajectoryPoint()
185 """Compute the quaternion of the path reference for a interpolated 186 point related to `s`, `s` being represented in the curve's parametric 188 The quaternion is computed assuming the heading follows the direction 189 of the path towards the target. Roll and pitch can also be computed 190 in case the `full_dof` is set to `True`. 194 * `s` (*type:* `float`): Curve's parametric input expressed in the 199 Rotation quaternion as a `numpy.array` as `(x, y, z, w)` 206 return self._init_rot
208 last_s = max(0, s - self._s_step)
213 dx = this_pos[0] - last_pos[0]
214 dy = this_pos[1] - last_pos[1]
215 dz = this_pos[2] - last_pos[2]
217 rotq = self._compute_rot_quat(dx, dy, dz)
220 q_step = quaternion_about_axis(
224 rotq = quaternion_multiply(rotq, q_step)
def generate_quat(self, s)
def generate_pos(self, s)
def get_samples(self, max_time, step=0.001)
def generate_pnt(self, s, t, args)
def set_parameters(self, params)
def init_interpolator(self)