generated from athackst/vscode_ros2_workspace
-
Notifications
You must be signed in to change notification settings - Fork 3
#825: Tracking Wind data over certain amount of time (seconds) #847
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
MilcToast
wants to merge
10
commits into
main
Choose a base branch
from
MilcToast/track-wind-data-825
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce06c17
added wind history to track last X amount of data, calculate average …
MilcToast d337d0d
updated docstrings of update_wind_history and _calculate_average_wind…
MilcToast ee75e1a
new test
MilcToast c4dc92b
Merge branch 'main' into MilcToast/track-wind-data-825
MilcToast 2b1e5d8
removed wind_history and wind_average from LocalPathState that was th…
MilcToast 2285ae2
update _calculate_average_wind's comments
MilcToast 0bb6331
combined 3 for loops into 1 for small performance improvement
MilcToast 7261d80
_calculate_average_wind now returns None if wind_history is empty
MilcToast a0fd9f1
specified wind_average is in kmph/dig for speed/direction
MilcToast d350335
Merge branch 'main' into MilcToast/track-wind-data-825
MilcToast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| """The path to the next global waypoint, represented by the LocalPath class.""" | ||
|
|
||
| import math | ||
| from collections import deque | ||
| from typing import List, Optional | ||
|
|
||
| import custom_interfaces.msg as ci | ||
|
|
@@ -14,6 +15,7 @@ | |
|
|
||
| WIND_SPEED_CHANGE_THRESH_PROP = 0.3 | ||
| WIND_DIRECTION_CHANGE_THRESH_DEG = 10 | ||
| WIND_HISTORY_LEN = 30 | ||
| LOCAL_WAYPOINT_REACHED_THRESH_KM = 0.5 | ||
| HEADING_WEIGHT = 0.6 | ||
| COST_WEIGHT = 0.4 | ||
|
|
@@ -104,13 +106,19 @@ class LocalPath: | |
| path (Path): Collection of coordinates that form the local path to the next | ||
| global waypoint. | ||
| state (LocalPathState): the current local path state. | ||
| wind_history (List[wcs.Wind]): History of wind sensor readings | ||
| (Queue with max length WIND_HISTORY_LEN). | ||
| wind_average (Optional[wcs.Wind]): Average of the wind history, used for path planning. | ||
| Updated every time a new wind sensor reading is added to wind_history. | ||
| """ | ||
|
|
||
| def __init__(self, parent_logger: RcutilsLogger): | ||
| self._logger = parent_logger.get_child(name="local_path") | ||
| self._ompl_path: Optional[OMPLPath] = None | ||
| self.path: Optional[ci.Path] = None | ||
| self.state: Optional[LocalPathState] = None | ||
| self.wind_history: deque = deque(maxlen=WIND_HISTORY_LEN) | ||
| self.wind_average: Optional[wcs.Wind] = None | ||
|
|
||
| @staticmethod | ||
| def calculate_desired_heading_and_wp_index( | ||
|
|
@@ -362,3 +370,36 @@ def _update(self, ompl_path: OMPLPath): | |
|
|
||
| self._ompl_path = ompl_path | ||
| self.path = self._ompl_path.get_path() | ||
|
|
||
| def update_wind_history(self, current_wind: wcs.Wind): | ||
| """Updates wind history and recalculates the average wind. The wind values are all | ||
| apparent wind. | ||
|
|
||
| Maintains a history of up to WIND_HISTORY_LEN wind readings. When the history | ||
| exceeds the max length, the oldest reading is removed. | ||
|
|
||
| Args: | ||
| current_wind (wcs.Wind): Current wind speed (kmph) and direction (deg) | ||
| """ | ||
|
|
||
| self.wind_history.append(current_wind) | ||
|
|
||
| # Recalculate average wind from history once minimum wind readings reached | ||
| if len(self.wind_history) == WIND_HISTORY_LEN: | ||
| self.wind_average = self._calculate_average_wind() | ||
|
|
||
| def _calculate_average_wind(self) -> Optional[wcs.Wind]: | ||
| """Calculates the average apparent wind from the wind history once the deque is full. | ||
|
|
||
| Returns: | ||
| Optional[wcs.Wind]: Average wind object, or None if history is empty. | ||
| """ | ||
| avg_speed = sum(wind.speed_kmph for wind in self.wind_history) / len(self.wind_history) | ||
|
||
|
|
||
| # Use circular mean to handle wrap-around | ||
| sin_sum = sum(math.sin(math.radians(wind.dir_deg)) for wind in self.wind_history) | ||
| cos_sum = sum(math.cos(math.radians(wind.dir_deg)) for wind in self.wind_history) | ||
MilcToast marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| avg_direction = math.degrees(math.atan2(sin_sum, cos_sum)) | ||
| avg_direction = cs.bound_to_180(avg_direction) | ||
|
|
||
| return wcs.Wind(avg_speed, avg_direction) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Make it clear here that the direction for this wind object is in degrees.