def tick(self, blackboard):
     body = actioncommand.standStraight()
     head = actioncommand.head(0, 0, False, 1, 1)
     leds = actioncommand.leds()
     req = robot.BehaviourRequest()
     req.actions = actioncommand.compose(head, body, leds)
     return req
Exemple #2
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
    def update(self, blackboard):
        """Update.

      Updates the current blackboard reference.
      """

        self.blackboard = blackboard
        # New behaviour request.
        self.b_request = robot.BehaviourRequest()
Exemple #4
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
Exemple #5
0
def EmptyBehaviourRequest():
   b = robot.BehaviourRequest()
   b.actions = robot.All()
   return b
Exemple #6
0
            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)

    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: