-
Notifications
You must be signed in to change notification settings - Fork 3
Raghumanimehta/485 removing ompl path state constructor #491
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
Merged
SPDonaghy
merged 9 commits into
main
from
raghumanimehta/485-removing_OMPLPathState_constructor
Feb 22, 2025
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e73014d
Removed OMPLPathState and added logic to calculate boat range and domain
raghumanimehta 69e4313
Refactoring to remove OMPLPathState complete, all tests pass
raghumanimehta cfe35ad
Merge branch 'main' into raghumanimehta/485-removing_OMPLPathState_co…
SPDonaghy 6815995
updates after review
raghumanimehta dfd0d6e
fixed linting issue to changes after review
raghumanimehta 8fb4fd8
Merge branch 'main' into raghumanimehta/485-removing_OMPLPathState_co…
raghumanimehta 68ba952
small changes to LocalPathState docstring
SPDonaghy b53daa2
renamed state_domain to start_box
SPDonaghy 137ad07
rm type cast goal x and y to int & added dummy wind speed
SPDonaghy 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
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 |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |
| from custom_interfaces.msg import HelperLatLon | ||
| from rclpy.impl.rcutils_logger import RcutilsLogger | ||
|
|
||
| # Fix the import | ||
| from shapely.geometry import MultiPolygon, Point, Polygon, box | ||
|
|
||
| import local_pathfinding.coord_systems as cs | ||
| from local_pathfinding.objectives import get_sailing_objective | ||
|
|
||
|
|
@@ -24,29 +27,6 @@ | |
| # ou.setLogLevel(ou.LOG_WARN) | ||
|
|
||
|
|
||
| class OMPLPathState: | ||
| def __init__(self, local_path_state: LocalPathState, logger: RcutilsLogger): | ||
| # TODO: derive OMPLPathState attributes from local_path_state | ||
| self.heading_direction = 45.0 | ||
| self.wind_direction = 10.0 | ||
| self.wind_speed = 1.0 | ||
|
|
||
| self.state_domain = (-1, 1) | ||
| self.state_range = (-1, 1) | ||
| self.start_state = (0.5, 0.4) | ||
| self.goal_state = (0.5, -0.4) | ||
|
|
||
| self.reference_latlon = ( | ||
| local_path_state.global_path[-1] | ||
| if local_path_state.global_path and len(local_path_state.global_path) > 0 | ||
| else HelperLatLon(latitude=0.0, longitude=0.0) | ||
| ) | ||
|
|
||
| if local_path_state: | ||
| self.planner = None | ||
| # self.planner = pyompl.RRTstar() | ||
|
|
||
|
|
||
| class OMPLPath: | ||
| """Represents the general OMPL Path. | ||
|
|
||
|
|
@@ -68,7 +48,11 @@ def __init__( | |
| parent_logger (RcutilsLogger): Logger of the parent class. | ||
| max_runtime (float): Maximum amount of time in seconds to look for a solution path. | ||
| local_path_state (LocalPathState): State of Sailbot. | ||
|
|
||
| Fields not mentioned in Args: | ||
| box_buffer (float): buffer around the sailbot position and the goal position in km | ||
SPDonaghy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| self.box_buffer = 1 | ||
| self._logger = parent_logger.get_child(name="ompl_path") | ||
|
|
||
| self._simple_setup = self._init_simple_setup(local_path_state) # this needs state | ||
|
|
@@ -114,6 +98,13 @@ def get_waypoints(self) -> List[HelperLatLon]: | |
|
|
||
| return waypoints | ||
|
|
||
| def create_space(self, position) -> Polygon: | ||
SPDonaghy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ Create a space around the given position. Position is the center of the space and | ||
| is a tuple of x and y. | ||
| """ | ||
| space = Point(position[0], position[1]).buffer(self.box_buffer, cap_style=3, join_style=2) | ||
| return space | ||
|
|
||
| def update_objectives(self): | ||
| """Update the objectives on the basis of which the path is optimized. | ||
| Raises: | ||
|
|
@@ -122,21 +113,32 @@ def update_objectives(self): | |
| raise NotImplementedError | ||
|
|
||
| def _init_simple_setup(self, local_path_state) -> pyompl.SimpleSetup: | ||
| """Initialize and configure the OMPL SimpleSetup object. | ||
| self.state = local_path_state | ||
|
|
||
| Returns: | ||
| og.SimpleSetup: Encapsulates the various objects necessary to solve a geometric or | ||
| control query in OMPL. | ||
| """ | ||
| self.state = OMPLPathState(local_path_state, self._logger) | ||
| # Create buffered spaces and extract their centers | ||
| state_domain = self.create_space(self.state.position) | ||
|
||
| start_x, start_y = self.state.position # Use original position for coordinates | ||
SPDonaghy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if not self.state.global_path: | ||
| goal_polygon = self.create_space([0, 0]) | ||
| goal_x, goal_y = (0, 0) | ||
| else: | ||
| goal_position = self.state.global_path[-1] | ||
SPDonaghy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| goal_polygon = self.create_space(goal_position) | ||
| goal_x, goal_y = goal_position | ||
|
|
||
| # create an SE2 state space: rotation and translation in a plane | ||
| space = pyompl.SE2StateSpace() | ||
|
|
||
| # set the bounds of the state space | ||
| bounds = pyompl.RealVectorBounds(dim=2) | ||
| x_min, x_max = self.state.state_domain | ||
| y_min, y_max = self.state.state_range | ||
| big_polygon = box(*MultiPolygon([state_domain, goal_polygon]).bounds) | ||
SPDonaghy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| x_min, y_min, x_max, y_max = big_polygon.bounds | ||
| # x_min, x_max = state_domain | ||
| # y_min, y_max = state_range | ||
|
|
||
| if x_max <= x_min or y_max <= y_min: | ||
| raise ValueError(f"Invalid bounds: x=[{x_min}, {x_max}], y=[{y_min}, {y_max}]") | ||
| bounds.setLow(0, x_min) | ||
| bounds.setLow(1, y_min) | ||
| bounds.setHigh(0, x_max) | ||
|
|
@@ -156,8 +158,8 @@ def _init_simple_setup(self, local_path_state) -> pyompl.SimpleSetup: | |
| # set the goal and start states of the simple setup object | ||
| start = pyompl.ScopedState(space) | ||
| goal = pyompl.ScopedState(space) | ||
| start_x, start_y = self.state.start_state | ||
| goal_x, goal_y = self.state.goal_state | ||
| # start_x, start_y = start_state | ||
SPDonaghy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # goal_x, goal_y = goal_state | ||
| start.setXY(start_x, start_y) | ||
| goal.setXY(goal_x, goal_y) | ||
| """self._logger.debug( | ||
|
|
@@ -170,6 +172,7 @@ def _init_simple_setup(self, local_path_state) -> pyompl.SimpleSetup: | |
| # Constructs a space information instance for this simple setup | ||
| space_information = simple_setup.getSpaceInformation() | ||
|
|
||
| # figure this out | ||
SPDonaghy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.state.planner = pyompl.RRTstar(space_information) | ||
|
|
||
| # set the optimization objective of the simple setup object | ||
|
|
@@ -178,7 +181,8 @@ def _init_simple_setup(self, local_path_state) -> pyompl.SimpleSetup: | |
| objective = get_sailing_objective( | ||
| space_information, | ||
| simple_setup, | ||
| self.state.heading_direction, | ||
| # This too | ||
| self.state.heading, | ||
| self.state.wind_direction, | ||
| self.state.wind_speed, | ||
| ) | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.