Example #1
0
def tick(blackboard):
    """
    This is the main entry point from C++ into our Python behaviours and back.

    More specifically it is the bridge from which C++ calls Python inside
    the runswift executable, and receives a BehaviourRequest back.

    Currently called in `robot/perception/behaviour/python/PythonSkill.cpp`,
    the `PythonSkill::execute()` C++ function, and explicitly the line
    `behaviour_tick(bb)`.

    :param blackboard: The runswift Blackboard, a bunch of things
        stored in global memory.
    :return: A `robot.BehaviourRequest()` instance, defined in C++ inside
        `robot/types/BehaviourRequest.hpp`.
    """
    # Update all blackboard dependent helper modules.
    Global.update(blackboard)
    TeamStatus.update(blackboard)
    FieldGeometry.update(blackboard)
    Timer.update(blackboard)
    LedOverride.reset()
    Sonar.update(blackboard)

    # Set the HeadSkill
    HeadSkill.singleton.resetRequestState()

    global skill_instance
    if not skill_instance:
        skill_instance = skill_instance_factory(blackboard)

    if isinstance(skill_instance, BehaviourTask):
        # On every tick of the perception thread, we update the blackboard,
        # tick the skill, and then return the resulting behaviour request.
        skill_instance.world.update(blackboard)
        skill_instance.world.b_request = robot.BehaviourRequest()
        skill_instance.world.b_request.actions = robot.All()
        skill_instance.tick()
        request = skill_instance.world.b_request
    else:
        # Backwards compat for old style skills if called directly via -s.
        request = skill_instance.tick(blackboard)

    headRequest = HeadSkill.singleton.tick(blackboard)
    request.actions.head = headRequest.actions.head

    # LED colouring.
    if len(blackboard.vision.uncertain_balls) > 0:
        request.actions.leds.rightEye = LEDColour.blue
    elif len(blackboard.vision.balls) > 0:
        request.actions.leds.rightEye = LEDColour.red
    else:
        request.actions.leds.rightEye = LEDColour.off

    if Global.amILost():
        request.actions.leds.leftEye = LEDColour.off
    else:
        request.actions.leds.leftEye = LEDColour.cyan

    return request
Example #2
0
def tick(blackboard):

    # Update all blackboard dependent helper modules.
    Global.update(blackboard)
    TeamStatus.update(blackboard)
    FieldGeometry.update(blackboard)
    Timer.update(blackboard)
    Sonar.update(blackboard)

    global skill_instance
    if not skill_instance:
        skill = blackboard.behaviour.skill
        # Load the module and the class we're going to use.
        found_skill = False
        SkillClass = None
        behaviour_packages = ["roles", "skills", "test"]
        for package in behaviour_packages:
            if skill not in [
                    name for _, name, _ in pkgutil.iter_modules(
                        ["/home/nao/data/behaviours/%s" % package])
            ]:
                Log.info("%s wasn't in %s, skipping import attempt.", skill,
                         package)
                continue
            try:
                skill_module = __import__("%s.%s" % (package, skill),
                                          fromlist=[skill])
                # Access the class so we can do some reflection.
                SkillClass = getattr(skill_module, skill)
                found_skill = True
                Log.info("Successfully imported %s from %s.%s", skill, package,
                         skill)
                break
            except ImportError, e:
                Log.error("%s %s", package, e)
                Log.error(traceback.format_exc())

        if not found_skill:
            raise ImportError(
                "Could not find skill: %s in any of our behaviour folders." %
                skill)

        if issubclass(SkillClass, BehaviourTask):
            new_world = world.World(blackboard)  # It's a whole new world.
            skill_instance = SkillClass(new_world)
        else:
            parentSkill = DummySkill(blackboard)
            skill_instance = SkillClass(blackboard, parentSkill)
def tick(blackboard):

   # Update all blackboard dependent helper modules.
   Global.update(blackboard)
   TeamStatus.update(blackboard)
   FieldGeometry.update(blackboard)
   Timer.update(blackboard)
   Sonar.update(blackboard)

   global skill_instance
   if not skill_instance:
      skill = blackboard.behaviour.skill
      # Load the module and the class we're going to use.
      found_skill = False
      SkillClass = None
      behaviour_packages = [ "roles", "skills", "test" ]
      for package in behaviour_packages:
         if skill not in [name for _, name, _ in pkgutil.iter_modules(["/home/nao/data/behaviours/%s" % package])]:
            Log.info("%s wasn't in %s, skipping import attempt.", skill, package)
            continue
         try:
            skill_module = __import__("%s.%s" % (package, skill), fromlist=[skill])
            # Access the class so we can do some reflection.
            SkillClass = getattr(skill_module, skill)
            found_skill = True
            Log.info("Successfully imported %s from %s.%s", skill, package, skill)
            break
         except ImportError, e:
            Log.error("%s %s", package, e)
            Log.error(traceback.format_exc())

      if not found_skill:
         raise ImportError("Could not find skill: %s in any of our behaviour folders." % skill)

      if issubclass(SkillClass, BehaviourTask):
         new_world = world.World(blackboard) # It's a whole new world.
         skill_instance = SkillClass(new_world)
      else:
         parentSkill = DummySkill(blackboard)
         skill_instance = SkillClass(blackboard, parentSkill)