<commit_before>import skills._kick
import behavior
import constants
import robocup
import enum
import main
import role_assignment


# lines up with the ball and the target, then drives up and kicks
# this differs from PivotKick which gets the ball first, then aims
# Note: LineKick recalculates the target_aim_point ONLY when the target point/segment changes
class LineKick(skills._kick._Kick):

    # tuneable constants
    DriveAroundDist = 0.15
    ChargeThresh = 0.1
    EscapeChargeThresh = 0.1
    SetupBallAvoid = 0.15
    AccelBias = 0.2
    FacingThresh = 10   # angle in degrees
    MaxChargeSpeed = 1.5
    BallProjectTime = 0.4
    DoneStateThresh = 0.11
    WrongSideOfBallThresh = 0.1
    ClosenessThreshold = constants.Robot.Radius + 0.04

    class State(enum.Enum):
        setup = 1
        charge = 2


    def __init__(self):
        super().__init__()

        self._got_close = False

        for state in LineKick.State:
            self.add_state(state, behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
            LineKick.State.setup,
            lambda: True,
            'immediately')

        self.add_transition(LineKick.State.setup,
            LineKick.State.charge,
            lambda: ( not self.robot_is_between_ball_and_target() ) and self._target_line.dist_to(self.robot.pos) < self.ChargeThresh and not self.robot.just_kicked(),
            "robot on line")

        self.add_transition(LineKick.State.charge,
            behavior.Behavior.State.completed,
            lambda: self.robot is not None and self._got_close and self.robot.just_kicked(),
            "robot kicked")

        self.add_transition(LineKick.State.charge,
            LineKick.State.setup,
            self.robot_is_between_ball_and_target,
            "robot between ball and target")

    def robot_is_between_ball_and_target(self):
        return self.robot is not None and \
            robocup.Segment(main.ball().pos, self.aim_target_point).dist_to(self.robot.pos) < self.WrongSideOfBallThresh

    def recalculate(self):
        self._target_line = robocup.Line(main.ball().pos, self.aim_target_point)
        # FIXME: errors?

    def on_exit_start(self):
        super().recalculate_aim_target_point()


    def execute_running(self):
        self.recalculate()
        super().execute_running()<commit_msg>Fixes LineKick transition from charge to setup.<commit_after>import skills._kick
import behavior
import constants
import robocup
import enum
import main
import role_assignment


# lines up with the ball and the target, then drives up and kicks
# this differs from PivotKick which gets the ball first, then aims
# Note: LineKick recalculates the target_aim_point ONLY when the target point/segment changes
class LineKick(skills._kick._Kick):

    # tuneable constants
    DriveAroundDist = 0.15
    ChargeThresh = 0.1
    EscapeChargeThresh = 0.1
    SetupBallAvoid = 0.15
    AccelBias = 0.2
    FacingThresh = 10   # angle in degrees
    MaxChargeSpeed = 1.5
    BallProjectTime = 0.4
    DoneStateThresh = 0.11
    ClosenessThreshold = constants.Robot.Radius + 0.04

    class State(enum.Enum):
        setup = 1
        charge = 2


    def __init__(self):
        super().__init__()

        self._got_close = False

        for state in LineKick.State:
            self.add_state(state, behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
            LineKick.State.setup,
            lambda: True,
            'immediately')

        self.add_transition(LineKick.State.setup,
            LineKick.State.charge,
            lambda: ( not self.robot_is_between_ball_and_target() ) and self._target_line.dist_to(self.robot.pos) < self.ChargeThresh and not self.robot.just_kicked(),
            "robot on line")

        self.add_transition(LineKick.State.charge,
            behavior.Behavior.State.completed,
            lambda: self.robot is not None and self._got_close and self.robot.just_kicked(),
            "robot kicked")

        self.add_transition(LineKick.State.charge,
            LineKick.State.setup,
            lambda: self.robot_is_between_ball_and_target() or self._target_line.dist_to(self.robot.pos) > self.ChargeThresh,
            "robot between ball and target")

    def robot_is_between_ball_and_target(self):
        return self.robot is not None and \
            self.robot.pos.dist_to(self.aim_target_point) < main.ball().pos.dist_to(self.aim_target_point)

    def recalculate(self):
        self._target_line = robocup.Line(main.ball().pos, self.aim_target_point)
        # FIXME: errors?

    def on_exit_start(self):
        super().recalculate_aim_target_point()


    def execute_running(self):
        self.recalculate()
        super().execute_running()
{'fraction_non_alphanumeric': 0.08546475358702432, 'fraction_numerical': 0.011228945726762321, 'mean_word_length': 2.7142857142857144, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869888', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1461, 'n_words': 328}