Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

agentstateperceptor.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: agentstateperceptor.cpp,v 1.5 2006/03/13 23:22:42 fruit Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #include "agentstateperceptor.h"
00023 #include <soccer/agentstate/agentstate.h>
00024 #include <soccer/soccerbase/soccerbase.h>
00025 #include <soccer/restrictedvisionperceptor/restrictedvisionperceptor.h>
00026 
00027 using namespace oxygen;
00028 using namespace zeitgeist;
00029 using namespace boost;
00030 
00031 AgentStatePerceptor::AgentStatePerceptor() : oxygen::Perceptor()
00032 {
00033     mPerceptRate = 10;
00034     mSenses = 0;
00035 }
00036 
00037 AgentStatePerceptor::~AgentStatePerceptor()
00038 {
00039 }
00040 
00041 bool
00042 AgentStatePerceptor::Percept(boost::shared_ptr<PredicateList> predList)
00043 {
00044     if (mAgentState.get() == 0)
00045     {
00046         return false;
00047     }
00048 
00049     --mSenses;
00050 
00051     if (mSenses > 0)
00052     {
00053         return false;
00054     }
00055 
00056     mSenses = mPerceptRate;
00057 
00058     Predicate& predicate = predList->AddPredicate();
00059     predicate.name = "AgentState";
00060     predicate.parameter.Clear();
00061 
00062     shared_ptr<BaseNode> parent =
00063         shared_dynamic_cast<BaseNode>(make_shared(GetParent()));
00064 
00065     if (parent.get() == 0)
00066     {
00067         GetLog()->Warning() << "WARNING: (AgentStatePerceptor) "
00068                             << "parent node is not derived from BaseNode\n";
00069     } else {
00070         shared_ptr<RestrictedVisionPerceptor> rvp =
00071             parent->FindChildSupportingClass<RestrictedVisionPerceptor>(false);
00072         if (rvp.get() == 0)
00073         {
00074             GetLog()->Warning() << "WARNING: (AgentStatePerceptor) "
00075                                 << "cannot find RestrictedVisionPerceptor instance\n";
00076         } else {
00077             // pan tilt information
00078             ParameterList& pantiltElement = predicate.parameter.AddList();
00079             pantiltElement.AddValue(std::string("pan_tilt"));
00080             pantiltElement.AddValue(static_cast<int>(roundf(rvp->GetPan())));
00081             pantiltElement.AddValue(static_cast<int>(roundf(rvp->GetTilt())));
00082         }
00083     }
00084 
00085     // battery
00086     ParameterList& batteryElement = predicate.parameter.AddList();
00087     batteryElement.AddValue(std::string("battery"));
00088     batteryElement.AddValue(mAgentState->GetBattery());
00089 
00090     // temperature
00091     ParameterList& tempElement = predicate.parameter.AddList();
00092     tempElement.AddValue(std::string("temp"));
00093     tempElement.AddValue(mAgentState->GetTemperature());
00094 
00095     return true;
00096 }
00097 
00098 void
00099 AgentStatePerceptor::OnLink()
00100 {
00101     SoccerBase::GetAgentState(*this,mAgentState);
00102 }
00103 
00104 void
00105 AgentStatePerceptor::OnUnlink()
00106 {
00107     mAgentState.reset();
00108 }

Generated on Thu Apr 6 15:25:37 2006 for rcssserver3d by  doxygen 1.4.4