Skip to content

feat: Add reverse mode in pure pursuit #1194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yangtzech
Copy link
Contributor

@yangtzech yangtzech commented Apr 5, 2025

Reference issue

What does this implement/fix?

  1. add reverse mode in pure pursuit and unit test
  2. add visualization of vehicle

Additional information

CheckList

  • Did you add an unittest for your new example or defect fix?
  • Did you add documents for your new example?
  • All CIs are green? (You can check it after submitting)

@yangtzech
Copy link
Contributor Author

yangtzech commented Apr 5, 2025

@AtsushiSakai some error not caused by this PR ocurred

@AtsushiSakai
Copy link
Owner

@yangtzech Thank you for your PR. Could you please rebase on the master branch?

@AtsushiSakai AtsushiSakai requested a review from Copilot May 1, 2025 05:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds reverse mode support to the pure pursuit algorithm and enhances vehicle visualization.

  • Adds a new unit test for reverse mode (test_backward)
  • Updates the State class and pure pursuit steering control to account for reverse movement
  • Introduces an improved vehicle plotting function with a reverse mode indicator

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/test_pure_pursuit.py Adds a new test case to validate reverse driving mode
PathTracking/pure_pursuit/pure_pursuit.py Updates algorithm logic for reverse mode and enhances vehicle visualization
Comments suppressed due to low confidence (2)

PathTracking/pure_pursuit/pure_pursuit.py:34

  • [nitpick] Global simulation control variables are declared at the module level; consider centralizing these related settings in a dedicated configuration block to improve maintainability.
show_animation = True  // pause_simulation = False  // is_reverse_mode = False

PathTracking/pure_pursuit/pure_pursuit.py:183

  • The numpy module is referenced via 'np' in plot_vehicle but there is no corresponding import (e.g., 'import numpy as np') in this module.
wheel = np.array([

Copy link
Owner

@AtsushiSakai AtsushiSakai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangtzech Thank you for the PR, and sorry for the delayed review.

I’ve added a few comments, so please take a look. Also, it would be great if you could add some diagrams or equations explaining the simulation to this document (though it’s not mandatory).
https://atsushisakai.github.io/PythonRobotics/modules/6_path_tracking/pure_pursuit_tracking/pure_pursuit_tracking.html

@@ -141,19 +163,119 @@ def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
plt.arrow(x, y, length * math.cos(yaw), length * math.sin(yaw),
fc=fc, ec=ec, head_width=width, head_length=width)
plt.plot(x, y)

def plot_vehicle(x, y, yaw, steer=0.0, color='blue', is_reverse=False):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line here.

"""
# Adjust heading angle in reverse mode
if is_reverse:
yaw = angle_mod(yaw + math.pi) # Rotate heading by 180 degrees
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to rotate the heading by 180 degrees? I thought the heading would stay the same even when moving backward, and that it wouldn’t affect the rendering.

delta = state.direction * math.atan2(2.0 * WB * math.sin(alpha) / Lf, 1.0)

# Limit steering angle to max value
delta = max(min(delta, MAX_STEER), -MAX_STEER)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.rear_x = self.x - ((WB / 2) * math.cos(self.yaw))
self.rear_y = self.y - ((WB / 2) * math.sin(self.yaw))
self.direction = -1 if is_reverse else 1 # Direction based on reverse flag
self.rear_x = self.x - self.direction * ((WB / 2) * math.cos(self.yaw))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rear_x, rear_y for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants