Exemplo n.º 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
Exemplo n.º 2
0
    def tick(self, blackboard):
        self.numFramesTracked += 1

        # get ball into centre of frame
        self.lostBall = (blackboard.localisation.ballLostCount > 60)
        request = robot.BehaviourRequest()
        request.actions = robot.All()

        neckRelative = blackboard.localisation.ballNeckRelative
        self.targetPitch = self.calculateDesiredPitch(neckRelative)

        if len(blackboard.vision.balls) > 0:
            ball = blackboard.vision.balls[0]
            imgCoords = blackboard.vision.balls[0].imageCoords

            if blackboard.vision.balls[0].topCamera:
                CONSTANT_X = 1280.0 / 1.06290551
                xDiff = -(imgCoords[0] - 640) / CONSTANT_X
            else:
                CONSTANT_X = 640.0 / 1.06290551
                xDiff = -(imgCoords[0] - 640 / 2) / CONSTANT_X

            self.targetYaw = xDiff

        if blackboard.localisation.ballLostCount < 3:
            factor = abs(self.targetYaw) / 1.06290551

            speed = 0.75 * factor  # 10.0 * factor * factor
            request.actions.head = actioncommand.head(self.targetYaw,
                                                      self.targetPitch, True,
                                                      speed, 0.2)

        else:
            self.ballYaw = self.calculateDesiredYaw(neckRelative)
            self.targetYaw = self.ballYaw
            request.actions.head = actioncommand.head(self.targetYaw,
                                                      self.targetPitch, False,
                                                      0.25, 0.2)

        return request
Exemplo n.º 3
0
def EmptyBehaviourRequest():
   b = robot.BehaviourRequest()
   b.actions = robot.All()
   return b
Exemplo n.º 4
0
def compose(head=head(), body=walk(), leds=leds()):
    return robot.All(head, body, leds, 0.0)
Exemplo n.º 5
0
                "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)

    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 = skills.HeadSkill.instance.tick(blackboard)
    request.actions.head = headRequest.actions.head

    # Eye LED setting.
    if len(blackboard.vision.balls) > 0:
        # Right Eye Red if you can see a ball.
        request.actions.leds.rightEye = LEDColour.red
    else:
        request.actions.leds.rightEye = LEDColour.off
Exemplo n.º 6
0
def compose(head=head(), body=walk(), leds=leds()):
    return robot.All(head, body, leds, 0.0, robot.StiffenCommand.NONE)