00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _KINEMATIC_EXCITATION_H_
00021 #define _KINEMATIC_EXCITATION_H_
00022
00023 #include "mbsim/link_mechanics.h"
00024 #include "mbsim/rigid_body.h"
00025 #include "mbsim/frame.h"
00026
00027 #ifdef HAVE_OPENMBVCPPINTERFACE
00028 #include "mbsim/utils/boost_parameters.h"
00029 #include "mbsim/utils/openmbv_utils.h"
00030 #endif
00031
00032 namespace MBSim {
00033
00034 class KinematicExcitation : public LinkMechanics {
00035 protected:
00036 Function<fmatvec::VecV(fmatvec::VecV,fmatvec::VecV)> *func;
00037 RigidBody* body;
00038 Frame C;
00039 public:
00040 KinematicExcitation(const std::string &name);
00041 void updateh(double, int i=0);
00042 void updateW(double, int i=0);
00043 void updateJacobians(double t, int j=0);
00044 void updatehRef(const fmatvec::Vec &hParent, int j=0);
00045 void updateWRef(const fmatvec::Mat &WParent, int j=0);
00046 void setDependentBody(RigidBody* body_) {body = body_;}
00047
00048 bool isActive() const { return true; }
00049 bool gActiveChanged() { return false; }
00050 void init(InitStage stage);
00051 bool isSetValued() const;
00052 void calclaSize(int j);
00053 void calcgSize(int j);
00054 void calcgdSize(int j);
00055
00056 void setForceFunction(Function<fmatvec::VecV(fmatvec::VecV,fmatvec::VecV)> *func_) {
00057 func=func_;
00058 func->setParent(this);
00059 func->setName("Force");
00060 }
00061
00062 void plot(double t, double dt=1);
00063
00064 #ifdef HAVE_OPENMBVCPPINTERFACE
00065
00066 BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVForce, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
00067 OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00068 FArrow=ombv.createOpenMBV();
00069 }
00070 void setOpenMBVForce(const boost::shared_ptr<OpenMBV::Arrow> &arrow) { FArrow=arrow; }
00071
00073 BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVMoment, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
00074 OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00075 MArrow=ombv.createOpenMBV();
00076 }
00077 void setOpenMBVMoment(const boost::shared_ptr<OpenMBV::Arrow> &arrow) { MArrow=arrow; }
00078 #endif
00079
00080 protected:
00081 #ifdef HAVE_OPENMBVCPPINTERFACE
00082 boost::shared_ptr<OpenMBV::Arrow> FArrow, MArrow;
00083 #endif
00084
00085 };
00086
00087 class GeneralizedPositionExcitation : public KinematicExcitation {
00088 protected:
00089 Function<fmatvec::VecV(double)> *f;
00090 public:
00091 GeneralizedPositionExcitation(const std::string &name) : KinematicExcitation(name) {}
00092
00093 void calcxSize();
00094
00095 void updatexd(double t);
00096 void updateg(double t);
00097 void updategd(double t);
00098 void updatewb(double t, int i=0);
00099
00100 std::string getType() const { return "GeneralizedPositionExcitation"; }
00101
00102 void setExcitationFunction(Function<fmatvec::VecV(double)>* f_) {
00103 f = f_;
00104 f->setParent(this);
00105 f->setName("Excitation");
00106 }
00107
00108 void init(Element::InitStage stage) {
00109 KinematicExcitation::init(stage);
00110 f->init(stage);
00111 }
00112 };
00113
00114 class GeneralizedVelocityExcitation : public KinematicExcitation {
00115 protected:
00116 Function<fmatvec::VecV(fmatvec::VecV,double)> *f;
00117 public:
00118 GeneralizedVelocityExcitation(const std::string &name) : KinematicExcitation(name) {}
00119
00120 void calcxSize();
00121
00122 void updatexd(double t);
00123 void updateg(double t);
00124 void updategd(double t);
00125 void updatewb(double t, int i=0);
00126
00127 std::string getType() const { return "GeneralizedVelocityExcitation"; }
00128
00129 void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV,double)>* f_) {
00130 f = f_;
00131 f->setParent(this);
00132 f->setName("Excitation");
00133 }
00134 void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV)>* f_) {
00135 setExcitationFunction(new StateDependentFunction<fmatvec::VecV>(f_));
00136 }
00137 void setExcitationFunction(Function<fmatvec::VecV(double)>* f_) {
00138 setExcitationFunction(new TimeDependentFunction<fmatvec::VecV>(f_));
00139 }
00140 };
00141
00142 class GeneralizedAccelerationExcitation : public KinematicExcitation {
00143 protected:
00144 Function<fmatvec::VecV(fmatvec::VecV,double)> *f;
00145 public:
00146 GeneralizedAccelerationExcitation(const std::string &name) : KinematicExcitation(name) {}
00147
00148 void calcxSize();
00149
00150 void updatexd(double t);
00151 void updateg(double t);
00152 void updategd(double t);
00153 void updatewb(double t, int i=0);
00154
00155 std::string getType() const { return "GeneralizedAccelerationExcitation"; }
00156
00157 void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV,double)>* f_) {
00158 f = f_;
00159 f->setParent(this);
00160 f->setName("Excitation");
00161 }
00162 void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV)>* f_) {
00163 setExcitationFunction(new StateDependentFunction<fmatvec::VecV>(f_));
00164 }
00165 void setExcitationFunction(Function<fmatvec::VecV(double)>* f_) {
00166 setExcitationFunction(new TimeDependentFunction<fmatvec::VecV>(f_));
00167 }
00168
00169 void init(Element::InitStage stage) {
00170 KinematicExcitation::init(stage);
00171 f->init(stage);
00172 }
00173 };
00174
00175 }
00176
00177 #endif