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

Utility module #21

Merged
merged 17 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions boat_nav/src/layline_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def compass_callback(self, compass):
self.compass = compass.data
self.update_apparent_wind()


def update_apparent_wind(self):
self.apparent_wind_heading = angles.normalize(self.ane_reading + self.compass)
self.wind_coming = angles.opposite(self.apparent_wind_heading)
Expand Down
16 changes: 8 additions & 8 deletions boat_nav/src/path_planners/long.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ class LongPlanner(Planner):
"""Simple Planner implementation that traverses the waypoints in waypoints_raw,
but does not destroy achieved waypoints, allowing infinite looping.
"""

@overrides
def setup(self):
if len(self.waypoints) is 0:
rospy.loginfo(rospy.get_caller_id() + " No points to nav")
self.set_minor_state(BoatState.MIN_COMPLETE)
return

self.publish_target(self.waypoints[0])
self.set_minor_state(BoatState.MIN_PLANNING)


@overrides
def planner(self):

# If we've reached a waypoint, add it to the end of the list to continue looping forever
if len(self.waypoints) > 0 and self.boat_reached_target():
if len(self.waypoints) > 0 and self._boat_reached_target():
self.waypoints.append(self.waypoints[0])

# Run the default traverse_waypoints planner
self.traverse_waypoints_planner();
self._traverse_waypoints_planner()
12 changes: 6 additions & 6 deletions boat_nav/src/path_planners/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

class NavPlanner(Planner):
"""Simple Planner implementation that traverses the waypoints in waypoints_raw once each."""

@overrides
def setup(self):
if len(self.waypoints) is 0:
rospy.loginfo(rospy.get_caller_id() + " No points to nav")
self.set_minor_state(BoatState.MIN_COMPLETE)
return

self.publish_target(self.waypoints[0])
self.set_minor_state(BoatState.MIN_PLANNING)


@overrides
def planner(self):

# Run the default traverse_waypoints planner
self.traverse_waypoints_planner();
self._traverse_waypoints_planner()
16 changes: 5 additions & 11 deletions boat_nav/src/path_planners/planner_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def planner(self):
NotImplementedError("Class %s doesn't implement planner()" % (self.__class__.__name__))


def traverse_waypoints_planner(self):
def _traverse_waypoints_planner(self):
"""Navigate through the waypoints on the waypoints_raw topic sequentially."""
waypoints = self.waypoints

# If the list of waypoints is not empty
if len(waypoints) > 0:

# If the boat is close enough to the waypoint, start navigating towards the next waypoint in the path
if self.boat_reached_target():
if self._boat_reached_target():
rospy.loginfo(rospy.get_caller_id() + " Reached intermediate waypoint (lat: %.2f, long: %.2f)", waypoints[0].pt.y, waypoints[0].pt.x)

del waypoints[0]
Expand Down Expand Up @@ -112,10 +112,7 @@ def _compass_callback(compass):

@staticmethod
def set_minor_state(minor):
"""Set the minor state of the BoatState.

@param minor: The state to set
"""
"""Set the minor state of the BoatState."""
Planner.state.minor = minor
_boat_state_pub.publish(Planner.state)

Expand All @@ -126,10 +123,7 @@ def clear_waypoints():

@staticmethod
def update_waypoints(new_pts):
SeamusJohnston marked this conversation as resolved.
Show resolved Hide resolved
"""Set and publish the specified waypoints.

@param new_pts: The waypoints to set
"""
"""Set and publish the specified waypoints."""
Planner.waypoints = new_pts
_waypoints_pub.publish(Planner.waypoints)

Expand Down Expand Up @@ -186,7 +180,7 @@ def _calc_wind_coming():
Planner.wind_coming = angles.opposite(Planner.new_wind_heading)


def boat_reached_target(self):
def _boat_reached_target(self):
"""Determine if the boat is within BUOY_TOL meters of the target_waypoint.

@return True if the boat is within the tolerance
Expand Down
4 changes: 2 additions & 2 deletions boat_nav/src/path_planners/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def planner(self):
if self.vision_target is ():

if len(self.waypoints) > 0:
self.traverse_waypoints_planner()
self._traverse_waypoints_planner()

# If we ran through all the waypoints set without finding anything, restart the planner
else:
Expand All @@ -72,7 +72,7 @@ def planner(self):
self.publish_target(Waypoint(self.vision_target, Waypoint.TYPE_INTERSECT))

#Once we intercept the vision target, publish and complete
if self.boat_reached_target(): #TODO: Add additional 'complete' criteria to ensure contact
if self._boat_reached_target(): #TODO: Add additional 'complete' criteria to ensure contact
self.found_pub.publish(True)
self.set_minor_state(BoatState.MIN_COMPLETE) #TODO: Add MIN_SHUTDOWN??

Expand Down
Loading