Example #1
0
"""Strict Ordered Patrolling Location r1, r2"""
ordered_patrol_day = StrictOrderedPatrolling([w["r1"], w["r2"]])

"""Strict Ordered Patrolling Location r3, r4"""
ordered_patrol_night = StrictOrderedPatrolling([w["r3"], w["r4"]])

"""Only if see a person, greet immediately"""
greet = BoundReaction(w["person"], w["greet"])

"""Only if see a person, register in the next step"""
register = BoundDelay(w["person"], w["register"])

try:

    n_day = Node(name="day_patrol_a",
                 context=w["day"],
                 specification=ordered_patrol_day,
                 world=w)

    n_night = Node(name="night_patrol_b",
                   context=w["night"],
                   specification=ordered_patrol_night,
                   world=w)

    n_greet = Node(name="greet_person",
                   specification=greet,
                   world=w)

    n_register = Node(name="register_person",
                      context=w["day"],
                      specification=register,
                      world=w)
Example #2
0
"""
"""We import the variables"""
w = RunningExample()
"""Strict Ordered Patrolling Location r1, r2"""
ordered_patrol_day = StrictOrderedPatrolling([w["r1"], w["r2"]])
print("one\n" + str(ordered_patrol_day))
"""Strict Ordered Patrolling Location r3, r4"""
ordered_patrol_night = StrictOrderedPatrolling([w["r3"], w["r4"]])
print("two\n" + str(ordered_patrol_night))
"""Only if see a person, greet in the next step"""
greet = BoundDelay(w["person"], w["greet"])

try:

    n_day = Node(name="day_patrol_a",
                 context=w["day"],
                 specification=ordered_patrol_day,
                 world=w)

    n_night = Node(name="night_patrol_b",
                   context=w["night"],
                   specification=ordered_patrol_night,
                   world=w)

    n_greet = Node(name="greet_person", specification=greet, world=w)

    n_day_greet = Node.composition({n_day, n_greet})
    n_night_greet = Node.composition({n_night, n_greet})
    cgg_con = Node.conjunction({n_day_greet, n_night_greet})
    cgg_dis = Node.disjunction({n_day_greet, n_night_greet})
    print(cgg_con)
    print("\n\ncon:\n")
Example #3
0
w = Crome()
"""Strict Ordered Patrolling Location r1, r2"""
ordered_patrol_day = StrictOrderedPatrolling([w["r1"], w["r2"]])
print("one\n" + str(ordered_patrol_day))
"""Strict Ordered Patrolling Location r3, r4"""
ordered_patrol_night = StrictOrderedPatrolling([w["r3"], w["r4"]])
print("two\n" + str(ordered_patrol_night))

greet = InstantaneousReaction(w["person"], w["greet"])

cure = InstantaneousReaction(w["person"], w["cure"])

try:

    n_day = Node(name="day_patrol_a",
                 context=w["day"],
                 specification=ordered_patrol_day,
                 world=w)

    n_night = Node(name="night_patrol_b",
                   context=w["night"],
                   specification=ordered_patrol_night,
                   world=w)

    n_greet = Node(name="greet_person",
                   context=w["day"],
                   specification=greet,
                   world=w)

    cgg_c = Node.build_cgg({n_day, n_night, n_greet}, Link.CONJUNCTION)
    cgg_c.session_name = "instant_action_under_context_conjunction"
    cgg_c.realize_specification_controllers()
Example #4
0
"""If it drops the object then it does not hold anymore"""
if_drop_not_hold = PromptReaction(w["hold"] & w["drop"], ~w["hold"])
"""Drop only when it is in the garbage and is holding"""
drop_near_garbage = InstantaneousReaction(w["drop"], ~w["k3"] & w["hold"])
"""GF(!hold)"""
keep_free_hands = GF(~w["hold"])

try:
    """Modeling the set of goals using robotic patterns"""
    set_of_goals = {
        Node(
            name="cleanup",
            description="Inside the living room are some misplaced objects. "
            "The robot has to tidy up that room, throwing to the garbage the unrecognized ones."
            "Find all misplaced objects in a room and bring them to their predeļ¬ned locations.",
            context=w["housekeeping"] & w["cleanup"],
            specification=Contract(
                assumptions=no_objects_when_hold,
                guarantees=patrol_living_room & stay_location_if_object
                & dont_hold_if_no_object & if_drop_not_hold & drop_near_garbage
                & keep_free_hands),
            world=w),
        Node(
            name="gpse",
            description="General Purpose Service Robot."
            "Similar to a modern smart-speaker,"
            "The robot can be asked to do anything and it immediately response with a voice notification",
            specification=Contract(
                guarantees=BoundReaction(w["alexa"], w["reply"])),
            world=w),
        Node(
            name="groceries",
Example #5
0
        "Conjunction has also failed since both goals have same ('TRUE') assumptions"
    )
"""We can remove the condition to begin from location c as well"""
g2 = Goal(
    name="patrol_c_d_init_c",
    description="Patrolling of locations c and d, beginning from location c",
    specification=Patrolling([t["c"], t["d"]]))

try:
    g12 = Goal.composition({g1, g2})
    print(g12)
    print("Composition Successful")
except GoalException as e:
    raise e
"""We can do the same with Node and build the CGG"""
n1_a = Node(goal=g1_a)

n1_b = Node(goal=g1_b)

n2 = Node(
    name="patrol_c_d_init_c",
    description="Patrolling of locations c and d, beginning from location c",
    specification=Patrolling([t["c"], t["d"]]) & Init(t["c"]))

try:
    cgg = Node.composition({n1_a, n1_b, n2})
    print(cgg)
except CGGException as e:
    print("Failed as before")

n2 = Node(
Example #6
0
File: run.py Project: pierg/crome
during context night => start from r3, patrol r3, r4 
always => if see a person, greet in the next step
"""

path = os.path.abspath(os.path.dirname(__file__))
"""We import the world"""
w = RunningExample()
"""Strict Ordered Patrolling Location r1, r2"""
ordered_patrol_day = StrictOrderedPatrolling([w["r1"], w["r2"]])
"""Strict Ordered Patrolling Location r3, r4"""
ordered_patrol_night = StrictOrderedPatrolling([w["r3"], w["r4"]])

try:

    n_day = Node(name="day_patrol_a",
                 context=w["day"],
                 specification=ordered_patrol_day,
                 world=w)

    n_night = Node(name="night_patrol_b",
                   context=w["night"],
                   specification=ordered_patrol_night,
                   world=w)

    t_cgg_start = time.time()
    cgg = Node.build_cgg({n_day, n_night})
    t_cgg_end = time.time()

    t_cgg = t_cgg_end - t_cgg_start

    cgg.set_session_name(folder_name)
    cgg.save()
Example #7
0
from cgg import Node
from cgg.exceptions import CGGException
from robocup import output_folder_name
from tools.persistence import Persistence

try:
    """Load the goals"""
    set_of_goals = Persistence.load_goals(output_folder_name)
    """Automatically build the CGG"""
    cgg = Node.build_cgg(set_of_goals)
    print(cgg)
    """Setting the saving folder"""
    cgg.set_session_name(output_folder_name)
    """Save CGG as text file"""
    cgg.save()
    """Save CGG so that it can be loaded later"""
    Persistence.dump_cgg(cgg)

except CGGException as e:
    raise e
Example #8
0
from cgg.exceptions import CGGException
from running_example import output_folder_name
from running_example.modeling_environment import RunningExample
from specification.atom.pattern.robotics.coremovement.surveillance import *
from specification.atom.pattern.robotics.trigger.triggers import *
from tools.persistence import Persistence
"""We import the environment"""
w = RunningExample()

try:
    """Modeling the set of goals using robotic patterns"""
    set_of_goals = {
        Node(
            name="day_patrol_12",
            description=
            "During context day => start from r1, patrol r1, r2 in strict order,\n"
            "Strict Ordered Patrolling Location r1, r2",
            context=w["day"],
            specification=StrictOrderedPatrolling([w["r1"], w["r2"]]),
            world=w),
        Node(
            name="night_patrol_34",
            description=
            "During context night => start from r3, patrol r3, r4 in strict order,\n"
            "Strict Ordered Patrolling Location r3, r4",
            context=w["night"],
            specification=StrictOrderedPatrolling([w["r3"], w["r4"]]),
            world=w),
        Node(name="greet_person",
             description="Always => if see a person, greet in the same step,\n"
             "Only if see a person, greet immediately",
             specification=BoundReaction(w["person"], w["greet"]),
Example #9
0
    def mutex_group(self) -> str:
        return "time"


"""We want to model a CGG that :
'always sleep during the night and always awake during the day"""

day = Day().to_atom()
night = Night().to_atom()

sleep_now = Init(Sleep())
awake_now = Init(Awake())
"""CASE 1"""
try:

    n1 = Node(name="awake_during_day",
              specification=Contract(assumptions=day, guarantees=awake_now))

    n2 = Node(name="sleep_during_night",
              specification=Contract(assumptions=night, guarantees=sleep_now))

    cgg = Node.conjunction({n1, n2})

    cgg.session_name = "case_1"

    cgg.translate_all_to_buchi()
    cgg.realize_specification_controllers()
    cgg.save()

    print(cgg)

    print(
Example #10
0
    pass

g1 = Goal(name="patrol_a_b_init_a_and_b",
          description="Patrolling of locations a and b and init a and b",
          specification=Patrolling([t["a"], t["b"]]) & Init(t["a"]))

try:
    g1.realize_to_controller()
except GoalException as e:
    raise e
"""Let's use nodes and build a CGG"""
"""Definition of a goals"""
try:

    n1 = Node(name="patrol_a_b_init_a_and_b",
              description="Patrolling of locations a and b and init a and b",
              specification=Patrolling([t["a"], t["b"]]) & Init(t["a"]))

    n2 = Node(name="patrol_c_d",
              description="Patrolling of locations c and d",
              specification=Patrolling([t["c"], t["d"]]))

    cgg = Node.composition({n1, n2})
    print(cgg)
    cgg.realize_specification_controllers(GraphTraversal.DFS)
    print(cgg)

    print(
        "The CGG is unrealizable because a-b, c-d are adjacent within each other but there is no way to go from a-b to c-d"
    )
    """Let us instantiate a different variables"""
Example #11
0
    @property
    def mutex_group(self) -> str:
        return "locations"


"""Infinitely Often Visit the Bed =  GF(bed) """
patrol_bed = Patrolling([Bed()])

"""Infinitely Often Visit the Office =  GF(office) """
patrol_office = Patrolling([Office()])

try:

    n1 = Node(name="awake_during_day",
              context=day,
              specification=Contract(guarantees=patrol_bed))

    n2 = Node(name="sleep_during_night",
              context=night,
              specification=Contract(guarantees=patrol_office))

    cgg = Node.conjunction({n1, n2})

    cgg.session_name = "case_3b_context"

    cgg.translate_all_to_buchi()
    cgg.realize_specification_controllers()
    cgg.save()

    print(cgg)