Skip to content

Commit 46d6bd1

Browse files
author
cl03
committed
utilize path distance instead of direct distance
1 parent 8976b31 commit 46d6bd1

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • bitbots_navigation/bitbots_path_planning/bitbots_path_planning

bitbots_navigation/bitbots_path_planning/bitbots_path_planning/controller.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,21 @@ def step(self, path: Path) -> tuple[Twist, PointStamped]:
6969
end_pose.position.y - current_pose.position.y, end_pose.position.x - current_pose.position.x
7070
)
7171

72-
# Calculate the distance from our current position to the final position of the global plan
73-
distance = math.hypot(
74-
end_pose.position.x - current_pose.position.x, end_pose.position.y - current_pose.position.y
75-
)
72+
if len(path.poses) < 3:
73+
# Calculate the distance from our current position to the final position of the global plan
74+
distance = math.hypot(
75+
end_pose.position.x - current_pose.position.x, end_pose.position.y - current_pose.position.y
76+
)
77+
else:
78+
# Calculate path length
79+
distance = 0
80+
a_position = current_pose.position
81+
pose: PoseStamped
82+
for pose in path.poses:
83+
b_postion = pose.pose.position
84+
distance += math.hypot(b_postion.x - a_position.x, b_postion.y - a_position.y)
85+
a_position = b_postion
86+
distance += math.hypot(end_pose.position.x - a_position.x, end_pose.position.y - a_position.y)
7687

7788
# Calculate the translational walk velocity.
7889
# It considers the distance and breaks if we are close to the final position of the global plan

0 commit comments

Comments
 (0)