Esempio n. 1
0
    def __init__(self, tbrain=None):
        self.playerNumber = 0

        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        self.locUncert = 0
        # TODO use location objects
        self.walkingToX = 0
        self.walkingToY = 0
        self.ballOn = False
        self.ballAge = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballVelX = 0
        self.ballVelY = 0
        self.ballUncert = 0
        self.role = 0
        self.inKickingState = False
        self.kickingToX = 0
        self.kickingToY = 0
        self.fallen = False
        self.active = True
        self.claimedBall = False

        self.frameSinceActive = 0
        self.lastTimestamp = 0
        self.framesWithoutPacket = -1

        self.brain = tbrain # brain instance
Esempio n. 2
0
    def __init__(self, tbrain=None):
        self.playerNumber = 0

        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        self.locUncert = 0
        # TODO use location objects
        self.walkingToX = 0
        self.walkingToY = 0
        self.ballOn = False
        self.ballAge = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballVelX = 0
        self.ballVelY = 0
        self.ballUncert = 0
        self.role = 0
        self.inKickingState = False
        self.kickingToX = 0
        self.kickingToY = 0
        self.fallen = False
        self.active = True
        self.alive = True
        self.claimedBall = False

        self.frameSinceActive = 0
        self.lastTimestamp = 0
        self.framesWithoutPacket = -1

        self.brain = tbrain  # brain instance
Esempio n. 3
0
def gamePlaying(player):
    if player.firstFrame():

        loc = player.brain.loc
        my_current_loc = player.brain.my
        my_current_odo = RobotLocation(loc.lastOdoX, loc.lastOdoY,
                                       loc.lastOdoTheta)

        #        delta_loc = my_current_loc - player.my_last_loc
        #        delta_odo = my_current_odo - player.my_last_odo

        if (player.testCounter > 0):
            player.printf("Odometry: {0}".format(my_current_odo -
                                                 player.my_last_odo))
            player.printf("Delta Odo {0}".format(
                NavStates.walkingTo.deltaDest))

        player.my_last_loc = RobotLocation(my_current_loc.x, my_current_loc.y,
                                           my_current_loc.h)
        player.my_last_odo = my_current_odo

        if player.testCounter >= len(player.benchmark):
            print "Done!"
            return player.goLater("gamePenalized")

        command = player.benchmark[player.testCounter]
        player.testCounter += 1
        player.numTestFrames = command[1]
        walkVector = command[0]
        player.brain.nav.walkTo(RelRobotLocation(*walkVector))

    if player.counter == player.numTestFrames:
        return player.goNow('nextCommand')

    return player.stay()
Esempio n. 4
0
def gameSet(player):
    if player.firstFrame():
        player.testCounter = 0
        player.benchmark = FRONT_SIDE_SPIN

        my = player.brain.my
        player.my_last_loc = RobotLocation(my.x, my.y, my.h)
        player.my_last_odo = RobotLocation(0, 0, 0)
    return player.stay()
Esempio n. 5
0
 def __init__(self,
              strategy=INIT_STRATEGY,
              formation=INIT_FORMATION,
              role=INIT_ROLE,
              subRole=INIT_SUB_ROLE,
              position=RobotLocation(0, 0, 0)):
     self.strategy = strategy
     self.formation = formation
     self.role = role
     self.subRole = subRole
     self.position = RobotLocation(0, 0, 0)
     self.changed = True
Esempio n. 6
0
def findStrikerHome(ball, hh):
    if not hasattr(findStrikerHome, 'upperHalf'):
        findStrikerHome.upperHalf = (ball.y -
                                     NogginConstants.CENTER_FIELD_Y) >= 0

    # the buffer zone is twice this because its this distance on each side of midfield
    # the buffer keeps us from oscillating sides of the field when the ball is near the center line
    oscBuff = 50
    if findStrikerHome.upperHalf and (
            ball.y - NogginConstants.CENTER_FIELD_Y) < -1 * oscBuff:
        findStrikerHome.upperHalf = False
    elif not findStrikerHome.upperHalf and (
            ball.y - NogginConstants.CENTER_FIELD_Y) > oscBuff:
        findStrikerHome.upperHalf = True

    goalCenter = Location(NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X,
                          NogginConstants.MIDFIELD_Y)
    ballToGoal = Location(goalCenter.x - ball.x,
                          goalCenter.y - ball.y)  # vector

    # avoid divide by zeros
    if ballToGoal == Location(0, 0):
        ballToGoal = Location(1, 0)

    # the point at which we draw our normal vector from
    percentageToPivot = 0.8
    pivotPoint = Location(ball.x + ballToGoal.x * 0.7,
                          ball.y + ballToGoal.y * 0.7)

    # two possible normal vectors. If ball.y is greater than midfield.y choose (dy, -dx)
    # else choose (-dy, dx)
    if findStrikerHome.upperHalf:
        normalVect = Location(ballToGoal.y, -1 * ballToGoal.x)
    else:
        normalVect = Location(-1 * ballToGoal.y, ballToGoal.x)

    # normalize the vector and make its magnitude to the desired value
    normalVectLength = 100
    normalizeMag = normalVectLength / normalVect.distTo(Location(0, 0))
    normalVect.x *= normalizeMag
    normalVect.y *= normalizeMag

    strikerHome = RobotLocation(pivotPoint.x + normalVect.x,
                                pivotPoint.y + normalVect.y, hh)

    # if for some reason you get placed off the field project back onto the field
    if strikerHome.x > NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20:
        strikerHome.x = NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20

    return strikerHome
Esempio n. 7
0
def findDefenderHome(left, ball, hh):
    bY = ball.y
    if ball.x < NogginConstants.MIDFIELD_X:
        if left:
            home = closePointOnSeg(role.evenDefenderBack.x,
                                   role.evenDefenderBack.y,
                                   role.evenDefenderForward.x,
                                   role.evenDefenderForward.y, ball.x, ball.y)
            return RobotLocation(home[0], home[1], hh)
        else:
            home = closePointOnSeg(role.oddDefenderBack.x,
                                   role.oddDefenderBack.y,
                                   role.oddDefenderForward.x,
                                   role.oddDefenderForward.y, ball.x, ball.y)
            return RobotLocation(home[0], home[1], hh)

    else:
        if left:
            if bY >= role.evenDefenderForward.y:
                return RobotLocation(role.evenDefenderForward.x,
                                     role.evenDefenderForward.y, hh)
            elif bY <= role.oddDefenderBack.y:
                return RobotLocation(role.evenDefenderBack.x,
                                     role.evenDefenderBack.y, hh)
            else:
                # ball is between the two defenders:
                # linear relationship between ball and where defender stands on their line

                xDist = role.evenDefenderForward.x - role.evenDefenderBack.x
                yDist = role.evenDefenderForward.y - role.evenDefenderBack.y

                t = ((bY - role.oddDefenderForward.y) /
                     (role.evenDefenderForward.y - role.oddDefenderForward.y))

                hx = role.evenDefenderBack.x + t * xDist
                hy = role.evenDefenderBack.y + t * yDist

                return RobotLocation(hx, hy, hh)
        else:
            if bY <= role.oddDefenderForward.y:
                return RobotLocation(role.oddDefenderForward.x,
                                     role.oddDefenderForward.y, hh)
            elif bY >= role.evenDefenderBack.y:
                return RobotLocation(role.oddDefenderBack.x,
                                     role.oddDefenderBack.y, hh)
            else:
                # ball is between the two defenders:
                # linear relationship between ball and where defender stands on their line

                xDist = role.oddDefenderForward.x - role.oddDefenderBack.x
                yDist = role.oddDefenderForward.y - role.oddDefenderBack.y

                t = ((bY - role.evenDefenderForward.y) /
                     (role.oddDefenderForward.y - role.evenDefenderForward.y))

                hx = role.oddDefenderBack.x + t * xDist
                hy = role.oddDefenderBack.y + t * yDist

                return RobotLocation(hx, hy, hh)
Esempio n. 8
0
    def __init__(self, tbrain=None):
        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        self.playerNumber = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballOn = False
        self.role = None
        self.subRole = None
        self.chaseTime = 0

        #other info we want stored
        self.brain = tbrain  # brain instance
        self.active = True
        self.grabbing = False
        self.dribbling = False
Esempio n. 9
0
    def __init__(self, tbrain=None):
        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        self.playerNumber = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballOn = False
        self.role = None
        self.subRole = None
        self.chaseTime = 0

        #other info we want stored
        self.brain = tbrain # brain instance
        self.active = True
        self.grabbing = False
        self.dribbling = False
Esempio n. 10
0
 def updateLoc(self):
     """
     Make Loc info a RobotLocation.
     """
     self.loc = RobotLocation(self.interface.loc.x,
                              self.interface.loc.y,
                              self.interface.loc.h)
Esempio n. 11
0
def positionAtHome(player):
    """
    Go to the player's home position. Defenders look in the direction of the 
    shared ball if it is on with reliability >= 2. Cherry pickers look in the direction
    of the shared ball if it is on with reliability >= 1.
    """
    home = RobotLocation(player.homePosition.x, player.homePosition.y, player.homePosition.h)
    # if (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 2 and 
    #     role.isDefender(player.role)):
    #     sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
    #     home.h = player.brain.loc.getRelativeBearing(sharedball)
    # elif (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 1 and 
    #       role.isCherryPicker(player.role)):
    #     sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
    #     home.h = player.brain.loc.getRelativeBearing(sharedball)

    if player.firstFrame():
        if role.isCherryPicker(player.role):
            player.brain.tracker.repeatWidePan()
        else:
            player.brain.tracker.trackBall()
        fastWalk = role.isCherryPicker(player.role)
        player.brain.nav.goTo(home, precision = nav.HOME,
                              speed = nav.QUICK_SPEED, avoidObstacles = True,
                              fast = fastWalk, pb = False)

    player.brain.nav.updateDest(home)
Esempio n. 12
0
    def __init__(self, tbrain=None):
        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        self.playerNumber = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballOn = False
        self.role = None
        self.chaseTime = 0
        self.defenderTime = 0
        self.offenderTime = 0
        self.middieTime = 0
        self.inKickingState = False

        #other info we want stored
        self.brain = tbrain # brain instance
        self.active = True
Esempio n. 13
0
    def __init__(self, tbrain=None):
        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        self.playerNumber = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballOn = False
        self.role = None
        self.chaseTime = 0
        self.defenderTime = 0
        self.offenderTime = 0
        self.middieTime = 0
        self.inKickingState = False

        #other info we want stored
        self.brain = tbrain  # brain instance
        self.active = True
Esempio n. 14
0
 def updateLoc(self):
     """
     Make Loc info a RobotLocation.
     """
     self.loc = RobotLocation(self.interface.loc.x, self.interface.loc.y,
                              self.interface.loc.h * (180. / math.pi))
     self.locUncert = self.interface.loc.uncert
Esempio n. 15
0
def findStrikerHome(ball, hh):
    if not hasattr(findStrikerHome, 'upperHalf'):
        findStrikerHome.upperHalf = (ball.y - NogginConstants.CENTER_FIELD_Y) >= 0 

    # the buffer zone is twice this because its this distance on each side of midfield
    # the buffer keeps us from oscillating sides of the field when the ball is near the center line
    oscBuff = 50
    if findStrikerHome.upperHalf and (ball.y - NogginConstants.CENTER_FIELD_Y) < -1*oscBuff:
        findStrikerHome.upperHalf = False
    elif not findStrikerHome.upperHalf and (ball.y - NogginConstants.CENTER_FIELD_Y) > oscBuff:
        findStrikerHome.upperHalf = True

    goalCenter = Location(NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X, NogginConstants.MIDFIELD_Y)
    ballToGoal = Location(goalCenter.x - ball.x, goalCenter.y - ball.y) # vector

    # avoid divide by zeros
    if ballToGoal == Location(0, 0):
        ballToGoal = Location (1, 0)

    # the point at which we draw our normal vector from
    percentageToPivot = 0.8
    pivotPoint = Location(ball.x + ballToGoal.x*0.7, ball.y + ballToGoal.y*0.7)

    # two possible normal vectors. If ball.y is greater than midfield.y choose (dy, -dx)
    # else choose (-dy, dx)
    if findStrikerHome.upperHalf:
        normalVect = Location(ballToGoal.y, -1*ballToGoal.x)
    else:
        normalVect = Location(-1*ballToGoal.y, ballToGoal.x)

    # normalize the vector and make its magnitude to the desired value
    normalVectLength = 100
    normalizeMag = normalVectLength/normalVect.distTo(Location(0,0))
    normalVect.x *= normalizeMag
    normalVect.y *= normalizeMag

    strikerHome = RobotLocation(pivotPoint.x + normalVect.x , pivotPoint.y + normalVect.y, hh)

    # if for some reason you get placed off the field project back onto the field
    if strikerHome.x > NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20:
        strikerHome.x = NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20

    return strikerHome
Esempio n. 16
0
def rightDefender(player):
    """
    Defenders position between ball and goal.
    """
    # if player.brain.ball.y >=  NogginConstants.MIDFIELD_Y:
    return RobotLocation(
        (player.brain.ball.x + NogginConstants.BLUE_GOALBOX_RIGHT_X) * .5,
        (player.brain.ball.y + (NogginConstants.GOALBOX_WIDTH * .25 +
                                NogginConstants.BLUE_GOALBOX_BOTTOM_Y)) * .5,
        player.brain.ball.bearing_deg + player.brain.loc.h)
Esempio n. 17
0
    def __init__(self, tbrain=None):
        '''variables include lots from the Packet class'''
        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        # things in the Packet()
        self.playerNumber = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballX = 0
        self.ballY = 0
        self.role = None
        self.subRole = None
        self.chaseTime = 0
        self.lastPacketTime = time.time()

        #other info we want stored
        self.brain = tbrain # brain instance
        self.active = True
        self.grabbing = False
        self.dribbling = False
Esempio n. 18
0
    def __init__(self, tbrain=None):
        '''variables include lots from the Packet class'''
        RobotLocation.__init__(self, 0.0, 0.0, 0.0)
        # things in the Packet()
        self.playerNumber = 0
        self.ballDist = 0
        self.ballBearing = 0
        self.ballX = 0
        self.ballY = 0
        self.ballOn = False
        self.role = None
        self.subRole = None
        self.chaseTime = 0
        self.lastPacketTime = time.time()

        #other info we want stored
        self.brain = tbrain  # brain instance
        self.active = True
        self.grabbing = False
        self.dribbling = False
Esempio n. 19
0
def walkToGoal(player):
    """
    Has the goalie walk in the general direction of the goal.
    """
    if player.firstFrame():
        player.brain.tracker.repeatBasicPan()
        player.returningFromPenalty = False
        player.brain.nav.goTo(RobotLocation(FIELD_WHITE_LEFT_SIDELINE_X,
                                       CENTER_FIELD_Y, 0.0))

    return Transition.getNextState(player, walkToGoal)
Esempio n. 20
0
def positionAtHome(player):
    """
    Go to the player's home position. Defenders look in the direction of the 
    shared ball if it is on with reliability >= 2. Cherry pickers look in the direction
    of the shared ball if it is on with reliability >= 1.
    """
    if player.firstFrame():
        player.brain.tracker.trackBall()

        home = RobotLocation(player.homePosition.x, player.homePosition.y, player.homePosition.h)
        if (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 2 and 
            role.isDefender(player.role)):
            sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
            home.h = player.brain.loc.getRelativeBearing(sharedball)
        elif (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 1 and 
              role.isCherryPicker(player.role)):
            sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
            home.h = player.brain.loc.getRelativeBearing(sharedball)

        fastWalk = role.isCherryPicker(player.role)
        player.brain.nav.goTo(home, precision = nav.HOME,
                              speed = nav.QUICK_SPEED, avoidObstacles = True,
                              fast = fastWalk, pb = False)

    home = RobotLocation(player.homePosition.x, player.homePosition.y, player.homePosition.h)
    if (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 2 and 
        role.isDefender(player.role)):
        sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
        home.h = player.brain.loc.getRelativeBearing(sharedball)
    elif (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 1 and 
          role.isCherryPicker(player.role)):
        sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
        home.h = player.brain.loc.getRelativeBearing(sharedball)

    player.brain.nav.updateDest(home)
Esempio n. 21
0
def walkToWayPoint(player):
    if player.brain.nav.dodging:
        return player.stay()

    if player.firstFrame():
        player.decider = KickDecider.KickDecider(player.brain)
        player.brain.tracker.trackBall()

    player.kick = player.decider.new2016KickStrategy()
    relH = player.decider.normalizeAngle(player.kick.setupH -
                                         player.brain.loc.h)

    ball = player.brain.ball

    # print "In walkToWayPoint"

    if transitions.shouldDecelerate(player):
        # print "I should decelerate"
        speed = speeds.SPEED_SIX
    else:
        speed = speeds.SPEED_EIGHT

    if fabs(relH) <= 50:  #constants.MAX_BEARING_DIFF:
        wayPoint = RobotLocation(
            ball.x -
            constants.WAYPOINT_DIST * cos(radians(player.kick.setupH)),
            ball.y -
            constants.WAYPOINT_DIST * sin(radians(player.kick.setupH)),
            player.brain.loc.h)

        # print("Going to waypoint")
        player.brain.nav.goTo(wayPoint,
                              Navigator.GENERAL_AREA,
                              speed,
                              True,
                              fast=True)

        if transitions.shouldSpinToKickHeading(player):
            return player.goNow('spinToKickHeading')

    else:
        player.brain.nav.chaseBall(speed, fast=True)

        if transitions.shouldPrepareForKick(player):
            return player.goLater('dribble')

    return player.stay()
Esempio n. 22
0
def walkToWayPoint(player):
    if player.brain.nav.dodging:
        return player.stay()

    if player.firstFrame():
        player.decider = KickDecider.KickDecider(player.brain)
        player.brain.tracker.trackBall()

    player.kick = player.decider.decidingStrategy()
    relH = player.decider.normalizeAngle(player.kick.setupH -
                                         player.brain.loc.h)

    ball = player.brain.ball

    if transitions.shouldDecelerate(player):
        speed = MIN_SPEED
    else:
        speed = MAX_SPEED

    if fabs(relH) <= constants.MAX_BEARING_DIFF:
        wayPoint = RobotLocation(
            ball.x -
            constants.WAYPOINT_DIST * cos(radians(player.kick.setupH)),
            ball.y -
            constants.WAYPOINT_DIST * sin(radians(player.kick.setupH)),
            player.brain.loc.h)

        player.brain.nav.goTo(wayPoint,
                              Navigator.CLOSE_ENOUGH,
                              speed,
                              True,
                              fast=True)

        if transitions.shouldSpinToKickHeading(player):
            return player.goNow('spinToKickHeading')

    else:
        player.brain.nav.chaseBall(speed, fast=True)

        if transitions.shouldPrepareForKick(player):
            return player.goLater('positionAndKickBall')

    return player.stay()
Esempio n. 23
0
def getRelativeDestination(my, dest):

    field_dest = dest

    if isinstance(field_dest, RelRobotLocation):
        return field_dest

    elif isinstance(field_dest, RelLocation):
        return RelRobotLocation(field_dest.relX, field_dest.relY,
                                field_dest.bearing)

    elif isinstance(field_dest, RobotLocation):
        return my.relativeRobotLocationOf(field_dest)

    elif isinstance(field_dest, Location):
        field_dest = RobotLocation(field_dest.x, field_dest.y, 0)
        relLocation = my.relativeRobotLocationOf(field_dest)
        relLocation.relH = my.getRelativeBearing(field_dest)
        return relLocation
    else:
        raise TypeError, "Navigator dest is not a Location type!" + str(dest)
Esempio n. 24
0
def chaser(player):
    """
    Chasers position off to one side of the ball about a meter away if a chaser
    or cherry picker is calling them off. Chasers position further away up field if
    a defender is calling them off.
    """
    if role.isStriker(player.roleOfClaimer):
        return striker(player)

    if role.isDefender(player.roleOfClaimer):
        if player.brain.ball.y >= player.brain.loc.y:
            return RobotLocation(
                player.brain.ball.x + 250,
                player.brain.ball.y - CHASER_DISTANCE,
                player.brain.ball.bearing_deg + player.brain.loc.h)
        return RobotLocation(
            player.brain.ball.x + 250, player.brain.ball.y + CHASER_DISTANCE,
            player.brain.ball.bearing_deg + player.brain.loc.h)
    else:
        southEast = RobotLocation(
            player.brain.ball.x - CHASER_DISTANCE,
            player.brain.ball.y - CHASER_DISTANCE,
            player.brain.ball.bearing_deg + player.brain.loc.h)
        southWest = RobotLocation(
            player.brain.ball.x - CHASER_DISTANCE,
            player.brain.ball.y + CHASER_DISTANCE,
            player.brain.ball.bearing_deg + player.brain.loc.h)
        northEast = RobotLocation(
            player.brain.ball.x + CHASER_DISTANCE,
            player.brain.ball.y - CHASER_DISTANCE,
            player.brain.ball.bearing_deg + player.brain.loc.h)
        northWest = RobotLocation(
            player.brain.ball.x + CHASER_DISTANCE,
            player.brain.ball.y + CHASER_DISTANCE,
            player.brain.ball.bearing_deg + player.brain.loc.h)

        supportPostitions = [southEast, southWest, northEast, northWest]
        positionsFilteredByInBounds = [
            position for position in supportPostitions
            if (inBounds(position) and notBlockingGoal(position))
        ]
        if len(positionsFilteredByInBounds) > 0:
            return min(positionsFilteredByInBounds,
                       key=distanceToPosition(player))

        # print "no in bounds position"
        return southEast
Esempio n. 25
0
def getRelativeDestination(my, dest):
    """
    Takes in a dest that can be of various types and
    then returns a relative robot location to get to that location.

    If it's an absolute location, the it uses the robot location to compute
    the relative location of the point.

    If dest doesn't have a heading (Location, RelLocation), then it will
    use the bearing to the point.
    """
    field_dest = dest

    if isinstance(field_dest, RelRobotLocation):
        return field_dest

    elif isinstance(field_dest, RelLocation):
        return RelRobotLocation(field_dest.relX,
                                field_dest.relY,
                                field_dest.bearing)

    elif isinstance(field_dest, RobotLocation):
        return my.relativeRobotLocationOf(field_dest)

    elif isinstance(field_dest, Location):
        field_dest = RobotLocation(field_dest.x, field_dest.y, 0)
        relLocation = my.relativeRobotLocationOf(field_dest)
        relLocation.relH = my.getRelativeBearing(field_dest)
        return relLocation

    elif (hasattr(field_dest, 'rel_x') and
          hasattr(field_dest, 'rel_y') and
          hasattr(field_dest, 'bearing_deg')):
        return RelRobotLocation(field_dest.rel_x,
                                field_dest.rel_y,
                                field_dest.bearing_deg)

    else:
        raise TypeError, "Navigator dest is not a Location type!" + str(dest)
Esempio n. 26
0
def goToPosition(nav):
    """
    Go to a position set in the navigator. General go to state.  Goes
    towards a location on the field stored in dest.
    The location can be a RobotLocation, Location, RelRobotLocation, RelLocation
    Absolute locations get transformed to relative locations based on current loc
    For relative locations we use our bearing to that point as the heading
    """
    relDest = helper.getRelativeDestination(nav.brain.loc, goToPosition.dest)

    #if nav.counter % 10 is 0:
    #    print "going to " + str(relDest)
    #    print "ball is at {0}, {1}, {2} ".format(nav.brain.ball.loc.relX,
    #                                             nav.brain.ball.loc.relY,
    #                                             nav.brain.ball.loc.bearing)

    if goToPosition.pb:
        # Calc dist to dest
        dist = helper.getDistToDest(nav.brain.loc, goToPosition.dest)
        if goToPosition.fast and dist < 140:
            goToPosition.fast = False
            goToPosition.dest = nav.brain.play.getPosition()
        elif not goToPosition.fast and dist > 160:
            goToPosition.fast = True
            goToPosition.dest = nav.brain.play.getPositionCoord()

    if goToPosition.fast:
        # So that fast mode works for objects of type RobotLocation also
        if isinstance(goToPosition.dest,
                      RobotLocation) and not goToPosition.close:
            fieldDest = RobotLocation(goToPosition.dest.x, goToPosition.dest.y,
                                      0)
            relDest = nav.brain.loc.relativeRobotLocationOf(fieldDest)
            relDest.relH = nav.brain.loc.getRelativeBearing(fieldDest)

        HEADING_ADAPT_CUTOFF = 103
        DISTANCE_ADAPT_CUTOFF = 10

        MAX_TURN = .5

        BOOK_IT_TURN_THRESHOLD = 23
        BOOK_IT_DISTANCE_THRESHOLD = 50

        if relDest.relH >= HEADING_ADAPT_CUTOFF:
            velH = MAX_TURN
        elif relDest.relH <= -HEADING_ADAPT_CUTOFF:
            velH = -MAX_TURN
        else:
            velH = helper.adaptSpeed(relDest.relH, HEADING_ADAPT_CUTOFF,
                                     MAX_TURN)

        if relDest.relX >= DISTANCE_ADAPT_CUTOFF:
            velX = goToPosition.speed
        elif relDest.relX <= -DISTANCE_ADAPT_CUTOFF:
            velX = -goToPosition.speed
        else:
            velX = helper.adaptSpeed(relDest.relX, DISTANCE_ADAPT_CUTOFF,
                                     goToPosition.speed)

        if relDest.relY >= DISTANCE_ADAPT_CUTOFF:
            velY = goToPosition.speed
        elif relDest.relY <= -DISTANCE_ADAPT_CUTOFF:
            velY = -goToPosition.speed
        else:
            velY = helper.adaptSpeed(relDest.relY, DISTANCE_ADAPT_CUTOFF,
                                     goToPosition.speed)

        if fabs(relDest.dist) > BOOK_IT_DISTANCE_THRESHOLD:
            goToPosition.close = False
            if fabs(relDest.relH) > BOOK_IT_TURN_THRESHOLD:
                if relDest.relH > 0: velH = MAX_TURN
                if relDest.relH < 0: velH = -MAX_TURN
                velX = 0
                velY = 0
                goToPosition.bookingIt = False
            else:
                velY = 0
                goToPosition.bookingIt = True
        else:
            goToPosition.close = True

        goToPosition.speeds = (velX, velY, velH)
        helper.setSpeed(nav, goToPosition.speeds)

    else:
        if goToPosition.adaptive:
            #reduce the speed if we're close to the target
            speed = helper.adaptSpeed(relDest.dist, constants.ADAPT_DISTANCE,
                                      goToPosition.speed)
        else:
            speed = goToPosition.speed

        helper.setDestination(nav, relDest, speed)

    return Transition.getNextState(nav, goToPosition)
Esempio n. 27
0
    if firstAttacker and secondAttacker:
        return True

    return False

### RANDOM STUFF
isKickingOff = False # Default is false, changed by pBrunswick or some other if
                     # this is not the case, TODO this is ugly

boxBuffer = 100 # Used for the buffered box when approach ball is potentially
                # going to transition out and into 'positionAtHome'

### HOME POSITIONS

oddDefenderHomePenn = RobotLocation(NogginConstants.BLUE_GOALBOX_RIGHT_X + 20,
                                    NogginConstants.MY_GOALBOX_BOTTOM_Y + 40,
                                    0)

evenDefenderHomePenn = RobotLocation(NogginConstants.BLUE_GOALBOX_RIGHT_X + 20,
                                    NogginConstants.MY_GOALBOX_TOP_Y - 40,
                                    0)

oddDefenderHomeMiami = RobotLocation(NogginConstants.BLUE_GOALBOX_RIGHT_X + 40,
                                    NogginConstants.MY_GOALBOX_BOTTOM_Y + 40,
                                    0)

evenDefenderHomeMiami = RobotLocation(NogginConstants.BLUE_GOALBOX_RIGHT_X + 40,
                                    NogginConstants.MY_GOALBOX_TOP_Y - 40,
                                    0)
oddDefenderHomeTexas = RobotLocation(NogginConstants.BLUE_GOALBOX_RIGHT_X + 75,
                                    NogginConstants.MY_GOALBOX_BOTTOM_Y + 15,
Esempio n. 28
0
import noggin_constants as NogginConstants
from objects import RobotLocation

isDefender = False  # default is false, changed by pBrunswick or some other if
# this is not the case

oddDefenderHome = RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X,
                                NogginConstants.GREEN_PAD_Y + 50, 20)

evenDefenderHome = RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X,
                                 NogginConstants.FIELD_GREEN_HEIGHT - 170, -20)

oddChaserHome = RobotLocation(NogginConstants.CENTER_FIELD_X,
                              NogginConstants.GREEN_PAD_Y + 10, 90)

evenChaserHome = RobotLocation(NogginConstants.CENTER_FIELD_X,
                               NogginConstants.FIELD_GREEN_HEIGHT - 10, -90)

ourKickoff = RobotLocation(NogginConstants.CENTER_FIELD_X,
                           NogginConstants.CENTER_FIELD_Y, 0)

theirKickoff = RobotLocation(NogginConstants.CENTER_FIELD_X - \
                                 NogginConstants.CENTER_CIRCLE_RADIUS - 10,
                             NogginConstants.CENTER_FIELD_Y,
                             0)

# These values are in cm, with the origin defined as the right corner of the
# field closest to your own goal

#   |                   |   ^
#   |                   |   |
Esempio n. 29
0
SAVE_DIST = 170.0

POSITION_FOR_KICK_DIST = 45.0
SLOW_DOWN_DIST = 60.0

BALL_X_OFFSET = 5
BALL_Y_OFFSET = 3
GOOD_ENOUGH_H = 6

HOME = 0
LEFT = 1
FAR_LEFT = 2
RIGHT = -1
FAR_RIGHT = -2

HOME_POSITION = RobotLocation(constants.FIELD_WHITE_LEFT_SIDELINE_X + 15.0,
                              constants.MIDFIELD_Y, 0.0)

LEFT_POSITION = RobotLocation(constants.FIELD_WHITE_LEFT_SIDELINE_X + 10.0,
                              HOME_POSITION.y + 35, 0.0)

FAR_LEFT_POSITION = RobotLocation(constants.FIELD_WHITE_LEFT_SIDELINE_X + 17.0,
                                  HOME_POSITION.y + 65, 0.0)

RIGHT_POSITION = RobotLocation(constants.FIELD_WHITE_LEFT_SIDELINE_X + 10.0,
                               HOME_POSITION.y - 35, 0.0)

FAR_RIGHT_POSITION = RobotLocation(
    constants.FIELD_WHITE_LEFT_SIDELINE_X + 17.0, HOME_POSITION.y - 65, 0.0)

LEFT_SHIFT = RelRobotLocation(5.0, 30.0, 0.0)
RIGHT_SHIFT = RelRobotLocation(5.0, -30.0, 0.0)
Esempio n. 30
0
        elif isSecondChaser(mate.role) or isCherryPicker(mate.role) or isStriker(player.role):
            secondAttacker = True
    
    return firstAttacker and secondAttacker

### RANDOM STUFF
isKickingOff = False # Default is false, changed by pBrunswick or some other if
                     # this is not the case, TODO this is ugly

boxBuffer = 100 # Used for the buffered box when approach ball is potentially
                # going to transition out and into 'positionAtHome'

### HOME POSITIONS
# Trapezoid of terror (defender positioning)
oddDefenderForward = RobotLocation(NogginConstants.MIDFIELD_X - 60,
                                    NogginConstants.BLUE_GOALBOX_BOTTOM_Y - 70,
                                    0)
evenDefenderForward = RobotLocation(NogginConstants.MIDFIELD_X - 60,
                                    NogginConstants.BLUE_GOALBOX_TOP_Y + 70,
                                    0)
oddDefenderBack = RobotLocation(NogginConstants.BLUE_GOALBOX_RIGHT_X + 20, 
                                NogginConstants.BLUE_GOALBOX_BOTTOM_Y - 10,
                                0)
evenDefenderBack = RobotLocation(NogginConstants.BLUE_GOALBOX_RIGHT_X + 20, 
                                NogginConstants.BLUE_GOALBOX_TOP_Y + 10,
                                0)

# Tomultuous triangle (odd chaser positioning)
strikerForward = RobotLocation(NogginConstants.MIDFIELD_X + NogginConstants.CENTER_CIRCLE_RADIUS + 170,
                                NogginConstants.MIDFIELD_Y,
                                180)
Esempio n. 31
0
def goToPosition(nav):
    """
    Go to a position set in the navigator. General go to state.  Goes
    towards a location on the field stored in dest.
    The location can be a RobotLocation, Location, RelRobotLocation, RelLocation
    Absolute locations get transformed to relative locations based on current loc
    For relative locations we use our bearing to that point as the heading
    """
    relDest = helper.getRelativeDestination(nav.brain.loc, goToPosition.dest)

    if nav.firstFrame():
        # print("Resetting at position transition!!")
        nav.atLocPositionTransition.reset()

    if not nav.brain.motion.calibrated:
        helper.stand(nav)
        return nav.stay()

    # if nav.counter % 10 is 0:
    # print "\ngoing to " + str(relDest)
    #    print "ball is at {0}, {1}, {2} ".format(nav.brain.ball.loc.relX,
    #                                             nav.brain.ball.loc.relY,
    #                                             nav.brain.ball.loc.bearing)

    if nav.counter < 5:
        # print("In go to position, walking in place")
        helper.walkInPlace(nav)
        return nav.stay()

    goToPosition.speed = nav.velocity
    if fabs(nav.requestVelocity - nav.velocity) > Navigator.SPEED_CHANGE:
        nav.velocity += copysign(Navigator.SPEED_CHANGE,
                                 (nav.requestVelocity - nav.velocity))

    if goToPosition.pb and isinstance(goToPosition.dest, RelRobotLocation):
        # Calc dist to dest
        dist = helper.getDistToDest(nav.brain.loc, goToPosition.dest)
        if goToPosition.fast and dist < 140:
            goToPosition.fast = False
            goToPosition.dest = nav.brain.play.getPosition()
        elif not goToPosition.fast and dist > 160:
            goToPosition.fast = True
            goToPosition.dest = nav.brain.play.getPositionCoord()

    if isinstance(goToPosition.dest, RobotLocation):
        dist = helper.getDistToDest(nav.brain.loc, goToPosition.dest)
        # print("Distance: ", dist)
        if dist < 30:
            # print("I'm close enough ! I should not go fast anymore")
            goToPosition.fast = False
            goToPosition.speeds = (0.1, 0.1, 0.1)

    # print("My reldest: ", str(relDest))

    if goToPosition.fast:
        # print("goToPosition fast")
        # So that fast mode works for objects of type RobotLocation also
        if isinstance(goToPosition.dest,
                      RobotLocation) and not goToPosition.close:
            # print("It is an instance of a robot location")
            fieldDest = RobotLocation(goToPosition.dest.x, goToPosition.dest.y,
                                      0)
            relDest = nav.brain.loc.relativeRobotLocationOf(fieldDest)
            relDest.relH = nav.brain.loc.getRelativeBearing(fieldDest)
        elif isinstance(goToPosition.dest, RelRobotLocation):
            relDest = goToPosition.dest

        HEADING_ADAPT_CUTOFF = 103
        DISTANCE_ADAPT_CUTOFF = 10

        MAX_TURN = .5

        BOOK_IT_TURN_THRESHOLD = 23
        BOOK_IT_DISTANCE_THRESHOLD = 50

        if relDest.relH >= HEADING_ADAPT_CUTOFF:
            velH = MAX_TURN
        elif relDest.relH <= -HEADING_ADAPT_CUTOFF:
            velH = -MAX_TURN
        else:
            velH = helper.adaptSpeed(relDest.relH, HEADING_ADAPT_CUTOFF,
                                     MAX_TURN)

        if relDest.relX >= DISTANCE_ADAPT_CUTOFF:
            velX = goToPosition.speed
        elif relDest.relX <= -DISTANCE_ADAPT_CUTOFF:
            velX = -goToPosition.speed
        else:
            velX = helper.adaptSpeed(relDest.relX, DISTANCE_ADAPT_CUTOFF,
                                     goToPosition.speed)

        if relDest.relY >= DISTANCE_ADAPT_CUTOFF:
            velY = goToPosition.speed
        elif relDest.relY <= -DISTANCE_ADAPT_CUTOFF:
            velY = -goToPosition.speed
        else:
            velY = helper.adaptSpeed(relDest.relY, DISTANCE_ADAPT_CUTOFF,
                                     goToPosition.speed)

        if fabs(relDest.dist) > BOOK_IT_DISTANCE_THRESHOLD:
            goToPosition.close = False
            if fabs(relDest.relH) > BOOK_IT_TURN_THRESHOLD:
                if relDest.relH > 0: velH = MAX_TURN
                if relDest.relH < 0: velH = -MAX_TURN
                velX = 0
                velY = 0
                goToPosition.bookingIt = False
            else:
                velY = 0
                goToPosition.bookingIt = True
        else:
            goToPosition.close = True

        # TODO nikki walk unsw hack
        # if relDest.relY < DISTANCE_ADAPT_CUTOFF:
        #     velY = 0.0

        if (fabs(relDest.relH) > 20.0):
            goToPosition.speeds = (0, 0, velH)
        else:
            goToPosition.speeds = (velX, velY, velH)
        # print("     NAV: My speeds:", velX, velY, velH)

        helper.setSpeed(nav, goToPosition.speeds)

    else:
        # print("Was not fase!")
        if goToPosition.adaptive:
            #reduce the speed if we're close to the target
            speed = helper.adaptSpeed(relDest.dist, constants.ADAPT_DISTANCE,
                                      goToPosition.speed)
        else:
            speed = goToPosition.speed

        helper.setDestination(nav, relDest, speed)
        # print("     NAV Setting dest: ", str(relDest))

    # if navTrans.shouldDodge(nav):
    #     return nav.goNow('dodge')

    return Transition.getNextState(nav, goToPosition)
Esempio n. 32
0
def cherryPicker(player):
    """
    Cherry pickers stay where they are but look to the ball.
    """
    return RobotLocation(player.brain.loc.x, player.brain.loc.y,
                         player.brain.ball.bearing_deg + player.brain.loc.h)
Esempio n. 33
0
 def mapPositionToRobotLocation(self, position):
     """
     Position must be a tuple with x, y, heading, role.
     @return: that position as a Robot Location
     """
     return RobotLocation(position[0], position[1], position[2])
Esempio n. 34
0
 def __init__(self, role=INIT_ROLE, position=RobotLocation(0, 0, 0)):
     self.role = role
     self.position = position
     self.changed = True