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

hingeeffector.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    Wed Nov 9 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 "hingeeffector.h"
00021 #include "hingeaction.h"
00022 
00023 using namespace oxygen;
00024 using namespace zeitgeist;
00025 using namespace salt;
00026 using namespace boost;
00027 using namespace std;
00028 
00029 HingeEffector::HingeEffector() : Effector()
00030 {
00031     SetName("hinge");
00032 }
00033 
00034 HingeEffector::~HingeEffector()
00035 {
00036 }
00037 
00038 bool HingeEffector::Realize(boost::shared_ptr<ActionObject> action)
00039 {
00040     if (mJoint.get() == 0)
00041         {
00042             return false;
00043         }
00044 
00045     shared_ptr<HingeAction> hingeAction =
00046         shared_dynamic_cast<HingeAction>(action);
00047 
00048     if (hingeAction.get() == 0)
00049     {
00050         GetLog()->Error()
00051             << "ERROR: (HingeEffector) cannot realize an "
00052             << "unknown ActionObject\n";
00053         return false;
00054     }
00055 
00056     mJoint->SetParameter(dParamVel, hingeAction->GetMotorVelocity());
00057 
00058     return true;
00059 }
00060 
00061 shared_ptr<ActionObject> HingeEffector::GetActionObject(const Predicate& predicate)
00062 {
00063     for(;;)
00064         {
00065             if (mJoint.get() == 0)
00066                 {
00067                     break;
00068                 }
00069 
00070             if (predicate.name != GetPredicate())
00071                 {
00072                     GetLog()->Error()
00073                         << "ERROR: (HingeEffector) invalid predicate"
00074                         << predicate.name << "\n";
00075                     break;
00076                 }
00077 
00078             Predicate::Iterator iter = predicate.begin();
00079 
00080             float velocity;
00081             if (! predicate.AdvanceValue(iter, velocity))
00082                 {
00083                     GetLog()->Error()
00084                         << "ERROR: (HingeEffector) motor velocity expected\n";
00085                     break;
00086                 }
00087 
00088             return shared_ptr<HingeAction>(new HingeAction(GetPredicate(),velocity));
00089         }
00090 
00091     return shared_ptr<ActionObject>();
00092 }
00093 
00094 void HingeEffector::OnLink()
00095 {
00096     mJoint = make_shared(FindParentSupportingClass<HingeJoint>());
00097 
00098     if (mJoint.get() == 0)
00099         {
00100             GetLog()->Error()
00101                 << "(HingeEffector) ERROR: found no HingeJoint parent\n";
00102         }
00103 
00104 }
00105 
00106 void HingeEffector::OnUnlink()
00107 {
00108     mJoint.reset();
00109 }

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