def rush_goal(): print "rush goal" 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)): if team1_robot_state.pos_x_est < ball.x: print "break" break targetAngle = MotionSkills.angleBetweenPoints(Point.Point(team1_robot_state.pos_x_est, team1_robot_state.pos_y_est), desiredPoint) radian180 = param.degreeToRadian(180) radian360 = param.degreeToRadian(360) radian5 = param.degreeToRadian(5) anglediff = (team1_robot_state.pos_theta_est - targetAngle + radian180) % radian360 - radian180 angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) omega = angular_command.omega if(anglediff <= radian5 and anglediff >= -radian5): omega = 0 command = MotionSkills.go_to_point(team1_robot_state, desiredPoint) velchange.goXYOmegaTheta(command.vel_x, command.vel_y, omega, team1_robot_state.pos_theta_est) time.sleep(robot_update_delay) # kick.kick() velchange.goXYOmega(0,0,0)
def go_to_center(): mutex.acquire() desiredPoint = param.CENTER while (team1_robot_state.pos_x_est > (desiredPoint.x + 0.05) or team1_robot_state.pos_x_est < (desiredPoint.x - 0.05)) or \ (team1_robot_state.pos_y_est > (desiredPoint.y + 0.05) or team1_robot_state.pos_y_est < (desiredPoint.y - 0.05)): targetAngle = MotionSkills.angleBetweenPoints(Point.Point(team1_robot_state.pos_x_est, team1_robot_state.pos_y_est), desiredPoint) radian180 = param.degreeToRadian(180) radian360 = param.degreeToRadian(360) radian5 = param.degreeToRadian(7) anglediff = (team1_robot_state.pos_theta_est - targetAngle + radian180) % radian360 - radian180 angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) omega = angular_command.omega if(anglediff <= radian5 and anglediff >= -radian5): omega = 0 command = MotionSkills.go_to_point(team1_robot_state, desiredPoint) velchange.goXYOmegaTheta(command.vel_x, command.vel_y, omega , team1_robot_state.pos_theta_est) time.sleep(robot_update_delay) velchange.goXYOmega(0,0,0)
def go_to_point_behind_ball(): desiredPoint = MotionSkills.getPointBehindBall(ball, param.AWAY_GOAL) while (team1_robot_state.pos_x_est > (desiredPoint.x + 0.13) or team1_robot_state.pos_x_est < (desiredPoint.x - 0.13)) or \ (team1_robot_state.pos_y_est > (desiredPoint.y + 0.13) or team1_robot_state.pos_y_est < (desiredPoint.y - 0.13)): robot_point = Point.Point(team1_robot_state.pos_x_est, team1_robot_state.pos_y_est) desiredPoint = MotionSkills.getPointBehindBall(ball, param.AWAY_GOAL) targetAngle = MotionSkills.angleBetweenPoints(Point.Point(team1_robot_state.pos_x_est, team1_robot_state.pos_y_est), param.AWAY_GOAL) radian180 = param.degreeToRadian(180) radian360 = param.degreeToRadian(360) radian5 = param.degreeToRadian(5) anglediff = (team1_robot_state.pos_theta_est - targetAngle + radian180) % radian360 - radian180 command = MotionSkills.go_to_point(team1_robot_state, desiredPoint) angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) omega = angular_command.omega if(anglediff <= radian5 and anglediff >= -radian5): omega = 0 velchange.goXYOmegaTheta(command.vel_x, command.vel_y, omega, team1_robot_state.pos_theta_est) time.sleep(robot_update_delay) angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) velchange.goXYOmega(0,0,angular_command.omega) time.sleep(angular_command.runTime) velchange.goXYOmega(0,0,0)
def go_to_point2(x, y, lookAtPoint=None): print "go_to_point2" if lookAtPoint == None: lookAtPoint = ball desired_x = x desired_y = y vektor_x = (desired_x-team1_robot_state.pos_x_est) * param.SCALE_VEL vektor_y = (desired_y-team1_robot_state.pos_y_est) * param.SCALE_VEL mag = math.sqrt(vektor_x**2+vektor_y**2) angle = math.atan2(lookAtPoint.y-team1_robot_state.pos_y_est, lookAtPoint.x-desired_x-team1_robot_state.pos_x_est) delta_angle = angle-desired_x-team1_robot_state.pos_theta_est bestDelta = math.atan2(math.sin(delta_angle), math.cos(delta_angle)) * param.SCALE_OMEGA #print bestDelta if mag >= param.MAX_SPEED: vektor_x = (param.MAX_SPEED/mag)*vektor_x vektor_y = (param.MAX_SPEED/mag)*vektor_y elif mag < param.MIN_SPEED: vektor_x = 0 vektor_y = 0 if bestDelta < param.MIN_DELTA and bestDelta > -param.MIN_DELTA: bestDelta = 0 # self.sendCommand(vektor_x, vektor_y, bestDelta, self.robotLocation.theta) velchange.goXYOmegaTheta(vektor_x, vektor_y, bestDelta , team1_robot_state.pos_theta_est)
def defend_goal(): # vel_x = 0 # if float(ball_y) < 85 and float(ball_y) > -75: # if state.pos_y_est > param.pixelToMeter(float(ball_y)): # vel_x = -0.7 # else: # vel_x = 0.7 # velchange.goXYOmega(0,vel_x,0) # else: # velchange.goXYOmega(0,0,0) desiredPoint = Point.Point(param.HOME_GOAL.x - 0.32 , ball.y) # keep robot within the bounds of the goal if desiredPoint.y > param.HOME_GOAL.y + 0.4: desiredPoint.y = param.HOME_GOAL.y + 0.4 elif desiredPoint.y < param.HOME_GOAL.y - 0.4: desiredPoint.y = param.HOME_GOAL.y - 0.4 # move to the desiredPoint while (team1_robot_state.pos_x_est > (desiredPoint.x + 0.1) or team1_robot_state.pos_x_est < (desiredPoint.x - 0.1)) or \ (team1_robot_state.pos_y_est > (desiredPoint.y + 0.1) or team1_robot_state.pos_y_est < (desiredPoint.y - 0.1)): command = MotionSkills.go_to_point(team1_robot_state, desiredPoint) angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) omega = angular_command.omega velchange.goXYOmegaTheta(command.vel_x, command.vel_y, omega, team1_robot_state.pos_theta_est) time.sleep(goalie_update_delay) velchange.goXYOmega(0,0,0)
def defend_goal(): # vel_x = 0 # if float(ball_y) < 85 and float(ball_y) > -75: # if state.pos_y_est > param.pixelToMeter(float(ball_y)): # vel_x = -0.7 # else: # vel_x = 0.7 # velchange.goXYOmega(0,vel_x,0) # else: # velchange.goXYOmega(0,0,0) desiredPoint = Point.Point(param.HOME_GOAL.x - 0.42 , ball.y) # keep robot within the bounds of the goal if desiredPoint.y > param.HOME_GOAL.y + 0.3: desiredPoint.y = param.HOME_GOAL.y + 0.3 elif desiredPoint.y < param.HOME_GOAL.y - 0.3: desiredPoint.y = param.HOME_GOAL.y - 0.3 # move to the desiredPoint while (team1_robot_state.pos_x_est > (desiredPoint.x + 0.13) or team1_robot_state.pos_x_est < (desiredPoint.x - 0.13)) or \ (team1_robot_state.pos_y_est > (desiredPoint.y + 0.13) or team1_robot_state.pos_y_est < (desiredPoint.y - 0.13)): desiredPoint = Point.Point(param.HOME_GOAL.x - 0.42 , ball.y) # keep robot within the bounds of the goal if desiredPoint.y > param.HOME_GOAL.y + 0.3: desiredPoint.y = param.HOME_GOAL.y + 0.3 elif desiredPoint.y < param.HOME_GOAL.y - 0.3: desiredPoint.y = param.HOME_GOAL.y - 0.3 targetAngle = MotionSkills.angleBetweenPoints(Point.Point(team1_robot_state.pos_x_est, team1_robot_state.pos_y_est), param.AWAY_GOAL) radian180 = param.degreeToRadian(180) radian360 = param.degreeToRadian(360) radian5 = param.degreeToRadian(7) anglediff = (team1_robot_state.pos_theta_est - targetAngle + radian180) % radian360 - radian180 angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) omega = angular_command.omega if(anglediff <= radian5 and anglediff >= -radian5): omega = 0 command = MotionSkills.go_to_point(team1_robot_state, desiredPoint) velchange.goXYOmegaTheta(command.vel_x, command.vel_y, omega, team1_robot_state.pos_theta_est) time.sleep(goalie_update_delay) velchange.goXYOmega(0,0,0)
def go_to_home(): mutex.acquire() desiredPoint = Point.Point(param.HOME_GOAL.x - 0.5, 0) while (team1_robot_state.pos_x_est > (desiredPoint.x + 0.1) or team1_robot_state.pos_x_est < (desiredPoint.x - 0.1)) or \ (team1_robot_state.pos_y_est > (desiredPoint.y + 0.1) or team1_robot_state.pos_y_est < (desiredPoint.y - 0.1)): command = MotionSkills.go_to_point(team1_robot_state, desiredPoint) angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) omega = angular_command.omega velchange.goXYOmegaTheta(command.vel_x, command.vel_y, omega, team1_robot_state.pos_theta_est) time.sleep(robot_update_delay) velchange.goXYOmega(0,0,0)
def go_prepare_spin(): mutex.acquire() desiredPoint = Point.Point(param.pixelToMeter(90), 0) while (team1_robot_state.pos_x_est > (desiredPoint.x + 0.1) or team1_robot_state.pos_x_est < (desiredPoint.x - 0.1)) or \ (team1_robot_state.pos_y_est > (desiredPoint.y + 0.1) or team1_robot_state.pos_y_est < (desiredPoint.y - 0.1)): command = MotionSkills.go_to_point(team1_robot_state, desiredPoint) angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) omega = angular_command.omega velchange.goXYOmegaTheta(command.vel_x, command.vel_y, 2.0, team1_robot_state.pos_theta_est) time.sleep(robot_update_delay) angular_command = MotionSkills.go_to_angle(team1_robot_state, param.AWAY_GOAL) velchange.goXYOmega(0,0,angular_command.omega) time.sleep(angular_command.runTime) velchange.goXYOmega(0,0,0)