Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Calculates current heading #88

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Krithik1
Copy link
Contributor

@Krithik1 Krithik1 commented Feb 14, 2024

Description

  • Resolves Publish desired heading sailbot_workspace#283
  • Gets current waypoint from GPS subscriber and finds the waypoint in self.local_path.waypoints
  • If found, calculates the heading based on formula linked in resources
  • GPS data not being sent, so running into error. If mock GPS data then works fine

Verification

  • Used mock GPS data for the current waypoint. Used the first value in the waypoints list.

Resources

@Krithik1 Krithik1 changed the title Made changes to calculate current heading. Calculates current heading Feb 14, 2024
Copy link
Contributor

@jamenkaye jamenkaye left a comment

Choose a reason for hiding this comment

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

Good start! I left a few comments 👍

local_pathfinding/node_navigate.py Outdated Show resolved Hide resolved
local_pathfinding/node_navigate.py Show resolved Hide resolved
local_pathfinding/node_navigate.py Outdated Show resolved Hide resolved
math.cos(current_waypoint.latitude),
(next_waypoint.latitude-current_waypoint.latitude)
)
return heading
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to add some tests for this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be the best way to test this:

  1. Create a helper function to get_desired_heading() that accepts "simple" arguments like waypoints or lists of waypoints, rather than "complicated" arguments like self (which is a whole sailbot object). get_desired_heading() will basically just call the helper function.
  2. Create test_node_navigate.py like you suggested, and just test the helper function. I'd suggest using simple tests like when the desired heading is $0 \degree$ or $90 \degree$, and maybe some more complicated tests where the "actual" value is computed with geodesic.inv() as well.

Copy link
Contributor

@jamenkaye jamenkaye left a comment

Choose a reason for hiding this comment

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

Hi Krithik, I left a few comments! We might need to add some more complexity here depending on if we need to determine which local waypoint we're going towards. Jay might be working on this tho so we can talk to him tomorrow.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe self.gps.lat_lon is the current GPS position of the boat, which is generally not one of the waypoints. I think Jay might be working on code to determine the next local waypoint, but we can sync up with him tomorrow

@@ -175,8 +178,22 @@ def get_desired_heading(self) -> float:
self.gps, self.ais_ships, self.global_path, self.filtered_wind_sensor, self.planner
Copy link
Contributor

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

break
if next_waypoint is None:
return 0.0
heading = GEODESIC.inv(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think GEODESIC.inv() has multiple returns (documentation), and I think you only want the forward azimuth (image at bottom)

I believe Patrick is a fan of this kind of syntax for this situation: _, value, _ = myfunc(), where myfunc() returns a touple:

def myfunc():
	return (1, 2, 3)

In this example, print(value) outputs 2.

image

math.cos(current_waypoint.latitude),
(next_waypoint.latitude-current_waypoint.latitude)
)
return heading
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be the best way to test this:

  1. Create a helper function to get_desired_heading() that accepts "simple" arguments like waypoints or lists of waypoints, rather than "complicated" arguments like self (which is a whole sailbot object). get_desired_heading() will basically just call the helper function.
  2. Create test_node_navigate.py like you suggested, and just test the helper function. I'd suggest using simple tests like when the desired heading is $0 \degree$ or $90 \degree$, and maybe some more complicated tests where the "actual" value is computed with geodesic.inv() as well.

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

Successfully merging this pull request may close these issues.

Publish desired heading
3 participants