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