Skip to content
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

User/medhansh/desired heading #467

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/local_pathfinding/local_pathfinding/local_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def update_if_needed(
if ompl_path.solved:
self._logger.info("Updating local path")
self._update(ompl_path)
return True

return False

def _update(self, ompl_path: OMPLPath):
self._ompl_path = ompl_path
Expand Down
42 changes: 39 additions & 3 deletions src/local_pathfinding/local_pathfinding/node_navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import custom_interfaces.msg as ci
from local_pathfinding.local_path import LocalPath

from pyproj import Geod


def main(args=None):
rclpy.init(args=args)
Expand Down Expand Up @@ -105,6 +107,8 @@ def __init__(self):
self.gps = None
self.global_path = None
self.filtered_wind_sensor = None
self.current_waypoint_index = 0
self.current_coord = self.local_path.waypoints[self.current_waypoint_index]

# attributes
self.local_path = LocalPath(parent_logger=self.get_logger())
Expand Down Expand Up @@ -171,12 +175,44 @@ def get_desired_heading(self) -> float:
self._log_inactive_subs_warning()
return -1.0

self.local_path.update_if_needed(
path_is_updated = self.local_path.update_if_needed(
self.gps, self.ais_ships, self.global_path, self.filtered_wind_sensor, self.planner
)

# TODO: create function to compute the heading from current position to next local waypoint
return 0.0
boat_lat = self.gps.position.lat_lon.latitude
Copy link
Contributor

Choose a reason for hiding this comment

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

The boat latitude and longitude could be placed in a tuple and parsed into the functions

boat_long = self.gps.position.lat_lon.longitude

if (path_is_updated):
self.current_waypoint_index = 0

return self.get_angle(boat_lat, boat_long, self.current_coord.latitude,
self.current_coord.longitude)

def get_angle(self, boat_lat, boat_long, current_lat, current_long):
# calculate distance from current position of boat to next local waypoint
distance = self.calculate_distance(boat_lat, boat_long, current_lat, current_long)
# update waypoint
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments are redundant

threshold = 0.5
self.update_waypoint(distance, threshold)
# return angle of direction
return self.calculate_angle(boat_lat, boat_long, current_lat, current_long)

def update_waypoint(self, distance, threshold):
if (distance < threshold):
# then update the next local waypoint by increasing index by 1
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this comment.

self.current_waypoint_index += 1

return self.local_path.waypoints[self.current_waypoint_index]

def calculate_distance(lat1, lon1, lat2, lon2):
GEODESIC = Geod(ellps="WGS84")
Copy link
Contributor

@FireBoyAJ24 FireBoyAJ24 Jan 11, 2025

Choose a reason for hiding this comment

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

You could add this statements to the top of the file

_, _, distance = GEODESIC.inv(lon1, lat1, lon2, lat2)
return distance

def calculate_angle(lat1, lon1, lat2, lon2):
Copy link
Contributor

Choose a reason for hiding this comment

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

The calculate_distance and calculate_angle function looks redundant as the functions are acting as wrappers to the geodesic.inv function. You could add the geodesic.inv function to the 'get_angle' function.

GEODESIC = Geod(ellps="WGS84")
forward_azimuth, _, _ = GEODESIC.inv(lon1, lat1, lon2, lat2)
return forward_azimuth

def update_params(self):
"""Update instance variables that depend on parameters if they have changed."""
Expand Down
Loading