-
Notifications
You must be signed in to change notification settings - Fork 0
Calculates current heading #88
base: main
Are you sure you want to change the base?
Changes from all commits
58cdc2f
8788e40
2944157
c7fe341
052962f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
"""The main node of the local_pathfinding package, represented by the `Sailbot` class.""" | ||
|
||
import rclpy | ||
from pyproj import Geod | ||
from rclpy.node import Node | ||
|
||
import custom_interfaces.msg as ci | ||
from local_pathfinding.local_path import LocalPath | ||
|
||
GEODESIC = Geod(ellps="WGS84") | ||
|
||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
|
@@ -175,8 +178,22 @@ def get_desired_heading(self) -> float: | |
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 | ||
current_waypoint = self.gps.lat_lon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe |
||
next_waypoint = None | ||
waypoints = self.local_path.waypoints | ||
for i in range(len(waypoints)): | ||
if waypoints[i] == current_waypoint and i < len(waypoints) - 1: | ||
next_waypoint = waypoints[i + 1] | ||
break | ||
if next_waypoint is None: | ||
return 0.0 | ||
heading = GEODESIC.inv( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I believe Patrick is a fan of this kind of syntax for this situation:
In this example, |
||
lats1=current_waypoint.latitude, | ||
lons1=current_waypoint.longitude, | ||
lats2=next_waypoint.latitude, | ||
lons2=next_waypoint.longitude, | ||
)[0] | ||
return heading | ||
Krithik1 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to add some tests for this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the tests, should I create a new test_node_navigate.py file and manually set the value of self.gps to calculate the desired heading? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be the best way to test this:
|
||
|
||
def update_params(self): | ||
"""Update instance variables that depend on parameters if they have changed.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is about line 175:
The function description says we should return something that violates the heading convention in the case of an error, but the heading convention allows$-180 \degree < \text{heading} \leq 180 \degree$ .
Can you please change the return value on line 175 to something outside those bounds? I'd suggest 404 since that's a common error number for websites haha