TestPrecEffSym.py
Go to the documentation of this file.
00001 # Copyright (c) 2013, Felix Kolbe
00002 # All rights reserved. BSD License
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 # * Redistributions of source code must retain the above copyright
00009 #   notice, this list of conditions and the following disclaimer.
00010 #
00011 # * Redistributions in binary form must reproduce the above copyright
00012 #   notice, this list of conditions and the following disclaimer in the
00013 #   documentation and/or other materials provided with the distribution.
00014 #
00015 # * Neither the name of the {organization} nor the names of its
00016 #   contributors may be used to endorse or promote products derived
00017 #   from this software without specific prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 
00031 """
00032 RGOAPTestPreconditionEffectSymmetry
00033 """
00034 
00035 
00036 from rgoap import Condition, Precondition, Effect, Action, Goal
00037 from rgoap import MemoryCondition
00038 from rgoap import Runner
00039 
00040 
00041 
00042 class SymmetricAction(Action):
00043 
00044     def __init__(self):
00045         Action.__init__(self,
00046                         [Precondition(Condition.get('robot.bumpered'), True)],
00047                         [Effect(Condition.get('robot.bumpered'), False)])
00048 
00049     def run(self, next_worldstate):
00050         print '%s: resetting bumper..' % self.__class__
00051 
00052 
00053 
00054 if __name__ == "__main__":
00055 
00056     runner = Runner()
00057 
00058     Condition.add(MemoryCondition(runner.memory, 'robot.bumpered', True))
00059 
00060     runner.actions.add(SymmetricAction())
00061 
00062 
00063     Condition.initialize_worldstate(runner.worldstate)
00064     print 'worldstate now is: ', runner.worldstate
00065 
00066 
00067     goal = Goal([Precondition(Condition.get('robot.bumpered'), False)])
00068 
00069     start_node = runner.update_and_plan(goal, introspection=True)
00070 
00071     print 'start_node: ', start_node
00072 
00073 
00074     if start_node is None:
00075         print 'No plan found! Check your ROS graph!'
00076     else:
00077         runner.execute(start_node)


rgoap
Author(s): Felix Kolbe
autogenerated on Sun Oct 5 2014 23:53:02