ObeyGameManager::ObeyGameManager(ConfigFile & configFile, Log & _log)
  : INITIAL_CHEST_COLOR  (configFile.getInt("rules/initialChestColor",   0x000000)),
    READY_CHEST_COLOR    (configFile.getInt("rules/readyChestColor",     0x0000FF)),
    SET_CHEST_COLOR      (configFile.getInt("rules/setChestColor",       0xFFFF00)),
    PLAYING_CHEST_COLOR  (configFile.getInt("rules/playingChestColor",   0x00FF00)),
    FINISHED_CHEST_COLOR (configFile.getInt("rules/finishedChestColor",  0x000000)),
    PENALIZED_CHEST_COLOR(configFile.getInt("rules/penalisedChestColor", 0xFF0000)),
    BLUE_TEAM_FOOT_COLOR (configFile.getInt("rules/blueTeamFootColor",   0x0000FF)),
    RED_TEAM_FOOT_COLOR  (configFile.getInt("rules/redTeamFootColor",    0xFF0000)),
    KICKOFF_FOOT_COLOR   (configFile.getInt("rules/kickoffFootColor",    0xFFFFFF)),
    NO_KICKOFF_FOOT_COLOR(configFile.getInt("rules/noKickoffFootColor",  0x000000)),
    READY_SPEECH            (configFile.getString("behaviors/2010/tactics/obeyGameManager/readySpeech",           "I will get ready for the game.")),
    SET_SPEECH              (configFile.getString("behaviors/2010/tactics/obeyGameManager/setSpeech",             "I am all set!")),
    PLAYING_SPEECH          (configFile.getString("behaviors/2010/tactics/obeyGameManager/playingSpeech",         "It's time to play.")),
    PENALIZED_SPEECH        (configFile.getString("behaviors/2010/tactics/obeyGameManager/penalizedSpeech",       "Please don't penalize me!")),
    BACK_FROM_PENALTY_SPEECH(configFile.getString("behaviors/2010/tactics/obeyGameManager/backFromPenaltySpeech", "The taste of freedom is sweet.")),
    BLUE_TEAM_SPEECH        (configFile.getString("behaviors/2010/tactics/obeyGameManager/blueTeamSpeech",        "I am now on the blue team.")),
    RED_TEAM_SPEECH         (configFile.getString("behaviors/2010/tactics/obeyGameManager/redTeamSpeech",         "I am now on the red team.")),
    KICKOFF_SPEECH          (configFile.getString("behaviors/2010/tactics/obeyGameManager/kickoffSpeech",         "We have kickoff.")),
    NO_KICKOFF_SPEECH       (configFile.getString("behaviors/2010/tactics/obeyGameManager/noKickoffSpeech",       "We don't have kickoff.")),
    PLAYER_NUMBER(configFile.getInt("team/playerNumber", 2)),
    HEAD_SPEED(configFile.getFloat("motion/defaultHeadSpeed", 0.8f)),
    log(_log),
    fsm(_log),
    previousState(Uninitialized),
    currentState(Uninitialized),
    wasIBlue(false),
    wasOurKickoff(false),
    wasIPenalized(false) {
  init(_log.getTimestamp());
}
CommRemote::CommRemote(ConfigFile & configFile, Log & _log)
  : listenPort            (configFile.getInt  ("comm/remoteListenPort", 10000)),
    maxClientQueue        (configFile.getInt  ("comm/remoteMaxClientQueue", 1)),
    maxPacketSize         (configFile.getInt  ("comm/maxPacketSize", 1024)),
    socketTimeout         (configFile.getFloat("comm/socketTimeout", 1)),
    robotMessageHeaderSize(configFile.getInt  ("comm/robotMessageHeaderSize", 5)),
    sendBufferSize        (configFile.getInt  ("comm/sendBufferSize", 1024 * 1024)),
    log(_log),
    serverSocket(-1),
    clientSocket(-1),
    threadRunning(false),
    thread(),
    dataMutex(),
    messagesToRobot(),
    messagesFromRobot(),
    wasConnectedToClient(false),
    sendBuffer(NULL),
    sendBufferOffset(0) {
  // Create the send buffer
  if (sendBufferSize > 0) {
    sendBuffer = new unsigned char[sendBufferSize];
  }

  // Create the TCP socket and bind to the right port
  createTCPSocket();

  // Create the data mutex
  if (pthread_mutex_init(&dataMutex, NULL) < 0) {
    LOG_ERROR("Error creating data mutex.");
    return;
  }

  // Start the thread to read/send packets
  if (pthread_create(&thread, NULL, startThread, this) < 0) {
    LOG_ERROR("Error creating thread.");
    return;
  }
}
Esempio n. 3
0
Field::Field(ConfigFile & configFile)
  : carpetLength       (configFile.getFloat("field/carpetLength")),
    carpetWidth        (configFile.getFloat("field/carpetWidth")),
    fieldLength        (configFile.getFloat("field/fieldLength")),
    fieldWidth         (configFile.getFloat("field/fieldWidth")),
    halfFieldLength    (fieldLength / 2),
    halfFieldWidth     (fieldWidth / 2),
    penaltyBoxLength   (configFile.getFloat("field/penaltyBoxLength")),
    penaltyBoxWidth    (configFile.getFloat("field/penaltyBoxWidth")),
    halfPenaltyBoxWidth(penaltyBoxWidth / 2),
    goalWidth          (configFile.getFloat("field/goalWidth")),
    centerCircleRadius (configFile.getFloat("field/centerCircleRadius")),
    isOurColorBlue     (true),
    ourPenaltyPoint     (-configFile.getFloat("field/distCenterToPenaltyPoint"), 0),
    opponentPenaltyPoint( configFile.getFloat("field/distCenterToPenaltyPoint"), 0),
    ourGoal              (-halfFieldLength, 0),
    opponentGoal         ( halfFieldLength, 0),
    ourGoalPostLeft      (-halfFieldLength, -goalWidth / 2),
    ourGoalPostRight     (-halfFieldLength,  goalWidth / 2),
    opponentGoalPostLeft ( halfFieldLength,  goalWidth / 2),
    opponentGoalPostRight( halfFieldLength, -goalWidth / 2),
    goaliePenaltyBoxTopLeft (-halfFieldLength + penaltyBoxLength , penaltyBoxWidth / 2),
    goaliePenaltyBoxTopRight(-halfFieldLength + penaltyBoxLength , -penaltyBoxWidth / 2),
    goaliePenaltyBoxBottomLeft(-halfFieldLength, penaltyBoxWidth / 2),
    goaliePenaltyBoxBottomRight(-halfFieldLength, -penaltyBoxWidth / 2)
{
	L_corners[0].x = getHalfFieldLength();
	L_corners[0].y = getHalfFieldWidth();
	L_corner_angles[0] = -3 * M_PI / 4;
	L_corners[1].x = getHalfFieldLength();
	L_corners[1].y = -getHalfFieldWidth();
	L_corner_angles[1] = 3 * M_PI / 4;
	L_corners[2].x = -getHalfFieldLength();
	L_corners[2].y = getHalfFieldWidth();
	L_corner_angles[2] = -M_PI / 4;
	L_corners[3].x = -getHalfFieldLength();
	L_corners[3].y = -getHalfFieldWidth();
	L_corner_angles[3] = M_PI / 4;
	L_corners[4].x = getHalfFieldLength() - getPenaltyBoxLength();
	L_corners[4].y = getHalfPenaltyBoxWidth();
	L_corner_angles[4] = -M_PI / 4;
	L_corners[5].x = getHalfFieldLength() - getPenaltyBoxLength();
	L_corners[5].y = -getHalfPenaltyBoxWidth();
	L_corner_angles[5] = M_PI / 4;
	L_corners[6].x = -getHalfFieldLength() + getPenaltyBoxLength();
	L_corners[6].y = getHalfPenaltyBoxWidth();
	L_corner_angles[6] = -3 * M_PI / 4;
	L_corners[7].x = -getHalfFieldLength() + getPenaltyBoxLength();
	L_corners[7].y = -getHalfPenaltyBoxWidth();
	L_corner_angles[7] = 3 * M_PI / 4;

	T_corners[0].x = getHalfFieldLength();
	T_corners[0].y = getHalfPenaltyBoxWidth();
	T_corner_angles[0] = -M_PI;
	T_corners[1].x = getHalfFieldLength();
	T_corners[1].y = -getHalfPenaltyBoxWidth();
	T_corner_angles[1] = -M_PI;
	T_corners[2].x = -getHalfFieldLength();
	T_corners[2].y = getHalfPenaltyBoxWidth();
	T_corner_angles[2] = M_PI;
	T_corners[3].x = -getHalfFieldLength();
	T_corners[3].y = -getHalfPenaltyBoxWidth();
	T_corner_angles[3] = M_PI;
	T_corners[4].x = 0;
	T_corners[4].y = getHalfFieldWidth();
	T_corner_angles[4] = -M_PI / 2;
	T_corners[5].x = 0;
	T_corners[5].y = -getHalfFieldWidth();
	T_corner_angles[5] = M_PI / 2;

	cross_corners[0].x = 0;
	cross_corners[0].y = getCenterCircleRadius();
	cross_corners[1].x = 0;
	cross_corners[1].y = -getCenterCircleRadius();

	//two endpoints per line segment
	//LINE ENDPOINTS MUST BE ORDERED SO THAT POINT 2 HAS X & Y THAT ARE >= THE X & Y OF POINT 1!!!!!!!!!
	lines[0][0].x = getHalfFieldLength(); lines[0][0].y = -getHalfFieldWidth();
	lines[0][1].x = getHalfFieldLength(); lines[0][1].y = getHalfFieldWidth();
	lines[1][0].x = -getHalfFieldLength(); lines[1][0].y = -getHalfFieldWidth();
	lines[1][1].x = -getHalfFieldLength(); lines[1][1].y = getHalfFieldWidth();
	lines[2][0].x = -getHalfFieldLength(); lines[2][0].y = getHalfFieldWidth();
	lines[2][1].x = getHalfFieldLength(); lines[2][1].y = getHalfFieldWidth();
	lines[3][0].x = -getHalfFieldLength(); lines[3][0].y = -getHalfFieldWidth();
	lines[3][1].x = getHalfFieldLength(); lines[3][1].y = -getHalfFieldWidth();
	lines[4][0].x = 0; lines[4][0].y = -getHalfFieldWidth();
	lines[4][1].x = 0; lines[4][1].y = getHalfFieldWidth();
	lines[5][0].x = getHalfFieldLength() - getPenaltyBoxLength(); lines[5][0].y = getHalfPenaltyBoxWidth();
	lines[5][1].x = getHalfFieldLength(); lines[5][1].y = getHalfPenaltyBoxWidth();
	lines[6][0].x = getHalfFieldLength() - getPenaltyBoxLength(); lines[6][0].y = -getHalfPenaltyBoxWidth();
	lines[6][1].x = getHalfFieldLength(); lines[6][1].y = -getHalfPenaltyBoxWidth();
	lines[7][0].x = getHalfFieldLength() - getPenaltyBoxLength(); lines[7][0].y = -getHalfPenaltyBoxWidth();
	lines[7][1].x = getHalfFieldLength() - getPenaltyBoxLength(); lines[7][1].y = getHalfPenaltyBoxWidth();
	lines[8][0].x = -getHalfFieldLength(); lines[8][0].y = getHalfPenaltyBoxWidth();
	lines[8][1].x = -getHalfFieldLength() + getPenaltyBoxLength(); lines[8][1].y = getHalfPenaltyBoxWidth();
	lines[9][0].x = -getHalfFieldLength(); lines[9][0].y = -getHalfPenaltyBoxWidth();
	lines[9][1].x = -getHalfFieldLength() + getPenaltyBoxLength(); lines[9][1].y = -getHalfPenaltyBoxWidth();
	lines[10][0].x = -getHalfFieldLength() + getPenaltyBoxLength(); lines[10][0].y = -getHalfPenaltyBoxWidth();
	lines[10][1].x = -getHalfFieldLength() + getPenaltyBoxLength(); lines[10][1].y = getHalfPenaltyBoxWidth();
}