00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }