6 from geometry_msgs.msg
import Pose, Point
8 def project_position(start, end, current, mindist, maxdist, line_divergence, side_offset):
10 def unit_vector(vector):
11 return vector / np.linalg.norm(vector + 1e-10)
14 return np.array([p.position.x, p.position.y])
16 def np_to_point(np_array):
17 return Point(np_array[0], np_array[1], 0)
19 start_pos = pose_to_np(start)
20 end_pos = pose_to_np(end)
21 current_pos = pose_to_np(current)
24 line = end_pos - start_pos
25 unit_line = unit_vector(line)
28 current_to_start = current_pos - start_pos
29 projection_length = np.dot(current_to_start, unit_line)
30 projection = start_pos + unit_line * projection_length
33 if np.dot(projection - start_pos, start_pos - end_pos) > 0:
34 projection = start_pos
37 deltadist = current_pos - projection
38 value = 0
if line_divergence == 0
else (line_divergence - np.sqrt(deltadist.dot(deltadist))) / line_divergence
39 distance = mindist + (maxdist - mindist) *
clamp(value, 0.0, 1.0)
40 new_pos = projection + unit_vector(end_pos - start_pos) * distance
43 if np.dot(new_pos - end_pos, end_pos - start_pos) > 0:
47 additional_vector = -side_offset * (current_pos - projection)
49 return np_to_point(new_pos+ additional_vector)
52 return min
if num < min
else max
if num > max
else num
56 pose.position.x = t.transform.translation.x
57 pose.position.y = t.transform.translation.y
58 pose.position.z = t.transform.translation.z
59 pose.orientation.x = t.transform.rotation.x
60 pose.orientation.y = t.transform.rotation.y
61 pose.orientation.z = t.transform.rotation.z
62 pose.orientation.w = t.transform.rotation.w
68 to_vec.x - from_vec.x,
69 to_vec.y - from_vec.y,
71 target_distance = math.sqrt(target_direction[0] ** 2 + target_direction[1] ** 2)
73 return [target_direction[0] / target_distance, target_direction[1] / target_distance]
76 def __init__(self, kp, ki, kd, target=0, windup_guard=20.0):
94 error = self.
target - current_value