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

hinge2effector.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) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: hinge2effector.cpp,v 1.2 2004/05/17 09:13:30 rollmark 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 "hinge2effector.h"
00023 #include "hinge2action.h"
00024 
00025 using namespace oxygen;
00026 using namespace zeitgeist;
00027 using namespace boost;
00028 using namespace std;
00029 
00030 Hinge2Effector::Hinge2Effector() : Effector()
00031 {
00032     SetName("hinge2");
00033 }
00034 
00035 Hinge2Effector::~Hinge2Effector()
00036 {
00037 }
00038 
00039 bool Hinge2Effector::Realize(boost::shared_ptr<ActionObject> action)
00040 {
00041     if (mJoint.get() == 0)
00042         {
00043             return false;
00044         }
00045 
00046     shared_ptr<Hinge2Action> hinge2Action =
00047         shared_dynamic_cast<Hinge2Action>(action);
00048 
00049     if (hinge2Action.get() == 0)
00050     {
00051         GetLog()->Error()
00052             << "ERROR: (Hinge2Effector) cannot realize an "
00053             << "unknown ActionObject\n";
00054         return false;
00055     }
00056 
00057     mJoint->SetAngularMotorVelocity
00058         (Joint::AI_SECOND, hinge2Action->GetMotorVelocity());
00059 
00060     return true;
00061 }
00062 
00063 shared_ptr<ActionObject> Hinge2Effector::GetActionObject(const Predicate& predicate)
00064 {
00065     for(;;)
00066         {
00067             if (mJoint.get() == 0)
00068                 {
00069                     break;
00070                 }
00071 
00072             if (predicate.name != GetPredicate())
00073                 {
00074                     GetLog()->Error()
00075                         << "ERROR: (KickEffector) invalid predicate"
00076                         << predicate.name << "\n";
00077                     break;
00078                 }
00079 
00080             Predicate::Iterator iter = predicate.begin();
00081 
00082             float velocity;
00083             if (! predicate.AdvanceValue(iter, velocity))
00084                 {
00085                     GetLog()->Error()
00086                         << "ERROR: (KickEffector) motor velocity expected\n";
00087                     break;
00088                 }
00089 
00090             return shared_ptr<Hinge2Action>(new Hinge2Action(GetPredicate(),velocity));
00091         }
00092 
00093     return shared_ptr<ActionObject>();
00094 }
00095 
00096 void Hinge2Effector::OnLink()
00097 {
00098     mJoint = make_shared(FindParentSupportingClass<Hinge2Joint>());
00099 
00100     if (mJoint.get() == 0)
00101         {
00102             GetLog()->Error()
00103                 << "(Hinge2Effector) ERROR: found no Hinge2Joint parent\n";
00104         }
00105 
00106 }
00107 
00108 void Hinge2Effector::OnUnlink()
00109 {
00110     mJoint.reset();
00111 }

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