helical_segment.py
Go to the documentation of this file.
1 # Copyright (c) 2016-2019 The UUV Simulator Authors.
2 # All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 import numpy as np
16 
17 class HelicalSegment(object):
18  """Generator of helical segments.
19 
20  > *Input arguments*
21 
22  * `center` (*type:* `list`): Center of the helix in meters
23  * `radius` (*type:* `float`): Radius of the helix in meters
24  * `n_turns` (*type:* `int`): Number of turns
25  * `delta_z` (*type:* `float`): Length of the step in the Z direction between each turn of the helix in meters
26  * `angle_offset` (*type:* `float`): Angle offset to start the helix
27  * `is_clockwise` (*type:* `bool`, *default:* `True`): If `True`, the helix is generated clockwise.
28 
29  > *Example*
30 
31  ```python
32  radius = 3
33  center = [2, 2, 2]
34  n_turns = 2
35  delta_z = 1
36  angle_offset = 0.0
37  is_clockwise = True
38 
39  helix = HelicalSegment(center, radius, n_turns, delta_z, angle_offset, is_clockwise)
40 
41  u = numpy.linspace(0, 1, 100)
42  pnts = numpy.array([helix.interpolate(i) for i in u])
43  ```
44  """
45  def __init__(self, center, radius, n_turns, delta_z, angle_offset, is_clockwise=True):
46  self._center = np.array(center)
47  assert self._center.size == 3, 'Size of center point vector must be 3'
48 
49  assert radius > 0, 'Helix radius must be greater than zero'
50  assert n_turns > 0, 'Number of turns must be greater than zero'
51  assert isinstance(is_clockwise, bool), 'is_clockwise flag must be a boolean'
52 
53  self._radius = radius
54  self._n_turns = n_turns
55  self._angle_offset = angle_offset
56  self._is_clockwise = is_clockwise
57  self._delta_z = delta_z
58  self._step_z = float(self._delta_z) / self._n_turns
59 
60  def get_length(self):
61  """Return the length of the helix in meters"""
62  return self._n_turns * np.sqrt(self._step_z**2 + (2 * np.pi * self._radius)**2)
63 
64  def get_pitch(self):
65  """Return the pitch angle of the helical path in radians"""
66  return np.sin(self._step_z / np.sqrt(self._step_z**2 + (2 * np.pi * self._radius)**2))
67 
68  def interpolate(self, u):
69  """Compute the 3D point on the helical path
70 
71  > *Input arguments*
72 
73  * `param` (*type:* `data_type`, *default:* `data`): Parameter description
74 
75  > *Returns*
76 
77  Description of return values
78  """
79  u = max(u, 0)
80  u = min(u, 1)
81  delta = 1 if self._is_clockwise else -1
82  x = self._radius * np.cos(self._n_turns * 2 * np.pi * u * delta + self._angle_offset)
83  y = self._radius * np.sin(self._n_turns * 2 * np.pi * u * delta + self._angle_offset)
84  z = self._n_turns * u * self._step_z
85 
86  return self._center + np.array([x, y, z])
87 
def __init__(self, center, radius, n_turns, delta_z, angle_offset, is_clockwise=True)


uuv_trajectory_control
Author(s):
autogenerated on Thu Jun 18 2020 03:28:42