#include <SenseHandler.h>
Definition at line 79 of file SenseHandler.h.
SenseHandler::SenseHandler | ( | Connection * | c, | |
WorldModel * | wm, | |||
ServerSettings * | ss, | |||
PlayerSettings * | ps, | |||
ActionScheduler * | as | |||
) |
Constructor for the SenseHandler. It needs a reference to a connection and a reference to a worldmodel.
c | Connection from which input is received | |
wm | WorldModel to which new information will be sent for processing | |
ss | ServerSettings that contain the parameters used by the server | |
ps | PlayerSettings that determine how to interact with messages. |
Definition at line 84 of file SenseHandler.cpp.
References as, AS, connection, ServerSettings::getSimulatorStep(), iLastCycle, iSimStep, iTimeSignal, itv, max(), min(), PS, sigalarmHandler(), SS, and WM.
void SenseHandler::handleMessagesFromServer | ( | ) |
This is the main routine of this class. It loops forever (till the thread is destroyed) and receives and parses the incoming messages.
Definition at line 125 of file SenseHandler.cpp.
References analyzeMessage(), connection, MAX_MSG, and Connection::receiveMessage().
Referenced by sense_callback().
void SenseHandler::setTimeSignal | ( | ) |
This method sets the time signal. This is the time that should be waited before the next action should be sent to the server. As soon as a sense message arrives this method is called. Using the information from the member variable 'iTriCounter' which denotes when the see message will arrive in this cycle (0=first half, 1=2nd half, 2=no see, all for the default view frequency) the timer is set. The values that denote the fraction of the simulation step that is waited are all defined in PlayerSettings, such that they can be easily changed.
Definition at line 150 of file SenseHandler.cpp.
References AS, ActionScheduler::dispatchAction(), WorldModel::getAgentViewFrequency(), WorldModel::getCurrentCycle(), PlayerSettings::getFractionWaitNoSee(), PlayerSettings::getFractionWaitSeeBegin(), PlayerSettings::getFractionWaitSeeEnd(), iLastCycle, iSimStep, iTimeSignal, iTriCounter, itv, PS, sigalarmHandler(), and WM.
Referenced by analyzeSenseMessage().
bool SenseHandler::analyzeMessage | ( | char * | strMsg | ) |
This method analyzes the type of the incoming message and calls the message that corresponds to this message.
strMsg | message that should be parsed. |
Definition at line 201 of file SenseHandler.cpp.
References analyzeChangePlayerTypeMessage(), analyzeCheckBall(), analyzeFullStateMessage(), analyzeHearMessage(), analyzeInitMessage(), analyzePlayerParamMessage(), analyzePlayerTypeMessage(), analyzeSeeGlobalMessage(), analyzeSeeMessage(), analyzeSenseMessage(), analyzeServerParamMessage(), WorldModel::getCurrentCycle(), WorldModel::getCurrentTime(), WorldModel::getPlayerNumber(), WorldModel::isFullStateOn(), Logger::log(), Log, Logger::logWithTime(), WorldModel::processRecvThink(), WorldModel::updateAfterSenseMessage(), and WM.
Referenced by handleMessagesFromServer().
bool SenseHandler::analyzeSeeGlobalMessage | ( | char * | strMsg | ) |
This method analyzes a see Message. All information from the different objects that is stored in a see message is send to worldmodel. A see message looks like(see 0 ((g r) 64.1 13) ((f r t) 65.4 -16) ....
strMsg | message that should be parsed |
Definition at line 314 of file SenseHandler.cpp.
References WorldModel::getCurrentTime(), SoccerTypes::getObjectFromStr(), WorldModel::getTeamName(), Parse::gotoFirstOccurenceOf(), Logger::log(), Log, Logger::logWithTime(), OBJECT_ILLEGAL, Parse::parseFirstDouble(), Parse::parseFirstInt(), WorldModel::processSeeGlobalInfo(), WorldModel::setTimeLastSeeGlobalMessage(), WorldModel::strLastSeeMessage, UnknownAngleValue, UnknownDoubleValue, Time::updateTime(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzeFullStateMessage | ( | char * | strMsg | ) |
This method parses a full state message. This message contains all information from the playing field without noise. It will not be used during real tournaments.
Definition at line 371 of file SenseHandler.cpp.
References CMD_CATCH, CMD_CHANGEVIEW, CMD_DASH, CMD_KICK, CMD_MOVE, CMD_POINTTO, CMD_SAY, CMD_TURN, CMD_TURNNECK, WorldModel::getAgentObjectType(), WorldModel::getCurrentTime(), SoccerTypes::getObjectFromStr(), SoccerTypes::getPlayModeFromRefereeMessage(), SoccerTypes::getRefereeMessageFromStr(), WorldModel::getSide(), Time::getTime(), SoccerTypes::getViewAngleFromStr(), SoccerTypes::getViewQualityFromStr(), Parse::gotoFirstOccurenceOf(), WorldModel::isBeforeKickOff(), Logger::log(), Log, Logger::logWithTime(), VecPosition::normalizeAngle(), OBJECT_BALL, Parse::parseFirstDouble(), Parse::parseFirstInt(), PM_ILLEGAL, WorldModel::processNewAgentInfo(), WorldModel::processSeeGlobalInfo(), Logger::restartTimer(), WorldModel::setNrOfCommands(), WorldModel::setPlayMode(), WorldModel::setTimeLastSeeGlobalMessage(), WorldModel::setTimeLastSenseMessage(), SIDE_LEFT, SIDE_RIGHT, WorldModel::strLastSeeMessage, UnknownAngleValue, UnknownDoubleValue, Time::updateTime(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzeSeeMessage | ( | char * | strMsg | ) |
This method analyzes a see Message. It gets the time from the message and tries to synchronize with the server. Then the message is stored in the world model, which processes it when it performs an update.
Definition at line 266 of file SenseHandler.cpp.
References WorldModel::getAgentViewFrequency(), WorldModel::getRelativeDistance(), Time::getTime(), Time::getTimeDifference(), WorldModel::getTimeLastRecvSenseMessage(), WorldModel::getTimeLastSeeMessage(), ServerSettings::getVisibleDistance(), iTriCounter, Log, Logger::logWithTime(), m_iSeeCounter, OBJECT_BALL, Parse::parseFirstInt(), WorldModel::setTimeLastSeeMessage(), SS, WorldModel::strLastSeeMessage, and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzeSenseMessage | ( | char * | strMsg | ) |
This method analyzes a sense message. All information from the player is parsed and updated in the WorldModel. A sense message looks like (sense_body 0 (view_mode high normal) (stamina 2000 1) (speed 0 0) (head_angle 0) (kick 0) (dash 0) (turn 0) (say 0) (turn_neck 0) (catch 0) (move 0) (change_view 0))
strMsg | message that should be parsed |
Definition at line 508 of file SenseHandler.cpp.
References WorldModel::getCurrentTime(), WorldModel::getRelativeDistance(), ServerSettings::getSimulatorStep(), ServerSettings::getSynchMode(), Time::getTime(), Time::getTimeDifference(), Time::getTimeStopped(), ServerSettings::getVisibleDistance(), iSimStep, iTimeSignal, Logger::log(), Log, Logger::logWithTime(), OBJECT_BALL, Parse::parseFirstInt(), Logger::restartTimer(), WorldModel::setTimeLastSenseMessage(), setTimeSignal(), SS, WorldModel::strLastSenseMessage, Time::updateTime(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzeInitMessage | ( | char * | strMsg | ) |
This method analyzes an init message. All information from the initialization is parsed and updated in the WorldModel. An init message looks like (init [l|r] 10 before_kick_off)
strMsg | message that should be parsed |
Definition at line 549 of file SenseHandler.cpp.
References SoccerTypes::getPlayModeFromStr(), SoccerTypes::getSideFromStr(), SoccerTypes::getTeammateObjectFromIndex(), Logger::log(), Log, Parse::parseFirstInt(), WorldModel::setAgentObjectType(), WorldModel::setPlayerNumber(), WorldModel::setPlayMode(), WorldModel::setSide(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzeHearMessage | ( | char * | strMsg | ) |
This method analyzes a hear message. When the message is from the referee the message is parsed and the new play mode is set or the goal difference is adjusted. When the message comes from another player the method analyzePlayerMessage is called A hear message looks like (hear 0 self|referee|dir message)
strMsg | message that should be parsed |
Definition at line 576 of file SenseHandler.cpp.
References WorldModel::addOneToGoalDiff(), analyzeCoachMessage(), analyzePlayerMessage(), SoccerTypes::getPlayModeFromRefereeMessage(), SoccerTypes::getRefereeMessageFromStr(), SoccerTypes::getRefereeMessageStr(), WorldModel::getSide(), Parse::gotoFirstNonSpace(), Parse::gotoFirstOccurenceOf(), Logger::log(), Log, Logger::logWithTime(), OBJECT_BALL, Parse::parseFirstInt(), PM_FROZEN, PM_ILLEGAL, WorldModel::processCatchedBall(), WorldModel::processSeeGlobalInfo(), REFC_GOAL_LEFT, REFC_GOAL_RIGHT, REFC_GOALIE_CATCH_BALL_LEFT, REFC_GOALIE_CATCH_BALL_RIGHT, REFC_PENALTY_FOUL_LEFT, REFC_PENALTY_FOUL_RIGHT, REFC_PENALTY_MISS_LEFT, REFC_PENALTY_MISS_RIGHT, REFC_PENALTY_ONFIELD_LEFT, REFC_PENALTY_ONFIELD_RIGHT, REFC_PENALTY_SCORE_LEFT, REFC_PENALTY_SCORE_RIGHT, WorldModel::setPlayMode(), WorldModel::setSidePenalty(), WorldModel::setTimeLastRefereeMessage(), SIDE_LEFT, SIDE_RIGHT, WorldModel::strLastHearMessage, WorldModel::subtractOneFromGoalDiff(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzePlayerMessage | ( | int | iTime, | |
char * | strMsg | |||
) |
This message analyzes an incoming communication message. Messages from opponents are discarded. First it is checked whether the message arrived from a teammate using a specific encoding string and then the contents are parsed and stored in the world model, which will process it when it updates the world model.
iTime | time from the message |
Definition at line 661 of file SenseHandler.cpp.
References WorldModel::getPlayerNumber(), Parse::gotoFirstNonSpace(), Logger::log(), Log, Parse::parseFirstInt(), WorldModel::storePlayerMessage(), and WM.
Referenced by analyzeHearMessage().
bool SenseHandler::analyzeCoachMessage | ( | char * | strMsg | ) |
Definition at line 713 of file SenseHandler.cpp.
References Logger::log(), and Log.
Referenced by analyzeHearMessage().
bool SenseHandler::analyzeChangePlayerTypeMessage | ( | char * | strMsg | ) |
This method analyzes the change player type message. This method checks whether the player that changed type equals the agent. When this is the case, it adjust the ServerSettings according to the values associated with this player type.
strMsg | string that contains the player type message. |
Definition at line 739 of file SenseHandler.cpp.
References WorldModel::getHeteroPlayerType(), SoccerTypes::getOpponentObjectFromIndex(), SoccerTypes::getTeammateObjectFromIndex(), Logger::log(), Log, Parse::parseFirstInt(), WorldModel::setHeteroPlayerType(), WorldModel::setSubstitutedOpp(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzeServerParamMessage | ( | char * | strMsg | ) |
This method analyzes the server_param message. This message contains all the server parameters. All settings of the ServerSettings are changed according to the supplied values. This makes the reading from a server configuration file obsolete.
strMsg | string message with all the server parameters |
Definition at line 769 of file SenseHandler.cpp.
References ServerSettings::getBallSize(), ServerSettings::getKickableMargin(), ServerSettings::getPlayerSize(), Logger::log(), Log, readServerParam(), ServerSettings::setMaximalKickDist(), and SS.
Referenced by analyzeMessage().
bool SenseHandler::analyzeCheckBall | ( | char * | strMsg | ) |
This method analyzes the check_ball message that is only received by the coach. It sets the information in the Worldmodel what the status of the ball is. The format is as follows (check_ball <time> <status>).
strMsg | string that contains the check_ball message |
Definition at line 725 of file SenseHandler.cpp.
References SoccerTypes::getBallStatusFromStr(), Parse::parseFirstInt(), WorldModel::setCheckBallStatus(), WorldModel::setTimeCheckBall(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzePlayerTypeMessage | ( | char * | strMsg | ) |
This method analyze a player type message. This message contains the values associated with a specific heterogeneous player type. The values are parsed from the message and supplied to the WorldModel method processNewHeteroPlayer.
strMsg | string that contains the player type information |
Definition at line 906 of file SenseHandler.cpp.
References Logger::log(), Log, Parse::parseFirstDouble(), Parse::parseFirstInt(), WorldModel::processNewHeteroPlayer(), and WM.
Referenced by analyzeMessage().
bool SenseHandler::analyzePlayerParamMessage | ( | char * | strMsg | ) |
This method analyzes the player_param message that indicates the ranges of the possible values for the heterogeneous player types. Nothing is done with this information.
strMsg | string that contains the player_param message. will always be true. |
Definition at line 937 of file SenseHandler.cpp.
References Logger::log(), Log, and readServerParam().
Referenced by analyzeMessage().
bool SenseHandler::readServerParam | ( | char * | strParam, | |
char * | strMsg | |||
) |
Definition at line 874 of file SenseHandler.cpp.
References WorldModel::getPlayerNumber(), ServerSettings::setValue(), SS, and WM.
Referenced by analyzePlayerParamMessage(), and analyzeServerParamMessage().
WorldModel* SenseHandler::WM [private] |
Worldmodel containing all data of the match
Definition at line 80 of file SenseHandler.h.
Referenced by analyzeChangePlayerTypeMessage(), analyzeCheckBall(), analyzeFullStateMessage(), analyzeHearMessage(), analyzeInitMessage(), analyzeMessage(), analyzePlayerMessage(), analyzePlayerTypeMessage(), analyzeSeeGlobalMessage(), analyzeSeeMessage(), analyzeSenseMessage(), readServerParam(), SenseHandler(), and setTimeSignal().
ServerSettings* SenseHandler::SS [private] |
ServerSettings with all server settings
Definition at line 81 of file SenseHandler.h.
Referenced by analyzeSeeMessage(), analyzeSenseMessage(), analyzeServerParamMessage(), readServerParam(), and SenseHandler().
PlayerSettings* SenseHandler::PS [private] |
PlayerSettings with all client settings
Definition at line 82 of file SenseHandler.h.
Referenced by SenseHandler(), and setTimeSignal().
Connection* SenseHandler::connection [private] |
Connection with server to receive messages
Definition at line 83 of file SenseHandler.h.
Referenced by handleMessagesFromServer(), and SenseHandler().
ActionScheduler* SenseHandler::AS [private] |
ActionScheduler for evaluating methods at specific time
Definition at line 84 of file SenseHandler.h.
Referenced by SenseHandler(), and setTimeSignal().
int SenseHandler::iTimeSignal [private] |
Wait time (microsec) before sense calls act
Definition at line 85 of file SenseHandler.h.
Referenced by analyzeSenseMessage(), SenseHandler(), and setTimeSignal().
int SenseHandler::iTriCounter [private] |
Indicates when see message will arive
Definition at line 86 of file SenseHandler.h.
Referenced by analyzeSeeMessage(), and setTimeSignal().
int SenseHandler::m_iSeeCounter [private] |
! Used to count number of see msg in 1 cycle
Definition at line 87 of file SenseHandler.h.
Referenced by analyzeSeeMessage().
int SenseHandler::iSimStep [private] |
Length (microsec) of server cycles
Definition at line 88 of file SenseHandler.h.
Referenced by analyzeSenseMessage(), SenseHandler(), and setTimeSignal().
int SenseHandler::iLastCycle [private] |
struct itimerval SenseHandler::itv [private] |
timer used to set alarm to send action
Definition at line 94 of file SenseHandler.h.
Referenced by SenseHandler(), and setTimeSignal().