You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(153) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(48) |
Feb
(46) |
Mar
(12) |
Apr
(4) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
(263) |
Mar
(235) |
Apr
(66) |
May
(42) |
Jun
(270) |
Jul
(65) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:03
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/driveeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/driveeffector Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.la *.lo .deps .dirstamp .libs |
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:03
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/catcheffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/catcheffector Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.la *.lo .deps .dirstamp .libs |
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:03
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/gamestateaspect Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:03
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/fieldflag In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/fieldflag Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs Makefile Makefile.in initeffector.la |
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:02
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/beameffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/beameffector Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.la *.lo .deps .dirstamp .libs |
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:02
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/createeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/createeffector Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.la *.lo .deps .dirstamp .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:02
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/gamestateperceptor Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-03-07 11:07:02
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/ballstateaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/ballstateaspect Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.la *.lo .deps .dirstamp .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-03-07 11:06:58
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/ball In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/ball Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.la *.lo .deps .dirstamp .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-03-07 11:06:58
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/agentstate In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/agentstate Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs Makefile Makefile.in initeffector.la |
From: Oliver O. <fr...@us...> - 2007-03-07 11:06:58
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/agentstateperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4727/agentstateperceptor Added Files: Tag: projectx .cvsignore Log Message: soccer plugins from rcssserver3D --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:53
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/visionperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/visionperceptor Added Files: Tag: projectx visionperceptor.cpp visionperceptor.h visionperceptor_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: visionperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: visionperceptor.cpp,v 1.1.2.1 2007/03/07 10:39:45 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "visionperceptor.h" #include <zeitgeist/logserver/logserver.h> #include <oxygen/sceneserver/scene.h> #include <oxygen/sceneserver/transform.h> #include <soccer/soccerbase/soccerbase.h> using namespace zeitgeist; using namespace oxygen; using namespace boost; using namespace salt; VisionPerceptor::VisionPerceptor() : Perceptor(), mSenseMyPos(false), mAddNoise(true), mUseRandomNoise(true), mStaticSenseAxis(true) { // set predicate name SetPredicateName("See"); // set some default noise values SetNoiseParams(0.0965, 0.1225, 0.1480, 0.005); } VisionPerceptor::~VisionPerceptor() { mDistRng.reset(); mPhiRng.reset(); mThetaRng.reset(); } void VisionPerceptor::SetNoiseParams(float sigma_dist, float sigma_phi, float sigma_theta, float cal_error_abs) { mSigmaDist = sigma_dist; mSigmaPhi = sigma_phi; mSigmaTheta = sigma_theta; mCalErrorAbs = cal_error_abs; NormalRngPtr rng1(new salt::NormalRNG<>(0.0,sigma_dist)); mDistRng = rng1; NormalRngPtr rng2(new salt::NormalRNG<>(0.0,sigma_phi)); mPhiRng = rng2; NormalRngPtr rng3(new salt::NormalRNG<>(0.0,sigma_theta)); mThetaRng = rng3; salt::UniformRNG<float> rng4(-mCalErrorAbs,mCalErrorAbs); mError = salt::Vector3f(rng4(),rng4(),rng4()); } void VisionPerceptor::OnLink() { SoccerBase::GetTransformParent(*this,mTransformParent); SoccerBase::GetAgentState(*this, mAgentState); SoccerBase::GetActiveScene(*this,mActiveScene); } void VisionPerceptor::OnUnlink() { mDistRng.reset(); mPhiRng.reset(); mThetaRng.reset(); mTransformParent.reset(); mAgentState.reset(); mActiveScene.reset(); } void VisionPerceptor::AddNoise(bool add_noise) { mAddNoise = add_noise; } void VisionPerceptor::UseRandomNoise(bool random_noise) { mUseRandomNoise = random_noise; } void VisionPerceptor::SetStaticSenseAxis(bool static_axis) { mStaticSenseAxis = static_axis; } bool VisionPerceptor::ConstructInternal() { mRay = shared_static_cast<oxygen::RayCollider> (GetCore()->New("oxygen/RayCollider")); if (mRay.get() == 0) { GetLog()->Error() << "Error: (VisionPerceptor) cannot create Raycollider. " << "occlusion check disabled\n"; } return true; } void VisionPerceptor::SetupVisibleObjects(TObjectList& visibleObjects) { TLeafList objectList; mActiveScene->ListChildrenSupportingClass<ObjectState>(objectList, true); salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos(); for (TLeafList::iterator i = objectList.begin(); i != objectList.end(); ++i) { ObjectData od; od.mObj = shared_static_cast<ObjectState>(*i); if (od.mObj.get() == 0) { GetLog()->Error() << "Error: (VisionPerceptor) skipped: " << (*i)->GetName() << "\n"; continue; // this should never happen } shared_ptr<Transform> j = od.mObj->GetTransformParent(); if (j.get() == 0) { continue; // this should never happen } od.mRelPos = j->GetWorldTransform().Pos() - myPos; od.mDist = od.mRelPos.Length(); visibleObjects.push_back(od); } } void VisionPerceptor::AddSense(oxygen::Predicate& predicate, ObjectData& od) const { ParameterList& element = predicate.parameter.AddList(); element.AddValue(od.mObj->GetPerceptName()); // if(od.mObj->GetPerceptName() == "Player") if(od.mObj->GetPerceptName() == "P") { ParameterList player; player.AddValue(std::string("team")); player.AddValue (std::string (od.mObj->GetPerceptName(ObjectState::PT_Player) ) ); element.AddValue(player); } if (!od.mObj->GetID().empty()) { ParameterList id; id.AddValue(std::string("id")); id.AddValue(od.mObj->GetID()); element.AddValue(id); } ParameterList& position = element.AddList(); position.AddValue(std::string("pol")); position.AddValue(od.mDist); position.AddValue(od.mTheta); position.AddValue(od.mPhi); } void VisionPerceptor::ApplyNoise(ObjectData& od) const { if (mAddNoise) { if (mUseRandomNoise) { od.mDist += (*(mDistRng.get()))() * od.mDist / 100.0; od.mTheta += (*(mThetaRng.get()))(); od.mPhi += (*(mPhiRng.get()))(); } else { /* This gives a constant random error throughout the whole * match. This behavior was not intended and is a bug and * not an intended feature. * It was kept in the simulator because I discovered this * bug only shortly before the competition. *sigh* oliver */ od.mDist += salt::NormalRNG<>(0.0,mSigmaDist)(); od.mTheta += salt::NormalRNG<>(0.0,mSigmaTheta)(); od.mPhi += salt::NormalRNG<>(0.0,mSigmaPhi)(); } } } bool VisionPerceptor::StaticAxisPercept(boost::shared_ptr<PredicateList> predList) { Predicate& predicate = predList->AddPredicate(); predicate.name = mPredicateName; predicate.parameter.Clear(); TTeamIndex ti = mAgentState->GetTeamIndex(); salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos(); TObjectList visibleObjects; SetupVisibleObjects(visibleObjects); for (std::list<ObjectData>::iterator i = visibleObjects.begin(); i != visibleObjects.end(); ++i) { ObjectData& od = (*i); od.mRelPos = SoccerBase::FlipView(od.mRelPos, ti); if (mAddNoise) { od.mRelPos += mError; } if ( (od.mRelPos.Length() <= 0.1) || (CheckOcclusion(myPos,od)) ) { // object is occluded or too close continue; } // theta is the angle in the X-Y (horizontal) plane od.mTheta = salt::gRadToDeg(salt::gArcTan2(od.mRelPos[1], od.mRelPos[0])); // latitude od.mPhi = 90.0 - salt::gRadToDeg(salt::gArcCos(od.mRelPos[2]/od.mDist)); // make some noise ApplyNoise(od); // generate a sense entry AddSense(predicate,od); } if (mSenseMyPos) { Vector3f sensedMyPos = SoccerBase::FlipView(myPos, ti); ParameterList& element = predicate.parameter.AddList(); element.AddValue(std::string("mypos")); element.AddValue(sensedMyPos[0]); element.AddValue(sensedMyPos[1]); element.AddValue(sensedMyPos[2]); } return true; } bool VisionPerceptor::DynamicAxisPercept(boost::shared_ptr<PredicateList> predList) { Predicate& predicate = predList->AddPredicate(); predicate.name = mPredicateName; predicate.parameter.Clear(); TTeamIndex ti = mAgentState->GetTeamIndex(); const Vector3f& up = mTransformParent->GetWorldTransform().Up(); // calc the percptors angle in the horizontal plane double fwTheta = gNormalizeRad(Vector2f(up[0],up[1]).GetAngleRad()); // calc the perceptors angle in the vertical plane double fwPhi = gNormalizeRad(Vector2f(up[0],up[2]).GetAngleRad()); TObjectList visibleObjects; SetupVisibleObjects(visibleObjects); for (std::list<ObjectData>::iterator i = visibleObjects.begin(); i != visibleObjects.end(); ++i) { ObjectData& od = (*i); od.mRelPos = SoccerBase::FlipView(od.mRelPos, ti); if (mAddNoise) { od.mRelPos += mError; } if (od.mRelPos.Length() <= 0.1) { // object is too close continue; } // theta is the angle in horizontal plane, with fwAngle as 0 degree od.mTheta = gRadToDeg(gNormalizeRad( Vector2f(od.mRelPos[0],od.mRelPos[1]).GetAngleRad() - fwTheta )); // latitude with fwPhi as 0 degreee od.mPhi = gRadToDeg(gNormalizeRad( Vector2f(od.mRelPos[0],od.mRelPos[2]).GetAngleRad() - fwPhi )); // make some noise ApplyNoise(od); // generate a sense entry AddSense(predicate,od); } return true; } bool VisionPerceptor::Percept(boost::shared_ptr<PredicateList> predList) { if ( (mTransformParent.get() == 0) || (mActiveScene.get() == 0) || (mAgentState.get() == 0) ) { return false; } return mStaticSenseAxis ? StaticAxisPercept(predList) : DynamicAxisPercept(predList); } bool VisionPerceptor::CheckOcclusion(const Vector3f& my_pos, const ObjectData& od) const { // (occlusion test disabled for now, every object is visible) return false; // if (mRay.get() == 0) return; // // sort objects wrt their distance // visible_objects.sort(); // // check visibility // std::list<ObjectData>::iterator start = visible_objects.begin(); // ++start; // // this is going to be expensive now: to check occlusion of an object, // // we have to check all closer objects. For n objects, we have to // // check at most n*(n-1)/2 objects. // for (std::list<ObjectData>::iterator i = start; // i != visible_objects.end(); ++i) // { // for (std::list<ObjectData>::iterator j = visible_objects.begin(); // j != i; ++j) // { // // cast ray from camera to object (j) // mRay->SetParams(j->mRelPos,my_pos,j->mDist); // dContactGeom contact; // shared_ptr<Collider> collider = shared_static_cast<Collider> // (i->mObj->GetChildSupportingClass("Collider")); // if (mRay->Intersects(collider)) // { // j->mVisible = false; // j = i; // } // } // } } void VisionPerceptor::SetSenseMyPos(bool sense) { mSenseMyPos = sense; } --- NEW FILE: visionperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: visionperceptor.h,v 1.1.2.1 2007/03/07 10:39:45 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef VISIONPERCEPTOR_H #define VISIONPERCEPTOR_H #include <salt/random.h> #include <oxygen/agentaspect/perceptor.h> #include <oxygen/physicsserver/raycollider.h> #include <oxygen/sceneserver/sceneserver.h> #include <oxygen/sceneserver/transform.h> #include <soccer/agentstate/agentstate.h> class VisionPerceptor : public oxygen::Perceptor { protected: typedef boost::shared_ptr<salt::NormalRNG<> > NormalRngPtr; struct ObjectData { boost::shared_ptr<ObjectState> mObj; float mTheta; // angle in the X-Y (horizontal) plane float mPhi; // latitude angle float mDist; // distance between perceptor and object salt::Vector3f mRelPos; ObjectData& operator=(const ObjectData& rhs) { mObj = rhs.mObj; mRelPos = rhs.mRelPos; mTheta = rhs.mTheta; mPhi = rhs.mPhi; mDist = rhs.mDist; } int operator==(const ObjectData& rhs) const { return mDist == rhs.mDist; } int operator<(const ObjectData& rhs) const { return mDist < rhs.mDist; } }; typedef std::list<ObjectData> TObjectList; public: VisionPerceptor(); virtual ~VisionPerceptor(); //! \return true, if valid data is available and false otherwise. bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); /** Set the noise parameters of the vision perceptor. * * This will always create new calibration error values. * The random noise added each step is normally distributed around 0.0. * The (fixed) calibration error is calculated once for each axis. It * is uniformly distributed between -cal_error_abs and cal_error_abs and * added to the "camera" coordinates. * * \param sigma_dist the sigma for the distance error distribution * \param sigma_phi the sigma for the horizontal angle error distribution * \param sigma_theta the sigma for the latitudal angle error distribution * \param cal_error_abs absolute value of the maximum calibration error * along each axis. */ void SetNoiseParams(float sigma_dist, float sigma_phi, float sigma_theta, float cal_error_abs); //! Turn sensing of agent position on/off void SetSenseMyPos(bool sense); /** Turn noise off/on. \param add_noise flag if noise should be used at all. */ void AddNoise(bool add_noise); /** Turn randomization off/on. \param random_noise flag if the measurement noise is randomized each step. */ void UseRandomNoise(bool random_noise); //! Turn senses relative to the X-axis of the team off/on void SetStaticSenseAxis(bool static_axis); protected: /** constructs the internal ray collider */ virtual bool ConstructInternal(); /** prepares a list of visible objects */ void SetupVisibleObjects(TObjectList& visibleObjects); /** Percept implementation for a static relative axis */ bool StaticAxisPercept(boost::shared_ptr<oxygen::PredicateList> predList); /** Percept implementation relative to the current orientation of the VisionPerceptor node */ bool DynamicAxisPercept(boost::shared_ptr<oxygen::PredicateList> predList); /** Checks if the given object is occluded, seen from from my_pos */ bool CheckOcclusion(const salt::Vector3f& my_pos, const ObjectData& od) const; /** constructs a sense entry for the given object in the given predicate*/ void AddSense(oxygen::Predicate& predicate, ObjectData& od) const; /** applies noise to the setup ObjectData */ void ApplyNoise(ObjectData& od) const; virtual void OnLink(); virtual void OnUnlink(); protected: //! vision calibration error salt::Vector3f mError; //! true, if the absolute position of the agent is sensed. bool mSenseMyPos; //! sigma for random measurement error (distance) float mSigmaDist; //! sigma for random measurement error (horizontal angle) float mSigmaTheta; //! sigma for random measurement error (latitudal angle) float mSigmaPhi; //! absolute maximum value of the calibration error float mCalErrorAbs; //! flag if we should noisify the data bool mAddNoise; //! flag if the error should be randomized each step bool mUseRandomNoise; /** flag if the senses are always relative to the X-axis of the team, default true */ bool mStaticSenseAxis; //! ray collider to check occlusion boost::shared_ptr<oxygen::RayCollider> mRay; //! random number generator for distance errors NormalRngPtr mDistRng; //! random number generator for angle errors NormalRngPtr mThetaRng; //! random number generator for angle errors NormalRngPtr mPhiRng; boost::shared_ptr<oxygen::Scene> mActiveScene; //! a reference to the next transorm parent boost::shared_ptr<oxygen::Transform> mTransformParent; //! a reference to the scene server boost::shared_ptr<oxygen::SceneServer> mSceneServer; //! a reference to the agent state boost::shared_ptr<AgentState> mAgentState; }; DECLARE_CLASS(VisionPerceptor); #endif //VISIONPERCEPTOR_H --- NEW FILE: visionperceptor_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: visionperceptor_c.cpp,v 1.1.2.1 2007/03/07 10:39:45 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "visionperceptor.h" using namespace boost; using namespace oxygen; using namespace std; FUNCTION(VisionPerceptor,setNoiseParams) { float inDist; float inPhi; float inTheta; float inErrorAbs; if ( (in.GetSize() != 4) || (! in.GetValue(in[0],inDist)) || (! in.GetValue(in[1],inPhi)) || (! in.GetValue(in[2],inTheta)) || (! in.GetValue(in[3],inErrorAbs)) ) { return false; } obj->SetNoiseParams(inDist,inPhi,inTheta,inErrorAbs); return true; } FUNCTION(VisionPerceptor,addNoise) { bool inAddNoise; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inAddNoise)) ) { return false; } obj->AddNoise(inAddNoise); return true; } FUNCTION(VisionPerceptor,useRandomNoise) { bool inRandomNoise; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inRandomNoise)) ) { return false; } obj->UseRandomNoise(inRandomNoise); return true; } FUNCTION(VisionPerceptor,setSenseMyPos) { bool inSenseMyPos; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inSenseMyPos)) ) { return false; } obj->SetSenseMyPos(inSenseMyPos); return true; } FUNCTION(VisionPerceptor,setStaticSenseAxis) { bool inStaticAxis; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inStaticAxis)) ) { return false; } obj->SetStaticSenseAxis(inStaticAxis); return true; } void CLASS(VisionPerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); DEFINE_FUNCTION(setNoiseParams); DEFINE_FUNCTION(addNoise); DEFINE_FUNCTION(useRandomNoise); DEFINE_FUNCTION(setSenseMyPos); DEFINE_FUNCTION(setStaticSenseAxis); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:52
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/trainercommandparser In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/trainercommandparser Added Files: Tag: projectx trainercommandparser.cpp trainercommandparser.h trainercommandparser_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: trainercommandparser_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of the trainer for rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Parser that gets a list of predicates and interprets the trainer commands contained in them */ #include "trainercommandparser.h" void CLASS(TrainerCommandParser)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: trainercommandparser.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of the trainer for rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Parser that gets a list of predicates and interprets the trainer commands contained in them */ #include <oxygen/physicsserver/body.h> #include <soccerbase/soccerbase.h> #include <agentstate/agentstate.h> #include <soccertypes.h> #include <gamestateaspect/gamestateaspect.h> #include "trainercommandparser.h" using namespace std; using namespace boost; using namespace zeitgeist; using namespace oxygen; TrainerCommandParser::TrainerCommandParser() : MonitorCmdParser() { // setup command map mCommandMap["agent"] = CT_PLAYER; mCommandMap["ball"] = CT_BALL; mCommandMap["playMode"] = CT_PLAYMODE; mCommandMap["dropBall"] = CT_DROP_BALL; mCommandMap["kickOff"] = CT_KICK_OFF; mCommandMap["getAck"] = CT_ACK; // setup team index map // Originally team sides were "L","R" and "N" // But this seems to be unused // ParseKickOffCommand depends on the long names mTeamIndexMap["Left"] = TI_LEFT; mTeamIndexMap["Right"] = TI_RIGHT; mTeamIndexMap["None"] = TI_NONE; // setup play mode map mPlayModeMap[STR_PM_BeforeKickOff] = PM_BeforeKickOff; mPlayModeMap[STR_PM_KickOff_Left] = PM_KickOff_Left; mPlayModeMap[STR_PM_KickOff_Right] = PM_KickOff_Right; mPlayModeMap[STR_PM_PlayOn] = PM_PlayOn; mPlayModeMap[STR_PM_KickIn_Left] = PM_KickIn_Left; mPlayModeMap[STR_PM_KickIn_Right] = PM_KickIn_Right; mPlayModeMap[STR_PM_CORNER_KICK_LEFT] = PM_CORNER_KICK_LEFT; mPlayModeMap[STR_PM_CORNER_KICK_RIGHT] = PM_CORNER_KICK_RIGHT; mPlayModeMap[STR_PM_GOAL_KICK_LEFT] = PM_GOAL_KICK_LEFT; mPlayModeMap[STR_PM_GOAL_KICK_RIGHT] = PM_GOAL_KICK_RIGHT; mPlayModeMap[STR_PM_OFFSIDE_LEFT] = PM_OFFSIDE_LEFT; mPlayModeMap[STR_PM_OFFSIDE_RIGHT] = PM_OFFSIDE_RIGHT; mPlayModeMap[STR_PM_FREE_KICK_LEFT] = PM_FREE_KICK_LEFT; mPlayModeMap[STR_PM_FREE_KICK_RIGHT] = PM_FREE_KICK_RIGHT; mPlayModeMap[STR_PM_Goal_Left] = PM_Goal_Left; mPlayModeMap[STR_PM_Goal_Right] = PM_Goal_Right; mPlayModeMap[STR_PM_GameOver] = PM_GameOver; mGetAck = false; } TrainerCommandParser::~TrainerCommandParser() { } bool TrainerCommandParser::SendAck(std::string &reply) { if (!mGetAck) { return false; } reply = "best"; mGetAck= false; return true; } void TrainerCommandParser::OnLink() { // we need the SexpParser to generate the predicates // from S-Expressions mSexpParser = shared_dynamic_cast<oxygen::BaseParser>(GetCore()->New("SexpParser")); if (mSexpParser.get() == 0) { GetLog()->Error() << "ERROR: (TrainerCommnadParser) failed to create SexpParser\n"; return; } } void TrainerCommandParser::OnUnlink() { mSexpParser.reset(); } void TrainerCommandParser::ParseMonitorMessage(const std::string& data) { if (mSexpParser.get() == 0) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get SexpParser\n"; return; } shared_ptr<PredicateList> predList = mSexpParser->Parse(data); ParsePredicates(*predList); } void TrainerCommandParser::ParsePredicates(oxygen::PredicateList & predList) { for ( PredicateList::TList::const_iterator iter = predList.begin(); iter != predList.end(); ++iter ) { const Predicate & predicate = (*iter); if (! ParsePredicate(predicate)) { continue; } } } bool TrainerCommandParser::ParsePredicate(const oxygen::Predicate & predicate) { SoccerBase::GetGameState(*this,mGameState); SoccerBase::GetSoccerRuleAspect(*this,mSoccerRule); // lookup the command type corresponding to the predicate name TCommandMap::iterator iter = mCommandMap.find(predicate.name); if (iter == mCommandMap.end()) { return false; } switch ((*iter).second) { case CT_PLAYER: ParsePlayerCommand(predicate); break; case CT_BALL: ParseBallCommand(predicate); break; case CT_PLAYMODE: ParsePlayModeCommand(predicate); break; case CT_DROP_BALL: mSoccerRule->DropBall(); break; case CT_KICK_OFF: ParseKickOffCommand(predicate); break; case CT_ACK: { mGetAck=true; // Predicate::Iterator ackParam(predicate); // ++ackParam; /* if (! predicate.GetValue(ackParam, mAckString)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get mAckString\n"; return false; }*/ break; } default: return false; } return true; } void TrainerCommandParser::ParsePlayerCommand(const oxygen::Predicate & predicate) { Predicate::Iterator unumParam(predicate); int unum; // extract unum if (predicate.FindParameter(unumParam, "unum")) { if (! predicate.GetValue(unumParam, unum)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get unum\n"; return; } } string team; TTeamIndex idx; Predicate::Iterator teamParam(predicate); // extract side if (predicate.FindParameter(teamParam, "team")) { if (! predicate.GetValue(teamParam, team)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get team name\n"; return; } idx = mTeamIndexMap[team]; } Predicate::Iterator posParam(predicate); if (predicate.FindParameter(posParam, "pos")) { salt::Vector3f pos; // extract position vector if (! predicate.GetValue(posParam, pos)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get agent pos\n"; return; } shared_ptr<Body> body; if (SoccerBase::GetAgentBody(*this, idx, unum, body)) { // set new velocity in the body body->SetPosition(pos); } else { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get agent body\n"; return; } } Predicate::Iterator velParam(predicate); if (predicate.FindParameter(velParam, "vel")) { salt::Vector3f vel; // extract velocity vector if (! predicate.GetValue(velParam, vel)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get agent vel\n"; return; } shared_ptr<Body> body; if (SoccerBase::GetAgentBody(*this, idx, unum, body)) { // set new velocity in the body body->SetVelocity(vel); body->SetAngularVelocity(salt::Vector3f(0.0f,0.0f,0.0f)); } else { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get agent body\n"; return; } } Predicate::Iterator batParam(predicate); if (predicate.FindParameter(batParam, "battery")) { double battery; // extract battery value if (! predicate.GetValue(batParam, battery)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get battery value\n"; return; } shared_ptr<AgentState> agentState; // get agent state if (SoccerBase::GetAgentState(*this, idx, unum, agentState)) { // set new battery agentState->SetBattery(battery); } else { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get agent state\n"; return; } } Predicate::Iterator tempParam(predicate); if (predicate.FindParameter(tempParam, "temperature")) { float temperature; // extract temperature value if (! predicate.GetValue(tempParam, temperature)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get temperatur value\n"; return; } shared_ptr<AgentState> agentState; // get agent state if (SoccerBase::GetAgentState(*this, idx, unum, agentState)) { // set new temperature agentState->SetBattery(temperature); } else { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get agent state\n"; return; } } } void TrainerCommandParser::ParseBallCommand(const oxygen::Predicate& predicate) { Predicate::Iterator posParam(predicate); if (predicate.FindParameter(posParam, "pos")) { salt::Vector3f pos; // extract position vector if (! predicate.GetValue(posParam, pos)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get ball pos\n"; return; } shared_ptr<Body> body; if (SoccerBase::GetBallBody(*this, body)) { // set new position in the body body->SetPosition(pos); } else { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get ball body\n"; return; } } Predicate::Iterator velParam(predicate); if (predicate.FindParameter(velParam, "vel")) { salt::Vector3f vel; // extract velocity vector if (! predicate.GetValue(velParam, vel)) { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get ball vel\n"; return; } shared_ptr<Body> body; if (SoccerBase::GetBallBody(*this, body)) { // set new velocity in the body body->SetVelocity(vel); body->SetAngularVelocity(salt::Vector3f(0.0f,0.0f,0.0f)); } else { GetLog()->Error() << "(TrainerCommandParser) ERROR: can't get ball body\n"; return; } } } void TrainerCommandParser::ParsePlayModeCommand(const oxygen::Predicate& predicate) { Predicate::Iterator pmParam(predicate); string mode; if (predicate.GetValue(pmParam,mode)) { TPlayModeMap::const_iterator playmode = mPlayModeMap.find(mode); if (playmode != mPlayModeMap.end()) { mGameState->SetPlayMode(playmode->second); } else { GetLog()->Debug() << "(TrainerCommandParser) ERROR: an unknown playmode" << mode << " was passed\n"; } } else { GetLog()->Debug() << "(TrainerCommandParser) ERROR: could not parse playmode " << mode << "\n"; } } void TrainerCommandParser::ParseKickOffCommand(const oxygen::Predicate& predicate) { Predicate::Iterator koParam(predicate); string team; if (predicate.GetValue(koParam,team)) { TTeamIndexMap::const_iterator kickoffteam = mTeamIndexMap.find(team); if (kickoffteam != mTeamIndexMap.end()) { if (mGameState.get() == 0) { GetLog()->Error() << "(TrainerCommandParser) ERROR " << "no GameStateAspect found, cannot kick off\n"; } else { mGameState->KickOff(kickoffteam->second); } } else { GetLog()->Error() << "(TrainerCommandParser) ERROR: unknown team" << team << "\n"; } } else { GetLog()->Debug() << "(TrainerCommandParser) ERROR: could not parse team " << team << "\n"; } } --- NEW FILE: trainercommandparser.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of the trainer for rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Parser that gets a list of predicates and interprets the trainer commands contained in them */ #ifndef TRAINERCOMMANDPARSER_H #define TRAINERCOMMANDPARSER_H #include <string> #include <oxygen/monitorserver/monitorcmdparser.h> #include <oxygen/gamecontrolserver/predicate.h> #include <oxygen/gamecontrolserver/baseparser.h> #include <salt/vector.h> #include <soccer/soccertypes.h> #include <soccer/soccerruleaspect/soccerruleaspect.h> class TrainerCommandParser : public oxygen::MonitorCmdParser { public: enum ECommandType { CT_PLAYER, CT_BALL, CT_PLAYMODE, CT_DROP_BALL, CT_KICK_OFF, CT_ACK }; typedef std::map<std::string, ECommandType> TCommandMap; typedef std::map<std::string, TTeamIndex> TTeamIndexMap; // mapping from string to TPlayMode typedef std::map<std::string, TPlayMode> TPlayModeMap; public: TrainerCommandParser(); virtual ~TrainerCommandParser(); bool SendAck(std::string &reply); /** This function will be called be called from the monitor server implementation to parse any command strings received from the monitor client process */ virtual void ParseMonitorMessage(const std::string& data); virtual void OnLink(); virtual void OnUnlink(); protected: /** parses the list of predicates; returns true on success */ void ParsePredicates(oxygen::PredicateList& predList); /** parses the given predicate and calls one of the specialized parse methods given below depending the predicate name; returns true if successful */ bool ParsePredicate(const oxygen::Predicate & predicate); /** parses and executes the player command contained in the given predicate */ void ParsePlayerCommand(const oxygen::Predicate & predicate); /** parses and executes the ball command contained in the given predicate */ void ParseBallCommand(const oxygen::Predicate & predicate); /** parses and executes the play mode command contained in the given predicate */ void ParsePlayModeCommand(const oxygen::Predicate & predicate); /** parses and executes the kick off command contained in the given predicate */ void ParseKickOffCommand(const oxygen::Predicate & predicate); protected: TCommandMap mCommandMap; TTeamIndexMap mTeamIndexMap; TPlayModeMap mPlayModeMap; //! cached reference for the gamestate aspect boost::shared_ptr<GameStateAspect> mGameState; //! cached reference for the soccer rule aspect boost::shared_ptr<SoccerRuleAspect> mSoccerRule; //! the parser used to create the PredicateList boost::shared_ptr<oxygen::BaseParser> mSexpParser; bool mGetAck; std::string mAckString; }; DECLARE_CLASS(TrainerCommandParser); #endif // TRAINERCOMMANDPARSER_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:51
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/soccerruleaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/soccerruleaspect Added Files: Tag: projectx soccerruleaspect.cpp soccerruleaspect.h soccerruleaspect_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: soccerruleaspect.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccerruleaspect.h,v 1.1.2.1 2007/03/07 10:39:44 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef SOCCERRULEASPECT_H #define SOCCERRULEASPECT_H #include <soccer/soccercontrolaspect/soccercontrolaspect.h> #include <soccer/soccertypes.h> class GameStateAspect; class BallStateAspect; class AgentState; namespace salt { class AABB2; } namespace oxygen { class Body; class AgentAspect; } class SoccerRuleAspect : public SoccerControlAspect { public: typedef std::list<boost::shared_ptr<AgentState> > TAgentStateList; public: SoccerRuleAspect(); virtual ~SoccerRuleAspect(); /** called during the update of the GameControlServer to allow the ControlAspect to perform any necessary checks. */ virtual void Update(float deltaTime); /** Drop ball at its current position and move all players away by the free kick radius. */ void DropBall(); /** Drop ball at a given position and move all players away from that position by the free kick radius. \param pos position where the ball should be dropped- */ void DropBall(salt::Vector3f pos); /** broadcast a said message to all players \param message said message- \param pos positon of the player- \param num uniform number- \param idx team index- */ void Broadcast(const std::string& message, const salt::Vector3f& pos, int number, TTeamIndex idx); /** Move all the players from a team which are too close to pos away from pos, with exception of the specified agent. \param pos the center of the area to be checked \param radius the radius of the area to be checked \param min_dist the minimum distance players will be moved away from pos \param idx the team which should be checked. If idx is TI_NONE, nothing will happen. Players are moved towards their side of the field. If they would leave the playing field, they are moved towards the X axis (the line from the left goal to the right goal). */ void ClearPlayersWithException(const salt::Vector3f& pos, float radius, float min_dist, TTeamIndex idx, boost::shared_ptr<AgentState> agentState); protected: /** rereads the current soccer script values */ virtual void UpdateCachedInternal(); /** set up the reference to the ball and field collider */ virtual void OnLink(); /** reset the reference to the ball and field recorder */ virtual void OnUnlink(); /** checks if the time for one game half has passed */ void CheckTime(); /** updates the RuleAspect during BeforeKickOff mode */ void UpdateBeforeKickOff(); /** updates the RuleAspect during KickOff mode */ void UpdateKickOff(TTeamIndex idx = TI_NONE); /** updates the RuleAspect during KickIn mode */ void UpdateKickIn(TTeamIndex ti = TI_NONE); /** updates the RuleAspect during Goal Kick mode */ void UpdateGoalKick(TTeamIndex ti = TI_NONE); /** updates the RuleAspect during Corner Kick mode */ void UpdateCornerKick(TTeamIndex ti = TI_NONE); /** update the RuleAspect during PlayOn mode */ void UpdatePlayOn(); /** update the RuleAspect during Goal mode */ void UpdateGoal(); /** update the RuleAspect during Offside mode */ void UpdateOffside(TTeamIndex ti = TI_NONE); /** update the RuleAspect when the match is over */ void UpdateGameOver(); /** checks if the ball is not on the playing field and puts it back to its last valid position. returns true if the ball left the field */ bool CheckBallLeftField(); /** Checks if the ball is in one of the two goals and scores the appropriate team. \return true if the ball was in one of the goals. */ bool CheckGoal(); /** checks if the assistant referee should raise the flag for offside */ bool CheckOffside(); /** moves the ball to pos setting its linear and angular velocity to 0 */ void MoveBall(const salt::Vector3f& pos); /** Moves an agent to pos setting its linear and angular velocity to 0. * \param agent_body a reference to the agent body * \param pos the position where the agent should be */ void MoveAgent(boost::shared_ptr<oxygen::Body> agent_body, const salt::Vector3f& pos); /** Move all the players from a team which are too close to pos away from pos. \param pos the center of the area to be checked \param radius the radius of the area to be checked \param min_dist the minimum distance players will be moved away from pos \param idx the team which should be checked. If idx is TI_NONE, nothing will happen. Players are moved towards their side of the field. If they would leave the playing field, they are moved towards the X axis (the line from the left goal to the right goal). */ void ClearPlayers(const salt::Vector3f& pos, float radius, float min_dist, TTeamIndex idx); /** Move all the players from a team inside an rectangular area away from that area. \param box the rectangular area to be checked \param min_dist the minimum distance players will be moved away from box \param idx the team which should be checked. If idx is TI_NONE, nothing will happen. Players are moved towards their side of the field. */ void ClearPlayers(const salt::AABB2& box, float min_dist, TTeamIndex idx); protected: /** reference to the body node of the Ball */ boost::shared_ptr<oxygen::Body> mBallBody; /** reference to the GameStateAspect */ boost::shared_ptr<GameStateAspect> mGameState; /** reference to the BallStateAspect */ boost::shared_ptr<BallStateAspect> mBallState; /** the radius of the Ball */ float mBallRadius; /** the length of the pause after a goal */ float mGoalPauseTime; /** the length of the pause after the ball left the field */ float mKickInPauseTime; /** the length of one game half */ float mHalfTime; /** the time we wait before dropping the ball in play modes where only one team can touch the ball */ float mDropBallTime; /** the point above the ground, where the ball left the field */ salt::Vector3f mLastValidBallPos; /** the field length (in meters) */ float mFieldLength; /** the field width (in meters) */ float mFieldWidth; /** the goal width (in meters) */ float mGoalWidth; /** the point on the field where we do the kick in, free kick etc. */ salt::Vector3f mFreeKickPos; /** the distance opponents have to keep during free kicks, kick ins etc. */ float mFreeKickDist; /** the (least) distance opponents will be moved away if they are to close during a free kick, kick in and situations like that. */ float mFreeKickMoveDist; /** flag if the simulator should do the kick off automatically after the agent */ bool mAutomaticKickOff; /** time to wait until we kick off automatically */ float mWaitBeforeKickOff; /** flag if we want to play only one half of the match */ bool mSingleHalfTime; // areas where opponents are not allowed in certain play modes /** bounding box for the right half of the field */ salt::AABB2 mRightHalf; /** bounding box for the left half of the field */ salt::AABB2 mLeftHalf; /** bounding box for the right penalty area */ salt::AABB2 mRightPenaltyArea; /** bounding box for the left penalty area */ salt::AABB2 mLeftPenaltyArea; /** say message size max limit */ int mSayMsgSize; /** max distance that player can hear a message */ float mAudioCutDist; /** list of players that are in offside position */ std::vector<int> mInOffsideLeftPlayers; std::vector<int> mInOffsideRightPlayers; boost::shared_ptr<oxygen::AgentAspect> mPreLastCollidingAgent; /** first colliding player in playon mode */ bool mFirstCollidingAgent; /** if agents don't pass don't worry about offside */ bool mNotOffside; /** if last mode was not playon, clear offside lists*/ bool mLastModeWasPlayOn; /** use offside law */ bool mUseOffside; }; DECLARE_CLASS(SoccerRuleAspect); #endif // SOCCERRULEASPECT_H --- NEW FILE: soccerruleaspect.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccerruleaspect.cpp,v 1.1.2.1 2007/03/07 10:39:43 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software [...1131 lines suppressed...] { if (pos[0] - dist < -mFieldLength/2.0) { new_pos[1] = pos[1] < 0 ? pos[1] + dist : pos[1] - dist; } else { new_pos[0] = pos[0] - dist; } } else { if (pos[0] + dist > mFieldLength/2.0) { new_pos[1] = pos[1] < 0 ? pos[1] + dist : pos[1] - dist; } else { new_pos[0] = pos[0] + dist; } } new_pos[2] = 1.0; MoveAgent(agent_body, new_pos); } } } --- NEW FILE: soccerruleaspect_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccerruleaspect_c.cpp,v 1.1.2.1 2007/03/07 10:39:44 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "soccerruleaspect.h" using namespace oxygen; void CLASS(SoccerRuleAspect)::DefineClass() { DEFINE_BASECLASS(SoccerControlAspect); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:47
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/soccercontrolaspect In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/soccercontrolaspect Added Files: Tag: projectx soccercontrolaspect.cpp soccercontrolaspect.h soccercontrolaspect_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: soccercontrolaspect.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccercontrolaspect.cpp,v 1.1.2.1 2007/03/07 10:39:43 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "soccercontrolaspect.h" #include <zeitgeist/logserver/logserver.h> #include <zeitgeist/scriptserver/scriptserver.h> #include <oxygen/sceneserver/scene.h> #include <oxygen/physicsserver/recorderhandler.h> #include <oxygen/physicsserver/body.h> #include <soccer/ball/ball.h> using namespace oxygen; using namespace boost; using namespace std; using namespace salt; SoccerControlAspect::SoccerControlAspect() : ControlAspect() { } SoccerControlAspect::~SoccerControlAspect() { } void SoccerControlAspect::OnLink() { shared_ptr<Scene> scene = GetActiveScene(); if (scene.get() == 0) { GetLog()->Error() << "(SoccerControlAspect) found no active scene node\n"; return; } mScenePath = scene->GetFullPath(); } shared_ptr<RecorderHandler> SoccerControlAspect::GetBallRecorder() { shared_ptr<RecorderHandler> node = shared_dynamic_cast<RecorderHandler> (GetCore()->Get(mScenePath + "Ball/geometry/recorder")); if (node.get() == 0) { GetLog()->Error() << "(SoccerControlAspect) found no ball collision recorder\n"; } return node; } shared_ptr<RecorderHandler> SoccerControlAspect::GetFieldRecorder() { shared_ptr<RecorderHandler> node = shared_dynamic_cast<RecorderHandler> (GetCore()->Get(mScenePath + "FieldBox/recorder")); if (node.get() == 0) { GetLog()->Error() << "(SoccerControlAspect) found no field collision recorder\n"; } return node; } shared_ptr<RecorderHandler> SoccerControlAspect::GetLeftGoalRecorder() { shared_ptr<RecorderHandler> node = shared_dynamic_cast<RecorderHandler> (GetCore()->Get(mScenePath + "GoalBoxL/recorder")); if (node.get() == 0) { GetLog()->Error() << "(SoccerControlAspect) found no left goal collision recorder\n"; } return node; } shared_ptr<RecorderHandler> SoccerControlAspect::GetRightGoalRecorder() { shared_ptr<RecorderHandler> node = shared_dynamic_cast<RecorderHandler> (GetCore()->Get(mScenePath + "GoalBoxR/recorder")); if (node.get() == 0) { GetLog()->Error() << "(SoccerControlAspect) found no right goal collision recorder\n"; } return node; } --- NEW FILE: soccercontrolaspect_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccercontrolaspect_c.cpp,v 1.1.2.1 2007/03/07 10:39:43 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "soccercontrolaspect.h" using namespace oxygen; void CLASS(SoccerControlAspect)::DefineClass() { DEFINE_BASECLASS(oxygen/ControlAspect); } --- NEW FILE: soccercontrolaspect.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccercontrolaspect.h,v 1.1.2.1 2007/03/07 10:39:43 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef SOCCERCONTROLASPECT_H #define SOCCERCONTROLASPECT_H #include <oxygen/controlaspect/controlaspect.h> #include <soccer/soccertypes.h> class GameStateAspect; class BallStateAspect; class Ball; namespace oxygen { class RecorderHandler; class Body; } /** \class SoccerControlAspect is the base class for all ControlAspects implemented in the soccer bundle. It serves as a place to collect utility functions and type definitions common to all ControlAspects in the soccer simulation */ class SoccerControlAspect : public oxygen::ControlAspect { public: SoccerControlAspect(); virtual ~SoccerControlAspect(); /** returns a reference to the RecorderHandler registered to the Ball node */ boost::shared_ptr<oxygen::RecorderHandler> GetBallRecorder(); /** returns a reference to the RecorderHandler registered to the FieldBox */ boost::shared_ptr<oxygen::RecorderHandler> GetFieldRecorder(); /** returns a reference to the RecorderHandler registered to the left goal box */ boost::shared_ptr<oxygen::RecorderHandler> GetLeftGoalRecorder(); /** returns a reference to the RecorderHandler registered to the left goal box */ boost::shared_ptr<oxygen::RecorderHandler> GetRightGoalRecorder(); protected: /** queries the SceneServer for the currently active scene */ virtual void OnLink(); protected: /** cached scene path */ std::string mScenePath; }; DECLARE_ABSTRACTCLASS(SoccerControlAspect); #endif // SOCCERCONTROLASPECT_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:46
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/soccerbase In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/soccerbase Added Files: Tag: projectx soccerbase.cpp soccerbase.h Log Message: soccer plugins from rcssserver3D --- NEW FILE: soccerbase.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccerbase.h,v 1.1.2.1 2007/03/07 10:39:42 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef SOCCERBASE_H #define SOCCERBASE_H #include <soccer/soccertypes.h> #include <zeitgeist/scriptserver/scriptserver.h> #include <zeitgeist/leaf.h> #include <zeitgeist/logserver/logserver.h> #include <boost/shared_ptr.hpp> //namespace zeitgeist //{ // class Leaf; //} namespace oxygen { class SceneServer; class Scene; class Transform; class Perceptor; class Body; class SphereCollider; class ControlAspect; } namespace salt { class Vector3f; } class AgentState; class GameStateAspect; class SoccerRuleAspect; class Ball; class SoccerBase { public: typedef std::list<boost::shared_ptr<AgentState> > TAgentStateList; public: SoccerBase() {} virtual ~SoccerBase() {} /** returns a reference to the SceneServer */ static bool GetSceneServer(const zeitgeist::Leaf& base, boost::shared_ptr<oxygen::SceneServer>& scene_server); /** returns a reference to the closest parent supporting Transform */ static bool GetTransformParent(const zeitgeist::Leaf& base, boost::shared_ptr<oxygen::Transform>& transform_parent); /** returns a reference to the Body node below the closest transform parent */ static bool GetBody(const zeitgeist::Leaf& base, boost::shared_ptr<oxygen::Body>& body); /** returns a reference to the Body node below the given Transform node */ static bool GetAgentBody(const boost::shared_ptr<oxygen::Transform> transform, boost::shared_ptr<oxygen::Body>& agent_body); /** returns a reference to the Body node below the given Transform node based on parameters team index and uniform number */ static bool GetAgentBody(const zeitgeist::Leaf& base, TTeamIndex idx, int unum, boost::shared_ptr<oxygen::Body>& agent_body); /** returns a reference to the AgentState node below the closest Transform parent */ static bool GetAgentState(const zeitgeist::Leaf& base, boost::shared_ptr<AgentState>& agent_state); /** returns a reference to the AgentState node below the given transform node */ static bool GetAgentState(const boost::shared_ptr<oxygen::Transform> transform, boost::shared_ptr<AgentState>& agentState); /** returns a reference to the AgentState node below the given Transform node based on parameters team index and uniform number */ static bool GetAgentState(const zeitgeist::Leaf& base, TTeamIndex idx, int unum, boost::shared_ptr<AgentState>& agent_state); static bool GetAgentStates(const zeitgeist::Leaf& base, TAgentStateList& agentStates, TTeamIndex idx = TI_NONE); /** return a reference to the GameStateAspect node */ static bool GetGameState(const zeitgeist::Leaf& base, boost::shared_ptr<GameStateAspect>& game_state); /** return a reference to the SoccerRuleAspect node */ static bool GetSoccerRuleAspect(const zeitgeist::Leaf& base, boost::shared_ptr<SoccerRuleAspect>& soccer_rule_aspect); /** returns a reference to the active scene from the SceneServer */ static bool GetActiveScene(const zeitgeist::Leaf& base, boost::shared_ptr<oxygen::Scene>& active_scene); /** returns a reference to the Ball node */ static bool GetBall(const zeitgeist::Leaf& base, boost::shared_ptr<Ball>& ball); /** returns a reference to the Body node below the Ball */ static bool GetBallBody(const zeitgeist::Leaf& base, boost::shared_ptr<oxygen::Body>& body); /** returns a reference to the Body SphereCollider node below the Ball */ static bool GetBallCollider(const zeitgeist::Leaf& base, boost::shared_ptr<oxygen::SphereCollider>& sphere); /** flips horizontal coordinates according to the side of the agent */ static salt::Vector3f FlipView(const salt::Vector3f& pos, TTeamIndex ti); /** Get the team index of the opponent team */ static TTeamIndex OpponentTeam(TTeamIndex ti); /** returns a reference to a ControlAspect registered to the GameControlServer */ static boost::shared_ptr<oxygen::ControlAspect> GetControlAspect(const zeitgeist::Leaf& base, const std::string& name); /** looks up a ruby variable in the Soccer namespace */ template<typename TYPE> static bool GetSoccerVar(const zeitgeist::Leaf& base, const std::string& name, TYPE& value) { static const std::string nSpace = "Soccer."; bool ok = base.GetCore()->GetScriptServer()->GetVariable (std::string(nSpace + name),value); if (! ok) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") soccer variable '" << name << "' not found\n"; return false; } return ok; } /** returns a string representing a play mode */ static std::string PlayMode2Str(const TPlayMode mode); }; #endif --- NEW FILE: soccerbase.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: soccerbase.cpp,v 1.1.2.1 2007/03/07 10:39:42 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "soccerbase.h" #include <oxygen/physicsserver/body.h> #include <oxygen/physicsserver/spherecollider.h> #include <oxygen/agentaspect/perceptor.h> #include <oxygen/sceneserver/sceneserver.h> #include <oxygen/sceneserver/scene.h> #include <oxygen/sceneserver/transform.h> #include <oxygen/controlaspect/controlaspect.h> #include <soccer/gamestateaspect/gamestateaspect.h> #include <soccer/soccerruleaspect/soccerruleaspect.h> #include <soccer/agentstate/agentstate.h> #include <soccer/ball/ball.h> using namespace boost; using namespace zeitgeist; using namespace oxygen; using namespace std; bool SoccerBase::GetSceneServer(const Leaf& base, shared_ptr<SceneServer>& scene_server) { scene_server = shared_static_cast<SceneServer> (base.GetCore()->Get("/sys/server/scene")); if (scene_server.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") scene server not found.\n"; return false; } return true; } bool SoccerBase::GetTransformParent(const Leaf& base, shared_ptr<Transform>& transform_parent) { transform_parent = shared_dynamic_cast<Transform> (make_shared(base.GetParentSupportingClass("Transform"))); if (transform_parent.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") parent node is not derived from TransformNode\n"; return false; } return true; } bool SoccerBase::GetAgentState(const shared_ptr<Transform> transform, shared_ptr<AgentState>& agent_state) { agent_state = shared_dynamic_cast<AgentState>(transform->GetChild("AgentState")); if (agent_state.get() == 0) { return false; } return true; } bool SoccerBase::GetAgentBody(const shared_ptr<Transform> transform, shared_ptr<Body>& agent_body) { agent_body = shared_dynamic_cast<Body> (transform->GetChildSupportingClass("Body", true)); if (agent_body.get() == 0) { transform->GetLog()->Error() << "(SoccerBase) ERROR: " << transform->GetName() << ") node has no Body child\n"; return false; } return true; } bool SoccerBase::GetAgentBody(const Leaf& base, TTeamIndex idx, int unum, shared_ptr<Body>& agent_body) { shared_ptr<AgentState> agentState; shared_ptr<Transform> parent; // get matching AgentState if (!GetAgentState(base, idx, unum, agentState)) return false; // get AgentAspect if (!GetTransformParent(*agentState, parent)) return false; // call GetAgentBody with matching AgentAspect return GetAgentBody(parent, agent_body); } bool SoccerBase::GetAgentState(const Leaf& base, shared_ptr<AgentState>& agent_state) { shared_ptr<Transform> parent; if (! GetTransformParent(base,parent)) { return false; } return GetAgentState(parent,agent_state); } bool SoccerBase::GetAgentState(const Leaf& base, TTeamIndex idx, int unum, shared_ptr<AgentState>& agentState) { // get the active scene shared_ptr<Scene> activeScene; if (GetActiveScene(base, activeScene)) { Leaf::TLeafList leafList; // get a list of all the agent aspects activeScene->GetChildrenOfClass("AgentAspect", leafList); if (leafList.size() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase) active scene doesn't have " << "children of type AgentAspect\n"; return false; } Leaf::TLeafList::iterator iter = leafList.begin(); // search through the list to find an agent state // with matching team index and unum for ( iter; iter != leafList.end(); ++iter ) { shared_ptr<Transform> agentAspect = shared_dynamic_cast<Transform>(*iter); if (GetAgentState(agentAspect, agentState) && (agentState->GetTeamIndex() == idx) && (agentState->GetUniformNumber() == unum)) { return true; } } } return false; } bool SoccerBase::GetAgentStates(const zeitgeist::Leaf& base, TAgentStateList& agentStates, TTeamIndex idx) { // get the active scene shared_ptr<Scene> activeScene; if (GetActiveScene(base, activeScene)) { Leaf::TLeafList leafList; // get a list of all the agent aspects activeScene->GetChildrenOfClass("AgentAspect", leafList); if (leafList.size() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase) active scene doesn't have " << "children of type AgentAspect\n"; return false; } shared_ptr<AgentState> agentState; Leaf::TLeafList::iterator iter = leafList.begin(); // search through the list to find an agent state // with matching team index for (iter; iter != leafList.end(); ++iter ) { shared_ptr<Transform> agentAspect = shared_dynamic_cast<Transform>(*iter); if (agentAspect.get() == 0) continue; if (GetAgentState(agentAspect, agentState) && ((agentState->GetTeamIndex() == idx) || (idx == TI_NONE))) { agentStates.push_back(agentState); } } return true; } return false; } bool SoccerBase::GetGameState(const Leaf& base, shared_ptr<GameStateAspect>& game_state) { game_state = shared_dynamic_cast<GameStateAspect> (base.GetCore()->Get("/sys/server/gamecontrol/GameStateAspect")); if (game_state.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") found no GameStateAspect\n"; return false; } return true; } bool SoccerBase::GetSoccerRuleAspect(const Leaf& base, shared_ptr<SoccerRuleAspect>& soccer_rule_aspect) { soccer_rule_aspect = shared_dynamic_cast<SoccerRuleAspect> (base.GetCore()->Get("/sys/server/gamecontrol/SoccerRuleAspect")); if (soccer_rule_aspect.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") found no SoccerRuleAspect\n"; return false; } return true; } bool SoccerBase::GetActiveScene(const Leaf& base, shared_ptr<Scene>& active_scene) { shared_ptr<SceneServer> sceneServer; if (! GetSceneServer(base,sceneServer)) { return false; } active_scene = sceneServer->GetActiveScene(); if (active_scene.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") SceneServer reports no active scene\n"; return false; } return true; } bool SoccerBase::GetBody(const Leaf& base, shared_ptr<Body>& body) { shared_ptr<Transform> parent; if (! GetTransformParent(base,parent)) { return false; } body = shared_dynamic_cast<Body>(parent->GetChildOfClass("Body")); if (body.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") parent node has no Body child."; return false; } return true; } bool SoccerBase::GetBall(const Leaf& base, shared_ptr<Ball>& ball) { shared_ptr<Scene> scene; if (! GetActiveScene(base,scene)) { return false; } ball = shared_dynamic_cast<Ball> (base.GetCore()->Get(scene->GetFullPath() + "Ball")); if (ball.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") found no ball node\n"; return false; } return true; } bool SoccerBase::GetBallBody(const Leaf& base, shared_ptr<Body>& body) { shared_ptr<Scene> scene; if (! GetActiveScene(base,scene)) { return false; } body = shared_dynamic_cast<Body> (base.GetCore()->Get(scene->GetFullPath() + "Ball/physics")); if (body.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") found no ball body node\n"; return false; } return true; } bool SoccerBase::GetBallCollider(const zeitgeist::Leaf& base, boost::shared_ptr<oxygen::SphereCollider>& sphere) { shared_ptr<Scene> scene; if (! GetActiveScene(base,scene)) { return false; } sphere = shared_dynamic_cast<SphereCollider> (base.GetCore()->Get(scene->GetFullPath() + "Ball/geometry")); if (sphere.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") Ball got no SphereCollider node\n"; return false; } return true; } salt::Vector3f SoccerBase::FlipView(const salt::Vector3f& pos, TTeamIndex ti) { salt::Vector3f newPos; switch (ti) { case TI_RIGHT: newPos[0] = -pos[0]; newPos[1] = -pos[1]; newPos[2] = pos[2]; break; case TI_NONE: case TI_LEFT: newPos = pos; break; } return newPos; } TTeamIndex SoccerBase::OpponentTeam(TTeamIndex ti) { switch (ti) { case TI_RIGHT: return TI_LEFT; case TI_LEFT: return TI_RIGHT; default: return TI_NONE; } } string SoccerBase::PlayMode2Str(const TPlayMode mode) { switch (mode) { case PM_BeforeKickOff: return STR_PM_BeforeKickOff; case PM_KickOff_Left: return STR_PM_KickOff_Left; case PM_KickOff_Right: return STR_PM_KickOff_Right; case PM_PlayOn: return STR_PM_PlayOn; case PM_KickIn_Left: return STR_PM_KickIn_Left; case PM_KickIn_Right: return STR_PM_KickIn_Right; case PM_CORNER_KICK_LEFT: return STR_PM_CORNER_KICK_LEFT; case PM_CORNER_KICK_RIGHT: return STR_PM_CORNER_KICK_RIGHT; case PM_GOAL_KICK_LEFT: return STR_PM_GOAL_KICK_LEFT; case PM_GOAL_KICK_RIGHT: return STR_PM_GOAL_KICK_RIGHT; case PM_OFFSIDE_LEFT: return STR_PM_OFFSIDE_LEFT; case PM_OFFSIDE_RIGHT: return STR_PM_OFFSIDE_RIGHT; case PM_GameOver: return STR_PM_GameOver; case PM_Goal_Left: return STR_PM_Goal_Left; case PM_Goal_Right: return STR_PM_Goal_Right; case PM_FREE_KICK_LEFT: return STR_PM_FREE_KICK_LEFT; case PM_FREE_KICK_RIGHT: return STR_PM_FREE_KICK_RIGHT; default: return STR_PM_Unknown; }; } shared_ptr<ControlAspect> SoccerBase::GetControlAspect(const zeitgeist::Leaf& base,const string& name) { static const string gcsPath = "/sys/server/gamecontrol/"; shared_ptr<ControlAspect> aspect = shared_dynamic_cast<ControlAspect> (base.GetCore()->Get(gcsPath + name)); if (aspect.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ") found no ControlAspect " << name << "\n"; } return aspect; } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:45
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/sexpmonitor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/sexpmonitor Added Files: Tag: projectx sexpmonitor.cpp sexpmonitor.h sexpmonitor_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: sexpmonitor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: sexpmonitor.cpp,v 1.1.2.1 2007/03/07 10:39:41 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "sexpmonitor.h" #include <sstream> #include <zeitgeist/logserver/logserver.h> #include <zeitgeist/scriptserver/scriptserver.h> #include <oxygen/sceneserver/sceneserver.h> #include <oxygen/sceneserver/scene.h> #include <oxygen/sceneserver/transform.h> #include <oxygen/agentaspect/agentaspect.h> #include <soccer/soccertypes.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/ball/ball.h> #include <soccer/gamestateaspect/gamestateaspect.h> #include <soccer/ballstateaspect/ballstateaspect.h> #include <soccer/agentstate/agentstate.h> #include <soccer/fieldflag/fieldflag.h> #include <netinet/in.h> #include <soccer/sayeffector/sayeffector.h> using namespace oxygen; using namespace zeitgeist; using namespace std; using namespace boost; SexpMonitor::SexpMonitor() : MonitorSystem(), mSendRotMatrix(false) { } SexpMonitor::~SexpMonitor() { } bool SexpMonitor::ConstructInternal() { return true; } void SexpMonitor::ParseMonitorMessage(const string& data) { GetLog()->Debug() << "SexpMonitor received " << data << " from monitor\n"; if (mGameState.get() == 0) { return; } if (mCommandParser.get() == 0) { GetLog()->Error() << "(SexpMonitor) ERROR: can't get TrainerCommandParser\n"; return; } // interpret the commands in the predicates mCommandParser->ParseMonitorMessage(data); } void SexpMonitor::AddPredicates(std::ostringstream& ss, const PredicateList& pList) { for ( PredicateList::TList::const_iterator iter = pList.begin(); iter != pList.end(); ++iter ) { const Predicate& pred = (*iter); ss << "("; ss << pred.name; const ParameterList& paramList = pred.parameter; ParameterList::TVector::const_iterator pIter = paramList.begin(); std::string param; while ( (pIter != paramList.end()) && (paramList.AdvanceValue(pIter, param)) ) { ss << " "; ss << param; } ss << ")"; } } void SexpMonitor::AddAgents(shared_ptr<Scene> activeScene, std::ostringstream& ss) const { TLeafList nodes; activeScene->ListChildrenSupportingClass<AgentAspect>(nodes, true); for (TLeafList::iterator i = nodes.begin(); i != nodes.end(); ++i) { shared_ptr<AgentAspect> aspect = shared_static_cast<AgentAspect>(*i); const salt::Vector3f& pos = aspect->GetWorldTransform().Pos(); ss << "(P "; shared_ptr<AgentState> state = shared_static_cast<AgentState> (aspect->GetChildOfClass("AgentState")); shared_ptr<SayEffector> sayEff = shared_static_cast<SayEffector> (aspect->GetChildOfClass("SayEffector")); if (state.get() != 0) { ss << "(s " << state->GetTeamIndex() << ")"; ss << "(id " << state->GetUniformNumber() << ")"; } // pos ss << "(pos " << pos << ")"; if (mSendRotMatrix) { // world transform ss << "(rot "; const salt::Matrix& trans = aspect->GetWorldTransform(); for (int i=0;i<16;++i) { ss << trans.m[i] << " "; } ss << ")"; } // extra field if the agent was the last colliding with the ball shared_ptr<AgentAspect> agent; TTime time; mBallState->GetLastCollidingAgent(agent,time); if (agent == aspect) { ss << "(last)"; } if (sayEff !=0 && sayEff->IfText()) { //ss <<"(say " <<sayEff->GetText()<<")"; } ss << ")"; } } void SexpMonitor::AddFlags(shared_ptr<Scene> activeScene, std::ostringstream& ss) { // the flags don't change, so we need to send them only once if (mSentFlags) { return; } mSentFlags = true; TLeafList nodes; activeScene->ListChildrenSupportingClass<FieldFlag>(nodes, true); for (TLeafList::iterator i = nodes.begin(); i != nodes.end(); ++i) { shared_ptr<FieldFlag> flag = shared_static_cast<FieldFlag>(*i); const salt::Vector3f& pos = flag->GetWorldTransform().Pos(); shared_ptr<ObjectState> state = shared_dynamic_cast<ObjectState> (flag->GetChildOfClass("ObjectState")); if (state.get() == 0) continue; ss << "(" << state->GetPerceptName()[0] << " "; // id ss << "(id " << state->GetID() << ")"; // pos ss << "(pos " << pos[0] << " " << pos[1] << " " << pos[2] << ")"; ss << ")"; } } void SexpMonitor::AddBall(shared_ptr<Scene> activeScene, std::ostringstream& ss) const { shared_ptr<Ball> ball = shared_static_cast<Ball>(activeScene->GetChild("Ball")); const salt::Vector3f& pos = ball->GetWorldTransform().Pos(); ss << "(B "; // pos ss << "(pos " << pos[0] << " " << pos[1] << " " << pos[2] << ")"; ss << ")"; } string SexpMonitor::GetMonitorInfo(const oxygen::PredicateList& pList) { if (mGameState->IsFinished()) { return "(Die)\n"; } shared_ptr<SceneServer> sceneServer = shared_dynamic_cast<SceneServer>(GetCore()->Get("/sys/server/scene")); if (sceneServer.get() == 0) { GetLog()->Error() << "(SexpMonitor) cannot get SceneServer\n"; return ""; } shared_ptr<Scene> activeScene = sceneServer->GetActiveScene(); ostringstream expression; expression << "(Info "; string reply; if (mCommandParser->SendAck(reply)) { expression << "(ack " + reply + ")"; } AddPredicates(expression, pList); AddAgents(activeScene, expression); AddFlags(activeScene, expression); AddBall(activeScene, expression); expression << ")\n"; return expression.str(); } string SexpMonitor::GetMonitorHeaderInfo(const oxygen::PredicateList& pList) { // if a new monitor connected, we have to resend all required data ResetSentFlags(); ostringstream ss; ss << "(Init "; AddPredicates(ss, pList); ss << ")\n"; return ss.str(); } void SexpMonitor::OnLink() { SoccerBase::GetGameState(*this,mGameState); // we need the TrainerCommandParser to parse the predicates // and interpret the commands mCommandParser = shared_dynamic_cast<TrainerCommandParser> (GetCore()->New("TrainerCommandParser")); if (mCommandParser.get() == 0) { GetLog()->Error() << "ERROR: (SexpMonitor) failed to create parser TrainerCommandParser\n"; return; } mCommandParser->SetName("TrainerCommandParser"); AddChildReference(mCommandParser); UpdateCached(); } void SexpMonitor::UpdateCached() { mBallState = shared_dynamic_cast<BallStateAspect> (GetCore()->Get("/sys/server/gamecontrol/BallStateAspect")); if (mBallState.get() == 0) { GetLog()->Error() << "(SexpMonitor) found no BallStateAspect\n"; } } void SexpMonitor::OnUnlink() { mGameState.reset(); mCommandParser.reset(); mBallState.reset(); } void SexpMonitor::ResetSentFlags() { mSentFlags = false; } void SexpMonitor::SendRotationMatrix(bool send) { mSendRotMatrix = send; } --- NEW FILE: sexpmonitor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: sexpmonitor.h,v 1.1.2.1 2007/03/07 10:39:42 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. FileSystemSTD */ #ifndef SEXPMONITOR_H__ #define SEXPMONITOR_H__ #include <string> #include <oxygen/monitorserver/monitorsystem.h> #include <soccer/trainercommandparser/trainercommandparser.h> class GameStateAspect; class BallStateAspect; namespace oxygen { class AgentAspect; class Scene; } /** \class SexpMonitor is a monitor plugin that generates S-Expressions for the rcssmonitor3D * * Protocoll: * (Init ...) Sends information about the simulator setup */ class SexpMonitor : public oxygen::MonitorSystem { public: SexpMonitor(); virtual ~SexpMonitor(); /** If a monitor sends information to the world model, this * function is called to process it. * @param data data sent from monitor to monitorsystem via SPADES. */ void ParseMonitorMessage(const std::string& data); /** This function will be called periodically to get information * about the current state of the world. * \param items holds a list of additional name value pairs. These * predicates are collected from MonitorItem objects registered to * the MonitorServer. The monitor should transfer them to the * client if possible. */ virtual std::string GetMonitorInfo(const oxygen::PredicateList& pList); /** This function is called once for every MonitorSystem each time * a new client connects. It should return any header/setup * information that is needed. * \param items holds a list of additional name value * pairs. These predicates are collected from MonitorItem objects * registered to the MonitorServer. The monitor should transfer * them to the client if possible. */ virtual std::string GetMonitorHeaderInfo(const oxygen::PredicateList& pList); /** This method can be used to set the flag for sending the rotation matrix of every object to the monitor. \param send flag wether to send the matrix or not */ void SendRotationMatrix(bool send); protected: /** called after the object has been created and attached to a core to allow for object dependent internal construction */ virtual bool ConstructInternal(); /** collects data from agentaspects and constructs a S-Expr description */ void AddAgents(boost::shared_ptr<oxygen::Scene> activeScene, std::ostringstream& ss) const; /** collects flag data and constructs a S-Expression description */ void AddFlags(boost::shared_ptr<oxygen::Scene> activeScene, std::ostringstream& ss); /** adds ball data to output string stream */ void AddBall(boost::shared_ptr<oxygen::Scene> activeScene, std::ostringstream& ss) const; /** sets the reference to the GameStateAspect */ virtual void OnLink(); /** resets the reference to the GameStateAspect */ virtual void OnUnlink(); virtual void UpdateCached(); void ResetSentFlags(); /** constructs a S-Expression from the predicate list received from the MonitorServer */ void AddPredicates(std::ostringstream& ss, const oxygen::PredicateList& pList); protected: boost::shared_ptr<GameStateAspect> mGameState; boost::shared_ptr<TrainerCommandParser> mCommandParser; boost::shared_ptr<BallStateAspect> mBallState; // flag if we want to send the rotation matrix bool mSendRotMatrix; // flags for sent information //! flag if the monitors received field flags information bool mSentFlags; }; DECLARE_CLASS(SexpMonitor); #endif // SEXPMONITOR_H__ --- NEW FILE: sexpmonitor_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: sexpmonitor_c.cpp,v 1.1.2.1 2007/03/07 10:39:42 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "sexpmonitor.h" FUNCTION(SexpMonitor,sendRotationMatrix) { bool sendRotMatrix; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),sendRotMatrix)) ) { return false; } obj->SendRotationMatrix(sendRotMatrix); return true; } void CLASS(SexpMonitor)::DefineClass() { DEFINE_BASECLASS(oxygen/MonitorSystem); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:44
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/sayeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/sayeffector Added Files: Tag: projectx sayaction.h sayeffector.cpp sayeffector.h sayeffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: sayeffector.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef SAYEFFECTOR_H #define SAYEFFECTOR_H #include <oxygen/agentaspect/effector.h> namespace oxygen { class AgentAspect; } class SoccerRuleAspect; class AgentState; class SayEffector : public oxygen::Effector { public: SayEffector(); virtual ~SayEffector(); /** realizes the action described by the ActionObject */ virtual bool Realize(boost::shared_ptr<oxygen::ActionObject> action); /** returns the name of the predicate this effector implements. */ virtual std::string GetPredicate() { return "say"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); /** setup the reference to the ball body node */ virtual void OnLink(); /** remove the reference to the ball body node */ virtual void OnUnlink(); std::string GetText(); bool IfText()const; protected: /** reference to the agent aspect */ boost::shared_ptr<oxygen::AgentAspect> mAgent; /** reference to the agentstate */ boost::shared_ptr<AgentState> mAgentState; /** reference to the soccer rule aspect */ boost::shared_ptr<SoccerRuleAspect> mSoccerRule; private: /** said message */ std::string mMessage; bool ifText; }; DECLARE_CLASS(SayEffector); #endif // SAYEFFECTOR_H --- NEW FILE: sayeffector_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: sayeffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:41 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "sayeffector.h" using namespace oxygen; void CLASS(SayEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); } --- NEW FILE: sayaction.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef SAYACTION_H #define SAYACTION_H #include <oxygen/gamecontrolserver/actionobject.h> class SayAction : public oxygen::ActionObject { public: SayAction(const std::string& predicate, std::string message) : ActionObject(predicate), mMessage(message) {} virtual ~SayAction() {} void GetMessage(std::string& msg) { msg = mMessage; } protected: std::string mMessage; }; #endif // SAYACTION_H --- NEW FILE: sayeffector.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "sayaction.h" #include "sayeffector.h" #include <zeitgeist/logserver/logserver.h> #include <oxygen/agentaspect/agentaspect.h> #include <soccer/agentstate/agentstate.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/soccerruleaspect/soccerruleaspect.h> using namespace boost; using namespace oxygen; using namespace salt; using namespace std; SayEffector::SayEffector() : oxygen::Effector() { } SayEffector::~SayEffector() { } bool SayEffector::Realize(shared_ptr<ActionObject> action) { if (mAgent.get() == 0) { GetLog()->Error() << "ERROR: (SayEffector) parent node is not derived from " << "BaseNode\n"; return false; } if (mAgentState.get() == 0) { return false; } shared_ptr<SayAction> sayAction = shared_dynamic_cast<SayAction>(action); if (sayAction.get() == 0) { GetLog()->Error() << "ERROR: (SayEffector) cannot realize an unknown ActionObject\n"; return false; } sayAction->GetMessage(mMessage); ifText=true; // If " ", "(" or ")" are in mMessage, return false if (mMessage.find_first_of("() ") != std::string::npos) { GetLog()->Debug() << "(SayEffector) found illegal character. Ignoring message [" << mMessage << "]\n"; ifText=false; return false; } mSoccerRule->Broadcast(mMessage, mAgent->GetWorldTransform().Pos(), mAgentState->GetUniformNumber(), mAgentState->GetTeamIndex()); return true; } string SayEffector::GetText() { ifText=false; return mMessage; } bool SayEffector::IfText()const { return ifText; } shared_ptr<ActionObject> SayEffector::GetActionObject(const Predicate& predicate) { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (SayEffector) invalid predicate" << predicate.name << "\n"; // some error happened return shared_ptr<ActionObject>(); } Predicate::Iterator iter = predicate.begin(); std::string message; if (! predicate.AdvanceValue(iter, message)) { GetLog()->Error() << "ERROR: (SayEffector) said message expected\n"; // some error happened return shared_ptr<ActionObject>(); } // construct the SayAction object return shared_ptr<SayAction>(new SayAction(GetPredicate(), message)); } void SayEffector::OnLink() { SoccerBase::GetAgentState(*this,mAgentState); SoccerBase::GetSoccerRuleAspect(*this,mSoccerRule); mAgent = shared_dynamic_cast<AgentAspect>(make_shared(GetParent())); if (mAgent.get() == 0) { GetLog()->Error() << "ERROR: (SayEffector) parent node is not derived from " << "AgentAspect\n"; return; } } void SayEffector::OnUnlink() { mAgent.reset(); mAgentState.reset(); mSoccerRule.reset(); } |
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/restrictedvisionperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/restrictedvisionperceptor Added Files: Tag: projectx restrictedvisionperceptor.cpp restrictedvisionperceptor.h restrictedvisionperceptor_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: restrictedvisionperceptor_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: restrictedvisionperceptor_c.cpp,v 1.1.2.1 2007/03/07 10:39:40 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "restrictedvisionperceptor.h" using namespace boost; using namespace oxygen; using namespace std; FUNCTION(RestrictedVisionPerceptor,setNoiseParams) { float inDist; float inPhi; float inTheta; float inErrorAbs; if ( (in.GetSize() != 4) || (! in.GetValue(in[0],inDist)) || (! in.GetValue(in[1],inPhi)) || (! in.GetValue(in[2],inTheta)) || (! in.GetValue(in[3],inErrorAbs)) ) { return false; } obj->SetNoiseParams(inDist,inPhi,inTheta,inErrorAbs); return true; } FUNCTION(RestrictedVisionPerceptor,addNoise) { bool inAddNoise; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inAddNoise)) ) { return false; } obj->AddNoise(inAddNoise); return true; } FUNCTION(RestrictedVisionPerceptor,setSenseMyPos) { bool inSenseMyPos; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inSenseMyPos)) ) { return false; } obj->SetSenseMyPos(inSenseMyPos); return true; } FUNCTION(RestrictedVisionPerceptor,setStaticSenseAxis) { bool inStaticAxis; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inStaticAxis)) ) { return false; } obj->SetStaticSenseAxis(inStaticAxis); return true; } FUNCTION(RestrictedVisionPerceptor,setViewCones) { int inHAngle; int inVAngle; if ( (in.GetSize() != 2) || (! in.GetValue(in[0],inHAngle)) || (! in.GetValue(in[1],inVAngle)) ) { return false; } obj->SetViewCones(inHAngle,inVAngle); return true; } FUNCTION(RestrictedVisionPerceptor,setPanRange) { int inLower; int inUpper; if ( (in.GetSize() != 2) || (! in.GetValue(in[0],inLower)) || (! in.GetValue(in[1],inUpper)) ) { return false; } obj->SetPanRange(inLower,inUpper); return true; } FUNCTION(RestrictedVisionPerceptor,setTiltRange) { int inLower; int inUpper; if ( (in.GetSize() != 2) || (! in.GetValue(in[0],inLower)) || (! in.GetValue(in[1],inUpper)) ) { return false; } obj->SetTiltRange(inLower,inUpper); return true; } void CLASS(RestrictedVisionPerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); DEFINE_FUNCTION(setNoiseParams); DEFINE_FUNCTION(addNoise); DEFINE_FUNCTION(setSenseMyPos); DEFINE_FUNCTION(setStaticSenseAxis); DEFINE_FUNCTION(setViewCones); DEFINE_FUNCTION(setPanRange); DEFINE_FUNCTION(setTiltRange); } --- NEW FILE: restrictedvisionperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: restrictedvisionperceptor.cpp,v 1.1.2.1 2007/03/07 10:39:40 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "restrictedvisionperceptor.h" #include <zeitgeist/logserver/logserver.h> #include <oxygen/sceneserver/scene.h> #include <oxygen/sceneserver/transform.h> #include <soccer/soccerbase/soccerbase.h> #include <salt/gmath.h> using namespace zeitgeist; using namespace oxygen; using namespace boost; using namespace salt; RestrictedVisionPerceptor::RestrictedVisionPerceptor() : Perceptor(), mSenseMyPos(false), mAddNoise(true), mStaticSenseAxis(true) { // set predicate name SetPredicateName("Vision"); // set some default noise values SetNoiseParams(0.0965, 0.1225, 0.1480, 0.005); SetViewCones(90,90); SetPanRange(-90,90); SetTiltRange(-20,20); SetPanTilt(0,0); } RestrictedVisionPerceptor::~RestrictedVisionPerceptor() { mDistRng.reset(); mPhiRng.reset(); mThetaRng.reset(); } void RestrictedVisionPerceptor::SetNoiseParams(float sigma_dist, float sigma_phi, float sigma_theta, float cal_error_abs) { mSigmaDist = sigma_dist; mSigmaPhi = sigma_phi; mSigmaTheta = sigma_theta; mCalErrorAbs = cal_error_abs; NormalRngPtr rng1(new salt::NormalRNG<>(0.0,sigma_dist)); mDistRng = rng1; NormalRngPtr rng2(new salt::NormalRNG<>(0.0,sigma_phi)); mPhiRng = rng2; NormalRngPtr rng3(new salt::NormalRNG<>(0.0,sigma_theta)); mThetaRng = rng3; salt::UniformRNG<float> rng4(-mCalErrorAbs,mCalErrorAbs); mError = salt::Vector3f(rng4(),rng4(),rng4()); } void RestrictedVisionPerceptor::SetViewCones(unsigned int hAngle, unsigned int vAngle) { mHViewCone = hAngle; mVViewCone = vAngle; } void RestrictedVisionPerceptor::SetPanRange(int lower, int upper) { /* The total pan range is 360 degrees, starting at -180 degrees * and ending at 180 degrees. For restricting this range: * - the normal case is: lower < upper, which means that * the horizontal pan angles should be between lower and upper. * - the not so normal case is upper < lower, which means that * the pan angles should be *either* smaller than 180 and > lower, *or* * they should be greater than -180 and < upper. */ mPanLower = gNormalizeDeg(lower); mPanUpper = gNormalizeDeg(upper); } void RestrictedVisionPerceptor::SetTiltRange(int lower, int upper) { mTiltLower = gNormalizeDeg(lower); mTiltUpper = gNormalizeDeg(upper); } // this should really go to gmath.h for the full release template <class TYPE1, class TYPE2> f_inline TYPE1 gClampAngleDeg(TYPE1 &val, TYPE2 min, TYPE2 max) { val = gNormalizeDeg(val); if (min <= max) { if (val<min) val=min; if (val>max) val=max; } else { if (val>=min || val<=max) return val; if (val>=(min+max)/2.0) val = min; else val = max; } return val; } void RestrictedVisionPerceptor::SetPanTilt(float pan, float tilt) { pan = gNormalizeDeg(pan); mPan = gClampAngleDeg(pan,mPanLower,mPanUpper); tilt = gNormalizeDeg(tilt); mTilt = gClampAngleDeg(tilt,mTiltLower,mTiltUpper); } void RestrictedVisionPerceptor::ChangePanTilt(float pan, float tilt) { SetPanTilt(mPan + pan, mTilt + tilt); } float RestrictedVisionPerceptor::GetPan() const { return mPan; } float RestrictedVisionPerceptor::GetTilt() const { return mTilt; } void RestrictedVisionPerceptor::OnLink() { SoccerBase::GetTransformParent(*this,mTransformParent); SoccerBase::GetAgentState(*this, mAgentState); SoccerBase::GetActiveScene(*this,mActiveScene); } void RestrictedVisionPerceptor::OnUnlink() { mDistRng.reset(); mPhiRng.reset(); mThetaRng.reset(); mTransformParent.reset(); mAgentState.reset(); mActiveScene.reset(); } void RestrictedVisionPerceptor::AddNoise(bool add_noise) { mAddNoise = add_noise; } void RestrictedVisionPerceptor::SetStaticSenseAxis(bool static_axis) { mStaticSenseAxis = static_axis; } bool RestrictedVisionPerceptor::ConstructInternal() { mRay = shared_static_cast<RayCollider> (GetCore()->New("oxygen/RayCollider")); if (mRay.get() == 0) { GetLog()->Error() << "Error: (RestrictedVisionPerceptor) cannot create Raycollider. " << "occlusion check disabled\n"; } return true; } void RestrictedVisionPerceptor::SetupVisibleObjects(TObjectList& visibleObjects) { TLeafList objectList; mActiveScene->ListChildrenSupportingClass<ObjectState>(objectList, true); salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos(); for (TLeafList::iterator i = objectList.begin(); i != objectList.end(); ++i) { ObjectData od; od.mObj = shared_static_cast<ObjectState>(*i); if (od.mObj.get() == 0) { GetLog()->Error() << "Error: (RestrictedVisionPerceptor) skipped: " << (*i)->GetName() << "\n"; continue; // this should never happen } shared_ptr<Transform> j = od.mObj->GetTransformParent(); if (j.get() == 0) { continue; // this should never happen } od.mRelPos = j->GetWorldTransform().Pos() - myPos; od.mDist = od.mRelPos.Length(); visibleObjects.push_back(od); } } void RestrictedVisionPerceptor::AddSense(Predicate& predicate, ObjectData& od) const { ParameterList& element = predicate.parameter.AddList(); element.AddValue(od.mObj->GetPerceptName()); if(od.mObj->GetPerceptName() == "Player") { ParameterList player; player.AddValue(std::string("team")); player.AddValue(od.mObj->GetPerceptName(ObjectState::PT_Player)); element.AddValue(player); } if (!od.mObj->GetID().empty()) { ParameterList id; id.AddValue(std::string("id")); id.AddValue(od.mObj->GetID()); element.AddValue(id); } ParameterList& position = element.AddList(); position.AddValue(std::string("pol")); position.AddValue(od.mDist); position.AddValue(od.mTheta); position.AddValue(od.mPhi); } void RestrictedVisionPerceptor::ApplyNoise(ObjectData& od) const { if (mAddNoise) { od.mDist += (*(mDistRng.get()))() * od.mDist / 100.0; od.mTheta += (*(mThetaRng.get()))(); od.mPhi += (*(mPhiRng.get()))(); } } bool RestrictedVisionPerceptor::StaticAxisPercept(boost::shared_ptr<PredicateList> predList) { Predicate& predicate = predList->AddPredicate(); predicate.name = mPredicateName; predicate.parameter.Clear(); TTeamIndex ti = mAgentState->GetTeamIndex(); salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos(); TObjectList visibleObjects; SetupVisibleObjects(visibleObjects); for (std::list<ObjectData>::iterator i = visibleObjects.begin(); i != visibleObjects.end(); ++i) { ObjectData& od = (*i); od.mRelPos = SoccerBase::FlipView(od.mRelPos, ti); if (mAddNoise) { od.mRelPos += mError; } if ( (od.mRelPos.Length() <= 0.1) || (CheckOcclusion(myPos,od)) ) { // object is occluded or too close continue; } // theta is the angle in the X-Y (horizontal) plane assert(gAbs(GetPan()) <= 360); od.mTheta = salt::gRadToDeg(salt::gArcTan2(od.mRelPos[1], od.mRelPos[0])) - GetPan(); od.mTheta = gNormalizeDeg(od.mTheta); // latitude assert(gAbs(GetTilt()) <= 360); od.mPhi = 90.0 - salt::gRadToDeg(salt::gArcCos(od.mRelPos[2]/od.mDist)) - GetTilt(); od.mPhi = gNormalizeDeg(od.mPhi); // make some noise ApplyNoise(od); // check if the object is in the current field of view if (gAbs(od.mTheta) > mHViewCone) continue; if (gAbs(od.mPhi) > mVViewCone) continue; // generate a sense entry AddSense(predicate,od); } if (mSenseMyPos) { Vector3f sensedMyPos = SoccerBase::FlipView(myPos, ti); ParameterList& element = predicate.parameter.AddList(); element.AddValue(std::string("mypos")); element.AddValue(sensedMyPos[0]); element.AddValue(sensedMyPos[1]); element.AddValue(sensedMyPos[2]); } return true; } bool RestrictedVisionPerceptor::DynamicAxisPercept(boost::shared_ptr<PredicateList> predList) { Predicate& predicate = predList->AddPredicate(); predicate.name = mPredicateName; predicate.parameter.Clear(); const int hAngle_2 = mHViewCone>>1; const int vAngle_2 = mVViewCone>>1; TTeamIndex ti = mAgentState->GetTeamIndex(); const Vector3f& up = mTransformParent->GetWorldTransform().Up(); // calc the percptors angle in the horizontal plane double fwTheta = gNormalizeRad(Vector2f(up[0],up[1]).GetAngleRad()); // calc the perceptors angle in the vertical plane // for this the vector has to rotated, i.e. you cannot just use x and z component //double fwPhi = gNormalizeRad(Vector2f(Vector2f(up[0],up[1]).Length(),up[2]).GetAngleRad()); // assume that perceptor is always horizontal. // FIXME: this is magic double fwPhi = 0.0; TObjectList visibleObjects; SetupVisibleObjects(visibleObjects); // log for 7th agent of the first team if ((mAgentState->GetTeamIndex() == 1) && (mAgentState->GetUniformNumber() ==7)) GetLog()->Debug() << "percept: " << visibleObjects.size() << " objects. :::" << up << " theta " << gRadToDeg(fwTheta) << " phi " << gRadToDeg(fwPhi) << "\n"; for (std::list<ObjectData>::iterator i = visibleObjects.begin(); i != visibleObjects.end(); ++i) { ObjectData& od = (*i); od.mRelPos = SoccerBase::FlipView(od.mRelPos, ti); if ((mAgentState->GetTeamIndex() == 1) && (mAgentState->GetUniformNumber() ==7)) GetLog()->Debug() << "object " << od.mObj->GetPerceptName() << " at : " << od.mRelPos << "\n"; if (mAddNoise) { od.mRelPos += mError; } if (od.mRelPos.Length() <= 0.1) { // object is too close continue; } // theta is the angle in horizontal plane, with fwAngle as 0 degree od.mTheta = gRadToDeg(gNormalizeRad( Vector2f(od.mRelPos[0],od.mRelPos[1]).GetAngleRad() - fwTheta )); // flags are always visible if ((gAbs(od.mTheta) > hAngle_2) && (od.mObj->GetPerceptName() != "Flag")) { // object is out of view range // GetLog()->Debug() << "(RestrictedVisionPerceptor) Omitting " // << od.mObj->GetPerceptName() << od.mObj->GetID() // << ": h-angle = " << od.mTheta << ".\n" ; continue; } // latitude with fwPhi as 0 degreee od.mPhi = gRadToDeg(gNormalizeRad( Vector2f( Vector2f(od.mRelPos[0],od.mRelPos[1]).Length(), od.mRelPos[2]).GetAngleRad() - fwPhi )); if ((gAbs(od.mPhi) > vAngle_2) && (od.mObj->GetPerceptName() != "Flag")) continue; // log for 7th agent of the first team if ((mAgentState->GetTeamIndex() == 1) && (mAgentState->GetUniformNumber() ==7)) GetLog()->Debug() << "percept: " << "adding object: " << gAbs(od.mPhi) << ":" << vAngle_2 << "\n"; // make some noise ApplyNoise(od); // generate a sense entry AddSense(predicate,od); } if (mSenseMyPos) { salt::Vector3f myPos = mTransformParent->GetWorldTransform().Pos(); Vector3f sensedMyPos = myPos; SoccerBase::FlipView(sensedMyPos, ti); ParameterList& element = predicate.parameter.AddList(); element.AddValue(std::string("mypos")); element.AddValue(sensedMyPos[0]); element.AddValue(sensedMyPos[1]); element.AddValue(sensedMyPos[2]); } return true; } bool RestrictedVisionPerceptor::Percept(boost::shared_ptr<PredicateList> predList) { if ( (mTransformParent.get() == 0) || (mActiveScene.get() == 0) || (mAgentState.get() == 0) ) { return false; } #if 1 return StaticAxisPercept(predList); #else return mStaticSenseAxis ? StaticAxisPercept(predList) : DynamicAxisPercept(predList); #endif } bool RestrictedVisionPerceptor::CheckOcclusion(const Vector3f& my_pos, const ObjectData& od) const { // (occlusion test disabled for now, every object is visible) return false; // if (mRay.get() == 0) return; // // sort objects wrt their distance // visible_objects.sort(); // // check visibility // std::list<ObjectData>::iterator start = visible_objects.begin(); // ++start; // // this is going to be expensive now: to check occlusion of an object, // // we have to check all closer objects. For n objects, we have to // // check at most n*(n-1)/2 objects. // for (std::list<ObjectData>::iterator i = start; // i != visible_objects.end(); ++i) // { // for (std::list<ObjectData>::iterator j = visible_objects.begin(); // j != i; ++j) // { // // cast ray from camera to object (j) // mRay->SetParams(j->mRelPos,my_pos,j->mDist); // dContactGeom contact; // shared_ptr<Collider> collider = shared_static_cast<Collider> // (i->mObj->GetChildSupportingClass("Collider")); // if (mRay->Intersects(collider)) // { // j->mVisible = false; // j = i; // } // } // } } void RestrictedVisionPerceptor::SetSenseMyPos(bool sense) { mSenseMyPos = sense; } --- NEW FILE: restrictedvisionperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: restrictedvisionperceptor.h,v 1.1.2.1 2007/03/07 10:39:40 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef RESTRICTEDVISIONPERCEPTOR_H #define RESTRICTEDVISIONPERCEPTOR_H #include <salt/random.h> #include <oxygen/agentaspect/perceptor.h> #include <oxygen/physicsserver/raycollider.h> #include <oxygen/sceneserver/sceneserver.h> #include <oxygen/sceneserver/transform.h> #include <soccer/agentstate/agentstate.h> class RestrictedVisionPerceptor : public oxygen::Perceptor { protected: typedef boost::shared_ptr<salt::NormalRNG<> > NormalRngPtr; struct ObjectData { boost::shared_ptr<ObjectState> mObj; float mTheta; // angle in the X-Y (horizontal) plane float mPhi; // latitude angle float mDist; // distance between perceptor and object salt::Vector3f mRelPos; //position relative to perceptor //string name; // name of the object ObjectData& operator=(const ObjectData& rhs) { mObj = rhs.mObj; mRelPos = rhs.mRelPos; mTheta = rhs.mTheta; mPhi = rhs.mPhi; mDist = rhs.mDist; } int operator==(const ObjectData& rhs) const { return mDist == rhs.mDist; } int operator<(const ObjectData& rhs) const { return mDist < rhs.mDist; } }; typedef std::list<ObjectData> TObjectList; public: RestrictedVisionPerceptor(); virtual ~RestrictedVisionPerceptor(); //! \return true, if valid data is available and false otherwise. bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); /** Set the noise parameters of the vision perceptor. * * This will always create new calibration error values. * The random noise added each step is normally distributed around 0.0. * The (fixed) calibration error is calculated once for each axis. It * is uniformly distributed between -cal_error_abs and cal_error_abs and * added to the "camera" coordinates. * * \param sigma_dist the sigma for the distance error distribution * \param sigma_phi the sigma for the horizontal angle error distribution * \param sigma_theta the sigma for the latitudal angle error distribution * \param cal_error_abs absolute value of the maximum calibration error * along each axis. */ void SetNoiseParams(float sigma_dist, float sigma_phi, float sigma_theta, float cal_error_abs); //! Turn sensing of agent position on/off void SetSenseMyPos(bool sense); /** Turn noise off/on. \param add_noise flag if noise should be used at all. */ void AddNoise(bool add_noise); //! Turn senses relative to the X-axis of the team off/on void SetStaticSenseAxis(bool static_axis); //! Set the visible area of the perceptor void SetViewCones(unsigned int hAngle, unsigned int vAngle); /** Set the pan range. * As long as the agents have no inherent direction and 0 degrees * horizontally is always directed towards the opponent side, it * does not make much sense to restrict the pan range other than * to a fixed angle, which disables panning effectively. * A range of 360 degrees (e.g. from -180 to 180) means no restriction. * @param lower lower bound (in degrees) * @param upper upper bound (in degrees) */ void SetPanRange(int lower, int upper); /** Set the tilt range. * Contrary to the pan range, it makes much sense to restrict the * tilt range. However, a range of 360 degrees (e.g. from -180 to 180) * means no restriction. * @param lower lower bound (in degrees) * @param upper upper bound (in degrees) */ void SetTiltRange(int lower, int upper); /** Set the view angles * @param pan the horizontal view angle in degrees * (0 degrees is the x-axis towards the opponent side) * @param tilt is the vertical view angle in degrees * (0 degrees is the angle parallel to the floor) */ void SetPanTilt(float pan, float tilt); /** Add values to the current view angles. * @param pan the horizontal view angle in degrees * (0 degrees is the x-axis towards the opponent side) * @param tilt is the vertical view angle in degrees * (0 degrees is the angle parallel to the floor) */ void ChangePanTilt(float pan, float tilt); /** Get the horizontal view direction. * @return the pan angle in degrees */ float GetPan() const; /** Get the horizontal view direction. * @return the tilt angle in degrees */ float GetTilt() const; protected: /** constructs the internal ray collider */ virtual bool ConstructInternal(); /** prepares a list of visible objects */ void SetupVisibleObjects(TObjectList& visibleObjects); /** Percept implementation for a static relative axis */ bool StaticAxisPercept(boost::shared_ptr<oxygen::PredicateList> predList); /** Percept implementation relative to the current orientation of the RestrictedVisionPerceptor node */ bool DynamicAxisPercept(boost::shared_ptr<oxygen::PredicateList> predList); /** Checks if the given object is occluded, seen from from my_pos */ bool CheckOcclusion(const salt::Vector3f& my_pos, const ObjectData& od) const; /** constructs a sense entry for the given object in the given predicate*/ void AddSense(oxygen::Predicate& predicate, ObjectData& od) const; /** applies noise to the setup ObjectData */ void ApplyNoise(ObjectData& od) const; virtual void OnLink(); virtual void OnUnlink(); protected: //! vision calibration error salt::Vector3f mError; //! true, if the absolute position of the agent is sensed. bool mSenseMyPos; //! sigma for random measurement error (distance) float mSigmaDist; //! sigma for random measurement error (horizontal angle) float mSigmaTheta; //! sigma for random measurement error (latitudal angle) float mSigmaPhi; //! absolute maximum value of the calibration error float mCalErrorAbs; //! flag if we should noisify the data bool mAddNoise; /** flag if the senses are always relative to the X-axis of the team, default true */ bool mStaticSenseAxis; //! horizontal opening of the vision cone unsigned int mHViewCone; //! vertical opening of the vision cone unsigned int mVViewCone; //! horizontal view direction in degrees float mPan; //! the lower bound for the horizontal view direction in degrees int mPanLower; //! the upper bound for the horizontal view direction in degrees int mPanUpper; //! vertical view direction in degrees float mTilt; //! the lower bound for the vertical view direction in degrees int mTiltLower; //! the upper bound for the vertical view direction in degrees int mTiltUpper; //! ray collider to check occlusion boost::shared_ptr<oxygen::RayCollider> mRay; //! random number generator for distance errors NormalRngPtr mDistRng; //! random number generator for angle errors NormalRngPtr mThetaRng; //! random number generator for angle errors NormalRngPtr mPhiRng; boost::shared_ptr<oxygen::Scene> mActiveScene; //! a reference to the next transorm parent boost::shared_ptr<oxygen::Transform> mTransformParent; //! a reference to the scene server boost::shared_ptr<oxygen::SceneServer> mSceneServer; //! a reference to the agent state boost::shared_ptr<AgentState> mAgentState; }; DECLARE_CLASS(RestrictedVisionPerceptor); #endif //VISIONPERCEPTOR_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:44
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/pantilteffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/pantilteffector Added Files: Tag: projectx pantiltaction.h pantilteffector.cpp pantilteffector.h pantilteffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: pantilteffector_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Mon May 9 2005 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: pantilteffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:39 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pantilteffector.h" using namespace oxygen; FUNCTION(PanTiltEffector,setMaxPanAngleDelta) { int inMaxPanAngleDelta; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inMaxPanAngleDelta)) ) { return false; } obj->SetMaxPanAngleDelta(inMaxPanAngleDelta); return true; } FUNCTION(PanTiltEffector,setMaxTiltAngleDelta) { int inMaxTiltAngleDelta; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inMaxTiltAngleDelta)) ) { return false; } obj->SetMaxTiltAngleDelta(inMaxTiltAngleDelta); return true; } FUNCTION(PanTiltEffector,setSigma) { float inSigma; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inSigma)) ) { return false; } obj->SetSigma(inSigma); return true; } void CLASS(PanTiltEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); DEFINE_FUNCTION(setSigma); DEFINE_FUNCTION(setMaxPanAngleDelta); DEFINE_FUNCTION(setMaxTiltAngleDelta); } --- NEW FILE: pantilteffector.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Mon May 9 2005 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: pantilteffector.h,v 1.1.2.1 2007/03/07 10:39:39 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef PANTILTEFFECTOR_H #define PANTILTEFFECTOR_H #include <salt/random.h> #include <oxygen/agentaspect/effector.h> #include <oxygen/physicsserver/body.h> #include <soccer/agentstate/agentstate.h> class PanTiltEffector : public oxygen::Effector { public: PanTiltEffector(); virtual ~PanTiltEffector(); /** realizes the action described by the ActionObject */ virtual bool Realize(boost::shared_ptr<oxygen::ActionObject> action); /** returns the name of the predicate this effector implements. */ virtual std::string GetPredicate() { return "pantilt"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); /** Set the maximum pan angle change. * The camera can pan to any angle, but the absolute pan angle * used for one 'pan' action may be restricted. A maximum pan * angle of 0 effectively disables panning, a value of 360 (or * greater) means no restriction. * @param max_pan_angle the maximum pan angle (in degrees) for one action */ void SetMaxPanAngleDelta(unsigned char max_pan_angle); /** Set the maximum tilt angle change. * Set the maximum absolute tilt angle change for one 'tilt' action. * @param max_tilt_angle the maximum tilt angle (in degrees) for one action */ void SetMaxTiltAngleDelta(unsigned char max_tilt_angle); /** Set the angle error parameter. * The error is normally distributed around zero. * @param sigma the sigma for the random number distribution */ void SetSigma(float sigma); protected: /** setup the reference to the agents body node */ virtual void OnLink(); /** remove the reference to the agents body node */ virtual void OnUnlink(); protected: typedef boost::shared_ptr<salt::NormalRNG<> > NormalRngPtr; /** the reference to the parent transform node */ boost::shared_ptr<oxygen::Transform> mTransformParent; /** the reference to the parents body node */ boost::shared_ptr<oxygen::Body> mBody; //! a reference to the agent state boost::shared_ptr<AgentState> mAgentState; /** random number generator for the error distribution of pan/tilt actions */ NormalRngPtr mActuatorErrorRNG; /** The maximum absolute value of the pan angle change */ unsigned char mMaxPanAngleDelta; /** The maximum absolute value of the tilt angle change */ unsigned char mMaxTiltAngleDelta; }; DECLARE_CLASS(PanTiltEffector); #endif // PANTILTEFFECTOR_H --- NEW FILE: pantiltaction.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Mon May 9 2005 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: pantiltaction.h,v 1.1.2.1 2007/03/07 10:39:39 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef DRIVEACTION_H #define DRIVEACTION_H #include <oxygen/gamecontrolserver/actionobject.h> #include <salt/vector.h> class PanTiltAction : public oxygen::ActionObject { public: PanTiltAction(const std::string& predicate, float pan, float tilt) : ActionObject(predicate), mPan(pan), mTilt(tilt) {} virtual ~PanTiltAction() {} //! @return the pan angle float GetPanAngle() const { return mPan; } //! @return the tilt angle float GetTiltAngle() const { return mTilt; } protected: //! the pan angle (in degrees) float mPan; //! the tilt angle (in degrees) float mTilt; }; #endif // DRIVEACTION_H --- NEW FILE: pantilteffector.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Mon May 9 2005 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: pantilteffector.cpp,v 1.1.2.1 2007/03/07 10:39:39 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pantiltaction.h" #include "pantilteffector.h" #include <salt/gmath.h> #include <zeitgeist/logserver/logserver.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/restrictedvisionperceptor/restrictedvisionperceptor.h> using namespace boost; using namespace oxygen; using namespace salt; PanTiltEffector::PanTiltEffector() : oxygen::Effector(), mMaxPanAngleDelta(90), mMaxTiltAngleDelta(10) { SetSigma(0.25); } PanTiltEffector::~PanTiltEffector() { } bool PanTiltEffector::Realize(boost::shared_ptr<ActionObject> action) { if (mBody.get() == 0) { return false; } shared_ptr<BaseNode> parent = shared_dynamic_cast<BaseNode>(make_shared(GetParent())); if (parent.get() == 0) { GetLog()->Error() << "ERROR: (PanTiltEffector) " << "parent node is not derived from BaseNode\n"; return false; } shared_ptr<PanTiltAction> panTiltAction = shared_dynamic_cast<PanTiltAction>(action); if (panTiltAction.get() == 0) { GetLog()->Error() << "ERROR: (PanTiltEffector) " << "cannot realize an unknown ActionObject\n"; return false; } float pan = panTiltAction->GetPanAngle(); // check for NAN if (std::isnan(pan)) { return true; } // cut down the pan angle if necessary if (gAbs(pan) > mMaxPanAngleDelta) { pan = gSign(pan) * mMaxPanAngleDelta; } float tilt = panTiltAction->GetTiltAngle(); // check for NAN if (std::isnan(tilt)) { return true; } // cut down the tilt angle if necessary if (gAbs(tilt) > mMaxTiltAngleDelta) { tilt = gSign(tilt) * mMaxTiltAngleDelta; } // apply random error if there is a RNG if (mActuatorErrorRNG.get() != 0) { pan += (*(mActuatorErrorRNG.get()))(); tilt += (*(mActuatorErrorRNG.get()))(); } // look for vision perceptor and apply change shared_ptr<RestrictedVisionPerceptor> rvp = parent->FindChildSupportingClass<RestrictedVisionPerceptor>(false); if (rvp.get() == 0) { GetLog()->Error() << "ERROR: (PanTiltEffector) " << "cannot find RestrictedVisionPerceptor instance\n"; return false; } rvp->ChangePanTilt(pan,tilt); return true; } shared_ptr<ActionObject> PanTiltEffector::GetActionObject(const Predicate& predicate) { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (PanTiltEffector) invalid predicate" << predicate.name << "\n"; return shared_ptr<ActionObject>(); } Predicate::Iterator iter = predicate.begin(); float pan; if (! predicate.AdvanceValue(iter, pan)) { GetLog()->Error() << "ERROR: (PanTiltEffector) 2 float parameters expected\n"; return shared_ptr<ActionObject>(new ActionObject(GetPredicate())); } float tilt; if (! predicate.AdvanceValue(iter, tilt)) { GetLog()->Error() << "ERROR: (PanTiltEffector) float parameter expected\n"; return shared_ptr<ActionObject>(new ActionObject(GetPredicate())); } return shared_ptr<ActionObject>(new PanTiltAction(GetPredicate(),pan,tilt)); } void PanTiltEffector::OnLink() { SoccerBase::GetTransformParent(*this,mTransformParent); SoccerBase::GetBody(*this,mBody); SoccerBase::GetAgentState(*this,mAgentState); } void PanTiltEffector::OnUnlink() { mActuatorErrorRNG.reset(); mTransformParent.reset(); mBody.reset(); } void PanTiltEffector::SetMaxPanAngleDelta(unsigned char max_pan_angle) { mMaxPanAngleDelta = max_pan_angle; } void PanTiltEffector::SetMaxTiltAngleDelta(unsigned char max_tilt_angle) { mMaxTiltAngleDelta = max_tilt_angle; } void PanTiltEffector::SetSigma(float sigma) { NormalRngPtr rng(new salt::NormalRNG<>(0.0,sigma)); mActuatorErrorRNG = rng; } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:42
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/objectstate In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/objectstate Added Files: Tag: projectx objectstate.cpp objectstate.h objectstate_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: objectstate.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: objectstate.cpp,v 1.1.2.1 2007/03/07 10:39:38 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "objectstate.h" #include <soccer/soccerbase/soccerbase.h> using namespace oxygen; ObjectState::ObjectState() : BaseNode() { } ObjectState::~ObjectState() { } void ObjectState::SetPerceptName(const std::string& name, TPerceptType pt) { mPerceptNames[pt] = name; } void ObjectState::SetPerceptName(const std::string& name, TPerceptType pt1, TPerceptType pt2) { // mPerceptNames[pt1] = "Player"; mPerceptNames[pt1] = "P"; mPerceptNames[pt2] = name; } std::string ObjectState::GetPerceptName(TPerceptType pt) const { TPerceptStringMap::const_iterator i = mPerceptNames.find(pt); if (i == mPerceptNames.end()) return std::string(); return i->second; } void ObjectState::SetID(const std::string& id, TPerceptType pt) { mIDs[pt] = id; } std::string ObjectState::GetID(TPerceptType pt) const { TPerceptStringMap::const_iterator i = mIDs.find(pt); if (i == mIDs.end()) return std::string(); return i->second; } boost::shared_ptr<oxygen::Transform> ObjectState::GetTransformParent() const { return mTransformParent; } void ObjectState::OnLink() { BaseNode::OnLink(); SoccerBase::GetTransformParent(*this,mTransformParent); } void ObjectState::OnUnlink() { BaseNode::OnUnlink(); mTransformParent.reset(); } --- NEW FILE: objectstate_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: objectstate_c.cpp,v 1.1.2.1 2007/03/07 10:39:38 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "objectstate.h" using namespace boost; using namespace oxygen; using namespace std; FUNCTION(ObjectState,setPerceptName) { string inName; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inName)) ) { return false; } obj->SetPerceptName(inName); return true; } FUNCTION(ObjectState,setID) { string inId; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inId)) ) { return false; } obj->SetID(inId); return true; } void CLASS(ObjectState)::DefineClass() { DEFINE_BASECLASS(oxygen/BaseNode); DEFINE_FUNCTION(setPerceptName); DEFINE_FUNCTION(setID); } --- NEW FILE: objectstate.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: objectstate.h,v 1.1.2.1 2007/03/07 10:39:38 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OBJECTSTATE_H #define OBJECTSTATE_H #include <oxygen/sceneserver/basenode.h> #include <oxygen/sceneserver/transform.h> class ObjectState : public oxygen::BaseNode { public: typedef enum TPerceptType { PT_Default, PT_TooFar, PT_Player }; public: ObjectState(); virtual ~ObjectState(); /** set the object name for perceptors */ virtual void SetPerceptName(const std::string& name, TPerceptType pt = PT_Default); /** set the object name for perceptors */ virtual void SetPerceptName(const std::string& name, TPerceptType pt , TPerceptType pt ); /** returns the object name for perceptors */ virtual std::string GetPerceptName(TPerceptType pt = PT_Default) const; /** set the object id for perceptors */ virtual void SetID(const std::string& id, TPerceptType pt = PT_Default); /** returns the object id */ virtual std::string GetID(TPerceptType pt = PT_Default) const; boost::shared_ptr<oxygen::Transform> GetTransformParent() const; protected: typedef std::map<TPerceptType, std::string> TPerceptStringMap; virtual void OnLink(); virtual void OnUnlink(); /** object names */ TPerceptStringMap mPerceptNames; /** object ids */ TPerceptStringMap mIDs; /** reference to the parent transform node*/ boost::shared_ptr<oxygen::Transform> mTransformParent; }; DECLARE_CLASS(ObjectState); #endif // OBJECTSTATE_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:42
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/kickeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/kickeffector Added Files: Tag: projectx kickaction.h kickeffector.cpp kickeffector.h kickeffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: kickeffector.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: kickeffector.h,v 1.1.2.1 2007/03/07 10:39:38 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KICKEFFECTOR_H #define KICKEFFECTOR_H #include <salt/random.h> #include <oxygen/agentaspect/agentaspect.h> #include <oxygen/agentaspect/effector.h> #include <oxygen/physicsserver/body.h> #include <soccer/ball/ball.h> #include <soccer/ballstateaspect/ballstateaspect.h> class BallStateAspect; class KickEffector : public oxygen::Effector { public: KickEffector(); virtual ~KickEffector(); /** realizes the action described by the ActionObject */ virtual bool Realize(boost::shared_ptr<oxygen::ActionObject> action); /** returns the name of the predicate this effector implements. */ virtual std::string GetPredicate() { return "kick"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); /** setup the reference to the ball body node */ virtual void OnLink(); /** remove the reference to the ball body node */ virtual void OnUnlink(); /** set the kick margin (the area within objects are kickable) */ void SetKickMargin(float margin); /** Set the force factor. * * The kick power vector is multiplied by this factor. */ void SetForceFactor(float force_factor); /** Set the torque factor. * * The kick torque vector is multiplied by this factor. */ void SetTorqueFactor(float torque_factor); /** Set the number of steps the force is applied. * \param steps the number of steps to apply force and torque. */ void SetSteps(int steps); /** Set the noise parameters. * If used, the noise values are normally distributed around 0.0. * Using this method, the sigmas of the distributions can be set. * Values <= 0 mean that no noise will be added. * * \param sigma_force for noise of the applied force * \param sigma_theta for noise of the angle in the x-y plane * \param sigma_phi_end for noise of the latitudal angle at the end of the range * \param sigma_phi_mid for noise of the latitudal angle in the middle of the angle range */ void SetNoiseParams(double sigma_force, double sigma_theta, double sigma_phi_end, double sigma_phi_mid); /** Set the maximum kick power. */ void SetMaxPower(float max_power); /** Set the latitudal angle range * \param min minimum latitudal kick angle in degrees * \param max maximum latitudal kick angle in degrees * * min has to be smaller than max. */ void SetAngleRange(float min, float max); protected: typedef boost::shared_ptr<salt::NormalRNG<> > NormalRngPtr; /** reference to the body node of the ball */ boost::shared_ptr<oxygen::Body> mBallBody; /** reference to the body node of the ball */ boost::shared_ptr<Ball> mBall; /** reference to the agent aspect */ boost::shared_ptr<oxygen::AgentAspect> mAgent; /** random number generator for the error distribution of the applied force */ NormalRngPtr mForceErrorRNG; /** random number generator for the error distribution of the theta */ NormalRngPtr mThetaErrorRNG; /** reference to the ball state aspect */ boost::shared_ptr<BallStateAspect> mBallStateAspect; private: /** the margin where objects can be kicked */ float mKickMargin; /** radius of the player */ float mPlayerRadius; /** radius of the ball */ float mBallRadius; /** force factor */ float mForceFactor; /** force factor */ float mTorqueFactor; /** the maximum kick power */ float mMaxPower; /** the minimal kick angle */ float mMinAngle; /** the maximum kick angle */ float mMaxAngle; /** number of simulation steps for applying kick force */ int mSteps; /** sigma for angle error at the end of the range (latitudal angle) */ double mSigmaPhiEnd; /** sigma for angle error in the middle of the range (latitudal angle) */ double mSigmaPhiMid; }; DECLARE_CLASS(KickEffector); #endif // KICKEFFECTOR_H --- NEW FILE: kickeffector.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: kickeffector.cpp,v 1.1.2.1 2007/03/07 10:39:37 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "kickaction.h" #include "kickeffector.h" #include <salt/random.h> #include <zeitgeist/logserver/logserver.h> #include <oxygen/sceneserver/transform.h> #include <oxygen/physicsserver/spherecollider.h> #include <soccer/soccerbase/soccerbase.h> using namespace boost; using namespace oxygen; using namespace salt; using namespace std; KickEffector::KickEffector() : oxygen::Effector(), mKickMargin(0.04),mPlayerRadius(0.0),mBallRadius(0.0), mForceFactor(4.0),mTorqueFactor(0.1), mMaxPower(100.0), mMinAngle(0.0),mMaxAngle(50.0), mSteps(10), mSigmaPhiEnd(0.9), mSigmaPhiMid(4.5) { } KickEffector::~KickEffector() { } bool KickEffector::Realize(boost::shared_ptr<ActionObject> action) { // this should also include the case when there is no ball // (because then there will be no body, neither). if (mBallBody.get() == 0) { return false; } if (mAgent.get() == 0) { GetLog()->Error() << "ERROR: (KickEffector) parent node is not derived from BaseNode\n"; return false; } shared_ptr<KickAction> kickAction = shared_dynamic_cast<KickAction>(action); if (kickAction.get() == 0) { GetLog()->Error() << "ERROR: (KickEffector) cannot realize an unknown ActionObject\n"; return false; } // if the agent doesn't have a body, we're done (this should never happen) if (mBall.get() == 0) return true; Vector3f force = mBallBody->GetWorldTransform().Pos() - mAgent->GetWorldTransform().Pos(); // the ball can be kicked if the distance is // less then Ball-Radius + Player-Radius + KickMargin AND // the player is close to the ground if (mAgent->GetWorldTransform().Pos().z() > mPlayerRadius + 0.01 || force.Length() > mPlayerRadius + mBallRadius + mKickMargin) { // ball is out of reach, or player is in the air: // kick has no effect return true; } // get the kick angle in the horizontal plane double theta = salt::gArcTan2(force[1], force[0]); if (mThetaErrorRNG.get() != 0) { theta += (*(mThetaErrorRNG.get()))(); } float phi = salt::gMin(salt::gMax(kickAction->GetAngle(), mMinAngle), mMaxAngle); if (mSigmaPhiEnd > 0.0 || mSigmaPhiMid > 0.0) { // f will be close to 0.0 if the angle is near the minimum or the maximum. // f will be close to 1.0 if the angle is somewhere in the middle of the range. float f = 1.0 - 2.0 * salt::gAbs((phi - mMinAngle) / (mMaxAngle - mMinAngle) - 0.5); // f is set to a number between mSigmaPhiEnd and mSigmaPhiMid f = salt::gMax(mSigmaPhiEnd + f * (mSigmaPhiMid-mSigmaPhiEnd), 0.0); phi = salt::NormalRNG<>(phi,f)(); } phi = salt::gDegToRad(90.0-phi); // x = r * cos(theta) * sin(90 - phi), with r = 1.0 force[0] = salt::gCos(theta) * salt::gSin(phi); // y = r * sin(theta) * sin(90 - phi), with r = 1.0 force[1] = salt::gSin(theta) * salt::gSin(phi); // z = r * cos(90 - phi), with r = 1.0 force[2] = salt::gCos(phi); float kick_power = salt::gMin(salt::gMax(kickAction->GetPower(), 1.0f), mMaxPower); if (mForceErrorRNG.get() != 0) { kick_power += (*(mForceErrorRNG.get()))(); } force *= (mForceFactor * kick_power); const Vector3f torque(-mTorqueFactor*force[1]/salt::g2PI, mTorqueFactor*force[0]/salt::g2PI, 0.0); mBall->SetAcceleration(mSteps,force,torque,mAgent); mBallStateAspect->UpdateLastKickingAgent(mAgent); return true; } shared_ptr<ActionObject> KickEffector::GetActionObject(const Predicate& predicate) { do { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (KickEffector) invalid predicate" << predicate.name << "\n"; break; } Predicate::Iterator iter = predicate.begin(); float angle; if (! predicate.AdvanceValue(iter, angle)) { GetLog()->Error() << "ERROR: (KickEffector) kick angle parameter expected\n"; break; } float power; if (! predicate.AdvanceValue(iter, power)) { GetLog()->Error() << "ERROR: (KickEffector) kick power expected\n"; break; } // construct the KickAction object return shared_ptr<KickAction>(new KickAction(GetPredicate(),angle,power)); } while (0); // some error happened return shared_ptr<ActionObject>(); } void KickEffector::OnLink() { SoccerBase::GetBall(*this,mBall); SoccerBase::GetBallBody(*this,mBallBody); mAgent = shared_dynamic_cast<AgentAspect>(make_shared(GetParent())); if (mAgent.get() == 0) { GetLog()->Error() << "ERROR: (KickEffector) parent node is not derived from AgentAspect\n"; return; } shared_ptr<SphereCollider> geom = shared_dynamic_cast<SphereCollider>(mAgent->GetChild("geometry")); if (geom.get() == 0) { GetLog()->Error() << "ERROR: (KickEffector) parent node has no SphereCollider child\n"; } else { mPlayerRadius = geom->GetRadius(); } if (! SoccerBase::GetBallCollider(*this,geom)) { GetLog()->Error() << "ERROR: (KickEffector) ball node has no SphereCollider child\n"; } else { mBallRadius = geom->GetRadius(); } if (mBallStateAspect.get() == 0) { mBallStateAspect = shared_dynamic_cast<BallStateAspect> (GetCore()->Get("/sys/server/gamecontrol/BallStateAspect")); if (mBallStateAspect.get() == 0) return; } } void KickEffector::OnUnlink() { mForceErrorRNG.reset(); mThetaErrorRNG.reset(); mBallBody.reset(); mAgent.reset(); } void KickEffector::SetKickMargin(float margin) { mKickMargin = margin; } void KickEffector::SetNoiseParams(double sigma_force, double sigma_theta, double sigma_phi_end, double sigma_phi_mid) { NormalRngPtr rng(new salt::NormalRNG<>(0.0,sigma_force)); mForceErrorRNG = rng; NormalRngPtr rng2(new salt::NormalRNG<>(0.0,sigma_theta)); mThetaErrorRNG = rng2; mSigmaPhiEnd = sigma_phi_end; mSigmaPhiMid = sigma_phi_mid; } void KickEffector::SetForceFactor(float force_factor) { mForceFactor = force_factor; } void KickEffector::SetTorqueFactor(float torque_factor) { mTorqueFactor = torque_factor; } void KickEffector::SetSteps(int steps) { mSteps = steps; } void KickEffector::SetMaxPower(float max_power) { mMaxPower = max_power; } void KickEffector::SetAngleRange(float min, float max) { if (max <= min) { GetLog()->Error() << "ERROR: (KickEffector) min. kick angle should be < max kick angle\n"; return; } mMinAngle = min; mMaxAngle = max; } --- NEW FILE: kickaction.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: kickaction.h,v 1.1.2.1 2007/03/07 10:39:37 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KICKACTION_H #define KICKACTION_H #include <oxygen/gamecontrolserver/actionobject.h> #include <salt/vector.h> class KickAction : public oxygen::ActionObject { public: KickAction(const std::string& predicate, float phi, float power) : ActionObject(predicate), mKickAngle(phi),mPower(power) {} virtual ~KickAction() {} /** returns the stored kick power */ float GetPower() const { return mPower; } /** returns the stored kick type */ float GetAngle() { return mKickAngle; } protected: /** the amount of force to be applied to be the ball */ float mPower; /** the kick angle to be applied to the ball */ float mKickAngle; }; #endif // KICKACTION_H --- NEW FILE: kickeffector_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: kickeffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:38 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "kickeffector.h" using namespace oxygen; FUNCTION(KickEffector,setKickMargin) { float inMargin; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inMargin)) ) { return false; } obj->SetKickMargin(inMargin); return true; } FUNCTION(KickEffector,setForceFactor) { float inForceFactor; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inForceFactor)) ) { return false; } obj->SetForceFactor(inForceFactor); return true; } FUNCTION(KickEffector,setTorqueFactor) { float inTorqueFactor; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inTorqueFactor)) ) { return false; } obj->SetTorqueFactor(inTorqueFactor); return true; } FUNCTION(KickEffector,setSteps) { int steps; if ( (in.GetSize() != 1) || (! in.GetValue(in[0], steps)) ) { return false; } obj->SetSteps(steps); return true; } FUNCTION(KickEffector,setNoiseParams) { float inForce; float inTheta; float inPhiEnd; float inPhiMid; if ( (in.GetSize() != 4) || (! in.GetValue(in[0], inForce)) || (! in.GetValue(in[1], inTheta)) || (! in.GetValue(in[2], inPhiEnd)) || (! in.GetValue(in[3], inPhiMid)) ) { return false; } obj->SetNoiseParams(inForce,inTheta,inPhiEnd,inPhiMid); return true; } FUNCTION(KickEffector,setMaxPower) { float inMaxPower; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(), inMaxPower)) ) { return false; } obj->SetMaxPower(inMaxPower); return true; } FUNCTION(KickEffector,setAngleRange) { float inMin; float inMax; if ( (in.GetSize() != 2) || (! in.GetValue(in[0], inMin)) || (! in.GetValue(in[1], inMax)) ) { return false; } obj->SetAngleRange(inMin,inMax); return true; } void CLASS(KickEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); DEFINE_FUNCTION(setKickMargin); DEFINE_FUNCTION(setForceFactor); DEFINE_FUNCTION(setTorqueFactor); DEFINE_FUNCTION(setSteps); DEFINE_FUNCTION(setNoiseParams); DEFINE_FUNCTION(setMaxPower); DEFINE_FUNCTION(setAngleRange); } |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:40
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/initeffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/initeffector Added Files: Tag: projectx initaction.h initeffector.cpp initeffector.h initeffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: initeffector.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: initeffector.cpp,v 1.1.2.1 2007/03/07 10:39:35 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "initaction.h" #include "initeffector.h" #include <zeitgeist/logserver/logserver.h> #include <oxygen/agentaspect/agentaspect.h> #include <oxygen/gamecontrolserver/predicate.h> #include <oxygen/physicsserver/body.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/agentstate/agentstate.h> #include <soccer/gamestateaspect/gamestateaspect.h> #include <sstream> using namespace boost; using namespace oxygen; using namespace salt; InitEffector::InitEffector() : oxygen::Effector() { } InitEffector::~InitEffector() { } bool InitEffector::Realize(boost::shared_ptr<ActionObject> action) { if ( (mGameState.get() == 0) || (mAgentAspect.get() == 0) ) { return false; } shared_ptr<InitAction> initAction = shared_dynamic_cast<InitAction>(action); if (initAction.get() == 0) { GetLog()->Error() << "ERROR: (InitEffector) cannot realize an unknown ActionObject\n"; return false; } // search for the AgentState shared_ptr<AgentState> state = shared_static_cast<AgentState> (mAgentAspect->GetChildOfClass("AgentState",true)); if (state.get() == 0) { GetLog()->Error() << "ERROR: (InitEffector) cannot find AgentState\n"; return false; } // register the uniform number and team index to the GameStateAspect mGameState->RequestUniform (state, initAction->GetName(), initAction->GetNumber()); // request an initial position for the agent and move it there Vector3f pos = mGameState->RequestInitPosition(state->GetTeamIndex()); shared_ptr<Body> body; if (SoccerBase::GetAgentBody(mAgentAspect,body)) { body->SetPosition(pos); body->SetVelocity(Vector3f(0,0,0)); body->SetAngularVelocity(Vector3f(0,0,0)); } return true; } shared_ptr<ActionObject> InitEffector::GetActionObject(const Predicate& predicate) { if (predicate.name != GetPredicate()) { GetLog()->Error() << "ERROR: (InitEffector) invalid predicate" << predicate.name << "\n"; return shared_ptr<ActionObject>(); } std::string name; predicate.GetValue(predicate.begin(),"teamname",name); int unum = 0; predicate.GetValue(predicate.begin(),"unum",unum); return shared_ptr<ActionObject>(new InitAction(GetPredicate(),name,unum)); } void InitEffector::OnLink() { mGameState = shared_dynamic_cast<GameStateAspect> (SoccerBase::GetControlAspect(*this,"GameStateAspect")); mAgentAspect = GetAgentAspect(); if (mAgentAspect.get() == 0) { GetLog()->Error() << "ERROR: (InitEffector) cannot get AgentAspect\n"; } } void InitEffector::OnUnlink() { mGameState.reset(); mAgentAspect.reset(); } --- NEW FILE: initeffector_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: initeffector_c.cpp,v 1.1.2.1 2007/03/07 10:39:36 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "initeffector.h" using namespace oxygen; void CLASS(InitEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); } --- NEW FILE: initaction.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: initaction.h,v 1.1.2.1 2007/03/07 10:39:35 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef INITACTION_H #define INITACTION_H #include <oxygen/gamecontrolserver/actionobject.h> class InitAction : public oxygen::ActionObject { public: InitAction(const std::string& predicate, const std::string& name, int number) : ActionObject(predicate), mName(name), mNumber(number) {} virtual ~InitAction() {} /** @return the requested team name */ const std::string& GetName() { return mName; } /** @return the requested uniform number */ int GetNumber() { return mNumber; } protected: /** the team name to set */ std::string mName; /** the requested uniform number */ int mNumber; }; #endif // INITACTION_H --- NEW FILE: initeffector.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: initeffector.h,v 1.1.2.1 2007/03/07 10:39:36 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef INITEFFECTOR_H #define INITEFFECTOR_H #include <oxygen/agentaspect/effector.h> class GameStateAspect; class InitEffector : public oxygen::Effector { // // functions // public: InitEffector(); virtual ~InitEffector(); /** realizes the action described by the ActionObject */ virtual bool Realize(boost::shared_ptr<oxygen::ActionObject> action); /** returns the name of the predicate this effector implements. */ virtual std::string GetPredicate() { return "init"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); protected: /** set up the reference GameStateAspect */ virtual void OnLink(); /** reset the reference to the GameStateAspect */ virtual void OnUnlink(); protected: /** reference to the GameStateAspect */ boost::shared_ptr<GameStateAspect> mGameState; /** reference to the AgentAspect */ boost::shared_ptr<oxygen::AgentAspect> mAgentAspect; }; DECLARE_CLASS(InitEffector); #endif // INITEFFECTOR_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:38
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/hearperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/hearperceptor Added Files: Tag: projectx hearperceptor.cpp hearperceptor.h hearperceptor_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: hearperceptor_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: hearperceptor_c.cpp,v 1.1.2.1 2007/03/07 10:39:35 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "hearperceptor.h" using namespace boost; using namespace oxygen; void CLASS(HearPerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); } --- NEW FILE: hearperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "hearperceptor.h" #include <soccer/agentstate/agentstate.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/gamestateaspect/gamestateaspect.h> //#include <soccer/soccertypes.h> using namespace oxygen; using namespace zeitgeist; using namespace std; HearPerceptor::HearPerceptor() : oxygen::Perceptor() { } HearPerceptor::~HearPerceptor() { } bool HearPerceptor::Percept(boost::shared_ptr<PredicateList> predList) { if ( (mAgentState.get() == 0) || (mGameState.get() == 0) ) { return false; } bool result = false; string message; float direction; if (mAgentState->GetSelfMessage(message)) { string self = "self"; Predicate& predicate = predList->AddPredicate(); predicate.name = "hear"; predicate.parameter.Clear(); predicate.parameter.AddValue(mGameState->GetTime()); predicate.parameter.AddValue(self); predicate.parameter.AddValue(message); result = true; } if (mAgentState->GetMessage(message, direction, true)) { Predicate& predicate = predList->AddPredicate(); predicate.name = "hear"; predicate.parameter.Clear(); predicate.parameter.AddValue(mGameState->GetTime()); predicate.parameter.AddValue(direction); predicate.parameter.AddValue(message); result = true; } if (mAgentState->GetMessage(message, direction, false)) { Predicate& predicate = predList->AddPredicate(); predicate.name = "hear"; predicate.parameter.Clear(); predicate.parameter.AddValue(mGameState->GetTime()); predicate.parameter.AddValue(direction); predicate.parameter.AddValue(message); result = true; } return result; } void HearPerceptor::OnLink() { SoccerBase::GetAgentState(*this, mAgentState); SoccerBase::GetGameState(*this, mGameState); } void HearPerceptor::OnUnlink() { mAgentState.reset(); mGameState.reset(); } --- NEW FILE: hearperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef HEARPERCEPTOR_H #define HEARPERCEPTOR_H #include <oxygen/agentaspect/perceptor.h> class AgentState; class GameStateAspect; namespace oxygen { class Predicate; } class HearPerceptor : public oxygen::Perceptor { public: HearPerceptor(); virtual ~HearPerceptor(); //! \return true, if valid data is available and false otherwise. virtual bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); protected: /** sets up the reference to the AgentState */ virtual void OnLink(); /** resets the reference to the AgentState */ virtual void OnUnlink(); protected: /** reference to the agentstate */ boost::shared_ptr<AgentState> mAgentState; /** reference to the GameStateAspect */ boost::shared_ptr<GameStateAspect> mGameState; }; DECLARE_CLASS(HearPerceptor); #endif // HEARPERCEPTOR_H |
From: Oliver O. <fr...@us...> - 2007-03-07 10:39:38
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/gamestateperceptor Added Files: Tag: projectx gamestateperceptor.cpp gamestateperceptor.h gamestateperceptor_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: gamestateperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: gamestateperceptor.cpp,v 1.1.2.1 2007/03/07 10:39:34 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "gamestateperceptor.h" #include <zeitgeist/logserver/logserver.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/agentstate/agentstate.h> #include <soccer/gamestateaspect/gamestateaspect.h> using namespace zeitgeist; using namespace oxygen; using namespace boost; using namespace std; GameStatePerceptor::GameStatePerceptor() : oxygen::Perceptor() { mFirstPercept = true; } GameStatePerceptor::~GameStatePerceptor() { } void GameStatePerceptor::InsertSoccerParam(Predicate& predicate, const std::string& name) { float value; if (! SoccerBase::GetSoccerVar(*this,name,value)) { return; } ParameterList& element = predicate.parameter.AddList(); element.AddValue(name); element.AddValue(value); } void GameStatePerceptor::InsertInitialPercept(Predicate& predicate) { // uniform number ParameterList& unumElement = predicate.parameter.AddList(); unumElement.AddValue(string("unum")); unumElement.AddValue(mAgentState->GetUniformNumber()); // team index std::string team; switch (mAgentState->GetTeamIndex()) { case TI_NONE : team = "none"; break; case TI_LEFT : team = "left"; break; case TI_RIGHT : team = "right"; break; } ParameterList& teamElement = predicate.parameter.AddList(); teamElement.AddValue(string("team")); teamElement.AddValue(team); // soccer variables // field geometry parameter InsertSoccerParam(predicate,"FieldLength"); InsertSoccerParam(predicate,"FieldWidth"); InsertSoccerParam(predicate,"FieldHeight"); InsertSoccerParam(predicate,"GoalWidth"); InsertSoccerParam(predicate,"GoalDepth"); InsertSoccerParam(predicate,"GoalHeight"); InsertSoccerParam(predicate,"BorderSize"); // agent parameter InsertSoccerParam(predicate,"AgentMass"); InsertSoccerParam(predicate,"AgentRadius"); InsertSoccerParam(predicate,"AgentMaxSpeed"); // ball parameter InsertSoccerParam(predicate,"BallRadius"); InsertSoccerParam(predicate,"BallMass"); } bool GameStatePerceptor::Percept(boost::shared_ptr<PredicateList> predList) { if ( (mGameState.get() == 0) || (mAgentState.get() == 0) ) { return false; } Predicate& predicate = predList->AddPredicate(); predicate.name = "GameState"; predicate.parameter.Clear(); // with the first GameState percept after the player is assigned // to a team it receives info about it's team and unum assignment // along with outher soccer parameters if ( (mFirstPercept) && (mAgentState->GetTeamIndex() != TI_NONE) ) { mFirstPercept = false; InsertInitialPercept(predicate); } // time ParameterList& timeElement = predicate.parameter.AddList(); timeElement.AddValue(string("time")); timeElement.AddValue(mGameState->GetTime()); // playmode ParameterList& pmElement = predicate.parameter.AddList(); pmElement.AddValue(string("playmode")); pmElement.AddValue(SoccerBase::PlayMode2Str(mGameState->GetPlayMode())); return true; } void GameStatePerceptor::OnLink() { SoccerBase::GetGameState(*this,mGameState); SoccerBase::GetAgentState(*this,mAgentState); } void GameStatePerceptor::OnUnlink() { mGameState.reset(); mAgentState.reset(); } --- NEW FILE: gamestateperceptor_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: gamestateperceptor_c.cpp,v 1.1.2.1 2007/03/07 10:39:34 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "gamestateperceptor.h" using namespace boost; using namespace oxygen; void CLASS(GameStatePerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); } --- NEW FILE: gamestateperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: gamestateperceptor.h,v 1.1.2.1 2007/03/07 10:39:34 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef GAMESTATEPERCEPTOR_H #define GAMESTATEPERCEPTOR_H #include <oxygen/agentaspect/perceptor.h> #include <soccer/soccertypes.h> class GameStateAspect; class AgentState; namespace oxygen { class Predicate; } class GameStatePerceptor : public oxygen::Perceptor { public: GameStatePerceptor(); virtual ~GameStatePerceptor(); //! \return true, if valid data is available and false otherwise. virtual bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); protected: /** sets up the reference to the GameStateAspect */ virtual void OnLink(); /** resets the reference to the GameStateAspect */ virtual void OnUnlink(); /** inserts predicate parameters the agent receives once after a successful init command into the predicate. These are it's uniform number and team as well as a subset of the soccer variables */ void InsertInitialPercept(oxygen::Predicate& predicate); /** inserts a soccer variable and its current value into the predicate */ void InsertSoccerParam(oxygen::Predicate& predicate, const std::string& name); protected: //! a reference to the game state boost::shared_ptr<GameStateAspect> mGameState; //! a reference to the agentstate boost::shared_ptr<AgentState> mAgentState; /** true until Percept() is called the first time after the agent is assigned to a team with a successful init command */ bool mFirstPercept; }; DECLARE_CLASS(GameStatePerceptor); #endif // GAMESTATEPERCEPTOR_H |