Example #1
0
def test():
    print "in test"
    mutex.acquire()
    desiredPoint = param.AWAY_GOAL

    while (team1_robot_state.pos_x_est > (desiredPoint.x + 0.4)) or \
            (team1_robot_state.pos_y_est > (desiredPoint.y + 0.3) or team1_robot_state.pos_y_est < (desiredPoint.y - 0.3)):

        starting_point = str(int(param.meterToPixel(team1_robot_state.pos_x_est))) + ',' + str(int(param.meterToPixel(team1_robot_state.pos_y_est)))
        end_point = str(int(param.meterToPixel(param.AWAY_GOAL.x))) + ',' + str(int(param.meterToPixel(param.AWAY_GOAL.y)))

        print starting_point
        print end_point
        # visited, shortest = path.shortest_path(graph, '-10,0' , '0,0')
        #
        # print shortest
        # point = shortest[10]
        # x,y = point.split(',')
        # next_point = Point.Point(x, y)
        #
        # command = MotionSkills.go_to_point(team1_robot_state, next_point)
        #
        # velchange.goXYOmega(command.vel_x, command.vel_y, team1_robot_state.pos_theta_est)
        # time.sleep(robot_update_delay)

        # desiredPoint = Point.Point(param.pixelToMeter(0), param.pixelToMeter(0))
        # go_to_point2(desiredPoint.x, desiredPoint.y, param.HOME_GOAL)
        # time.sleep(0.01)

    velchange.goXYOmega(0,0,0)
Example #2
0
def obstruction(start, end, team2_robot_state):
    team2_x = param.meterToPixel(team2_robot_state.pos_x_est)
    team2_y = param.meterToPixel(team2_robot_state.pos_y_est)

    ray = br.bresenham([param.meterToPixel(start.x), param.meterToPixel(start.y)], [param.meterToPixel(end.x), param.meterToPixel(end.y)])

    for point in ray.path:
        print point[0], "," , point[1]
        if point[0] < (team2_x + 30) and point[0] > (team2_x - 30) and \
           point[1] < (team2_y + 30) and point[1] > (team2_y - 30):
           return True

    return False
Example #3
0
def test():
    print "in test"
    mutex.acquire()

    start = Point.Point(team1_robot_state.pos_x_est, team1_robot_state.pos_y_est)
    end = Point.Point(-350, 0)


    print "Start:", param.meterToPixel(start.x) , ", " , param.meterToPixel(start.y)
    print "End:", int(end.x) , ", " , int(end.y)

    obstruction = ray.obstruction(start,end,team2_robot_state)

    if obstruction == True:
        print "obstruction"
    else:
        print "clear line of sight"
Example #4
0
def one_on_one():
    mutex.acquire()

    state = "idle"
    start = default_timer()
    ball_prev_x = ball.x
    ball_prev_y = ball.y

    while True:
        if goal_scored() and state != "idle":
            print "goal scored", param.meterToPixel(ball.x)
            state = "reset"

        # If there's input ready, do something, else do something
        # else. Note timeout is zero so select won't block at all.
        while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            command = sys.stdin.readline().strip().lower()
            if command == "r":
                state = "reset"
            elif command == "s":
                state = "defend"
            elif command == "k":
                velchange.goXYOmega(0,0,0)
                state = "idle"

        if state == "idle":
            print "state: idle"
            pass

        elif state == "defend":
            print "state: defend"
            if ball.x < 0:
                # transition
                state = "score"
            else:
                # save state
                ball_prev_x = ball.x
                ball_prev_y = ball.y

                # restart timer
                start = default_timer()

                # transition
                state = "defend_goal"

        elif state == "defend_goal":
            print "state: defend_goal"

            if ball.x < 0:
                # transition
                state = "score"
                continue

            if abs(ball.x - ball_prev_x) < 0.02 and abs(ball.y - ball_prev_y) < 0.02:
                if default_timer() - start > 0.5:
                    # transition
                    state = "score"
                else:
                    defend_goal()
            else:
                start = default_timer()
                ball_prev_x = ball.x
                ball_prev_y = ball.y
                defend_goal()

        elif state == "score":
            print "state: score"

            go_to_point_behind_ball()
            rush_goal()

            state = "defend"

        elif state == "reset":
            print "state: reset"

            go_prepare_spin()

            state = "idle"