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

universaljointperceptor.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    Thu Jan 4 2006
00005    Copyright (C) 2006 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 "universaljointperceptor.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 UniversalJointPerceptor::UniversalJointPerceptor() : Perceptor()
00029 {
00030 }
00031 
00032 UniversalJointPerceptor::~UniversalJointPerceptor()
00033 {
00034 }
00035 
00036 void UniversalJointPerceptor::OnLink()
00037 {
00038     mJoint = make_shared(FindParentSupportingClass<UniversalJoint>());
00039 
00040     if (mJoint.get() == 0)
00041         {
00042             GetLog()->Error()
00043                 << "(UniversalJointPerceptor) ERROR: found no UniversalJoint parent\n";
00044         }
00045 
00046 }
00047 
00048 void UniversalJointPerceptor::OnUnlink()
00049 {
00050     mJoint.reset();
00051 }
00052 
00053 void UniversalJointPerceptor::InsertAxisAngle(Predicate& predicate, Joint::EAxisIndex idx)
00054 {
00055     ParameterList& axisElement = predicate.parameter.AddList();
00056     if (idx == Joint::AI_FIRST)
00057     {
00058         axisElement.AddValue(string("axis1"));
00059         axisElement.AddValue(mJoint->GetAngle(Joint::AI_FIRST));
00060     }
00061     else
00062     {
00063         axisElement.AddValue(string("axis2"));
00064         axisElement.AddValue(mJoint->GetAngle(Joint::AI_SECOND));
00065     }
00066 }
00067 
00068 void UniversalJointPerceptor::InsertAxisRate(Predicate& predicate, Joint::EAxisIndex idx)
00069 {
00070     ParameterList& axisElement = predicate.parameter.AddList();
00071     if (idx == Joint::AI_FIRST)
00072     {
00073         axisElement.AddValue(string("rate1"));
00074         axisElement.AddValue(mJoint->GetAngleRate(Joint::AI_FIRST));
00075     }
00076     else
00077     {
00078         axisElement.AddValue(string("rate2"));
00079         axisElement.AddValue(mJoint->GetAngleRate(Joint::AI_SECOND));
00080     }
00081 }
00082 
00083 bool UniversalJointPerceptor::Percept(boost::shared_ptr<oxygen::PredicateList> predList)
00084 {
00085     if (mJoint.get() == 0)
00086         {
00087             return false;
00088         }
00089 
00090     Predicate& predicate = predList->AddPredicate();
00091     predicate.name = "UJ";
00092     predicate.parameter.Clear();
00093 
00094     ParameterList& nameElement = predicate.parameter.AddList();
00095     nameElement.AddValue(string("name"));
00096     nameElement.AddValue(GetName());
00097 
00098     InsertAxisAngle(predicate, Joint::AI_FIRST);
00099     InsertAxisRate(predicate, Joint::AI_FIRST);
00100     InsertAxisAngle(predicate, Joint::AI_SECOND);
00101     InsertAxisRate(predicate, Joint::AI_SECOND);
00102 
00103     return true;
00104 }
00105 
00106 

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