00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of rcssserver3D 00004 Thu Nov 8 2005 00005 Copyright (C) 2005 RoboCup Soccer Server 3D Maintenance Group 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; version 2 of the License. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 #include "hingeperceptor.h" 00021 #include <zeitgeist/logserver/logserver.h> 00022 00023 using namespace oxygen; 00024 using namespace zeitgeist; 00025 using namespace boost; 00026 using namespace std; 00027 00028 HingePerceptor::HingePerceptor() : Perceptor() 00029 { 00030 } 00031 00032 HingePerceptor::~HingePerceptor() 00033 { 00034 } 00035 00036 void HingePerceptor::OnLink() 00037 { 00038 mJoint = make_shared(FindParentSupportingClass<HingeJoint>()); 00039 00040 if (mJoint.get() == 0) 00041 { 00042 GetLog()->Error() 00043 << "(HingePerceptor) ERROR: found no HingeJoint parent\n"; 00044 } 00045 00046 } 00047 00048 void HingePerceptor::OnUnlink() 00049 { 00050 mJoint.reset(); 00051 } 00052 00053 void HingePerceptor::InsertAxisAngle(Predicate& predicate) 00054 { 00055 ParameterList& axisElement = predicate.parameter.AddList(); 00056 axisElement.AddValue(string("axis")); 00057 axisElement.AddValue(mJoint->GetAngle()); 00058 } 00059 00060 void HingePerceptor::InsertAxisRate(Predicate& predicate) 00061 { 00062 ParameterList& axisElement = predicate.parameter.AddList(); 00063 axisElement.AddValue(string("rate")); 00064 axisElement.AddValue(mJoint->GetAngleRate()); 00065 } 00066 00067 bool HingePerceptor::Percept(boost::shared_ptr<oxygen::PredicateList> predList) 00068 { 00069 if (mJoint.get() == 0) 00070 { 00071 return false; 00072 } 00073 00074 Predicate& predicate = predList->AddPredicate(); 00075 predicate.name = "HJ"; 00076 predicate.parameter.Clear(); 00077 00078 ParameterList& nameElement = predicate.parameter.AddList(); 00079 nameElement.AddValue(string("name")); 00080 nameElement.AddValue(GetName()); 00081 00082 InsertAxisAngle(predicate); 00083 InsertAxisRate(predicate); 00084 00085 return true; 00086 } 00087 00088