📄 soccer.cpp
字号:
/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-this file is part of rcssserver3DFri May 9 2003Copyright (C) 2002,2003 Koblenz UniversityCopyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group$Id: soccer.cpp,v 1.5 2006/05/17 11:52:18 jamu Exp $This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; version 2 of the License.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "soccer.h"#include <sstream>using namespace zeitgeist;using namespace std;using namespace boost;using namespace oxygen;using namespace salt;Soccer::Soccer() : Behavior(){ mTeamName = "unnamed"; mSensationCount = 0; mDriveVec = Vector3f(0,0,0);}Soccer::~Soccer(){}void Soccer::InitAgent(){ GetLog()->Debug() << "sending init command\n"; stringstream ss; ss << "A(init (unum " << mTeamUnum << ") (teamname " << mTeamName << "))"; mComm->PutOutput(ss.str().c_str());}void Soccer::CreateAgent(){ // use the create effector to setup the Sensors and Effectors GetLog()->Debug() << "creating agent\n"; mComm->PutOutput("A(create)");}void Soccer::Beam(const salt::Vector3f& position){ GetLog()->Debug() << "beaming [" << position[0] << " " << position[1] << " " << position[2] << "]\n"; stringstream ss; ss << "A(beam " << " " << position[0] << " " << position[1] << " " << position[2] << ")\n"; mComm->PutOutput(ss.str());}void Soccer::Kick(const float angle, const float power){ GetLog()->Debug() << "kicking Ball" << " angle=" << angle << " power=" << power << "\n"; stringstream ss; ss << "A(kick " << angle << " " << power << ")"; mComm->PutOutput(ss.str());}void Soccer::Drive(const salt::Vector3f& driveVec){ GetLog()->Debug() << "driving [" << driveVec[0] << " " << driveVec[1] << " " << driveVec[2] << "]\n"; if (driveVec == mDriveVec) { // no explicit change needed GetLog()->Debug() << "not changing drive vector\n"; return; } stringstream ss; ss << "A(drive" << " " << driveVec[0] << " " << driveVec[1] << " " << driveVec[2] << ")"; mComm->PutOutput(ss.str());}voidSoccer::PanTilt(float pan, float tilt){ GetLog()->Debug() << "panning+tilting [" << pan << " " << tilt << "]\n"; if (pan == 0 && tilt == 0) { // no explicit change needed GetLog()->Debug() << "not changing camera\n"; return; } stringstream ss; ss << "A(pantilt" << " " << pan << " " << tilt << ")"; mComm->PutOutput(ss.str());}void Soccer::Say(string message){ GetLog()->Debug() << "saying [" << message << "]\n"; stringstream ss; ss << "A(say" << " " << message << ")"; mComm->PutOutput(ss.str());}void Soccer::Think(){ GetLog()->Debug() << "received sensation " << mSensationCount << "\n"; switch (mSensationCount) { case 0: CreateAgent(); break; case 1: case 2: case 4: case 5: break; case 3: InitAgent(); break; default: Behave(); } ++mSensationCount; mComm->PutOutput(DoneThinkingMessage());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -