Skip to content

Commit

Permalink
Move Runner's retrying logic from plan() to update_and_plan()
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Kolbe committed Jan 9, 2014
1 parent 9a1a0fc commit ccf3d55
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 18 additions & 12 deletions rgoap/src/rgoap/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,35 @@ def _update_worldstate(self):
Condition.initialize_worldstate(self.worldstate)
_logger.info("worldstate initialized/updated to: %s", self.worldstate)

def update_and_plan(self, goal, tries=1, introspection=False):
"""update worldstate and call self.plan(...)"""
self._update_worldstate()
return self.plan(goal, tries, introspection)


def plan(self, goal, tries=1, introspection=False):
"""plan for given goal and return start_node of plan or None"""
def _check_conditions(self):
# check for any still uninitialised condition
for (condition, value) in self.worldstate._condition_values.iteritems():
if value is None:
_logger.warn("Condition still 'None': %s", condition)


def update_and_plan(self, goal, tries=1, introspection=False):
"""update worldstate and call self.plan(...), repeating for
number of tries or until a plan is found"""
assert tries >= 1
while tries > 0:
tries -= 1
# FIXME: retries won't work here if the input does not change
start_node = self.planner.plan(goal=goal)
self._update_worldstate()
start_node = self.plan(goal, introspection)
if start_node is not None:
break

if tries > 0: # if there are tries left
_logger.warn("Runner retrying in update_and_plan")
return start_node


def plan(self, goal, introspection=False):
"""plan for given goal and return start_node of plan or None"""
self._check_conditions()
return self.planner.plan(goal=goal)



def plan_and_execute_goals(self, goals):
"""Sort goals by usability and try to plan and execute one by one until
one goal is achieved"""
Expand Down Expand Up @@ -176,7 +182,7 @@ def update_and_plan_and_execute(self, goal, tries=1, introspection=False):
start_node = self.update_and_plan(goal, tries, introspection)

if start_node is None:
# TODO: maybe at this point update and replan? reality might have changed
# TODO: maybe at this point update and replan, regardless of 'tries'? reality might have changed
_logger.error("RGOAP Runner aborts, no plan found!")
return 'aborted'

Expand Down
4 changes: 2 additions & 2 deletions rgoap_ros/src/rgoap_ros/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ def service_preempt(self):
self._current_smach.service_preempt()


def plan(self, goal, tries=1, introspection=False):
def plan(self, goal, introspection=False):
"""plan for given goal and return start_node of plan or None
introspection: introspect RGOAP planning via smach.introspection
"""
if introspection:
self._setup_introspection()

start_node = Runner.plan(self, goal, tries)
start_node = Runner.plan(self, goal, introspection)

if introspection:
if start_node is not None:
Expand Down

0 comments on commit ccf3d55

Please sign in to comment.