00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _FRAME_H__
00021 #define _FRAME_H__
00022
00023 #include "mbsim/element.h"
00024
00025 #ifdef HAVE_OPENMBVCPPINTERFACE
00026 #include "mbsim/utils/boost_parameters.h"
00027 #include "mbsim/utils/openmbv_utils.h"
00028 #endif
00029
00030 namespace MBSim {
00031
00039 class Frame : public Element {
00040 public:
00044 enum Feature {
00045 position, firstTangent, normal, secondTangent, cosy, position_cosy, velocity, angularVelocity, velocity_cosy, velocities, velocities_cosy, all
00046 };
00047
00052 Frame(const std::string &name = "dummy");
00053
00057 virtual ~Frame() {}
00058
00059
00060 std::string getType() const { return "Frame"; }
00061 virtual void plot(double t, double dt = 1);
00062 virtual void closePlot();
00063
00064
00065
00066 virtual int gethSize(int i=0) const { return hSize[i]; }
00067 virtual int gethInd(int i=0) const { return hInd[i]; }
00068
00069
00070 virtual const fmatvec::Vec3& getPosition() const { return WrOP; }
00071 virtual const fmatvec::SqrMat3& getOrientation() const { return AWP; }
00072 virtual fmatvec::Vec3& getPosition() { return WrOP; }
00073 virtual fmatvec::SqrMat3& getOrientation() { return AWP; }
00074 virtual void setPosition(const fmatvec::Vec3 &v) { WrOP = v; }
00075 virtual void setOrientation(const fmatvec::SqrMat3 &AWP_) { AWP = AWP_; }
00076 virtual const fmatvec::Vec3& getVelocity() const { return WvP; }
00077 virtual const fmatvec::Vec3& getAngularVelocity() const { return WomegaP; }
00078 virtual const fmatvec::Mat3xV& getJacobianOfTranslation(int j=0) const { return WJP[j]; }
00079 virtual const fmatvec::Mat3xV& getJacobianOfRotation(int j=0) const { return WJR[j]; }
00080 virtual const fmatvec::Vec3& getGyroscopicAccelerationOfTranslation(int j=0) const { return WjP[j]; }
00081 virtual const fmatvec::Vec3& getGyroscopicAccelerationOfRotation(int j=0) const { return WjR[j]; }
00082 virtual const fmatvec::Vec3& getAcceleration() const { return WaP; }
00083 virtual const fmatvec::Vec3& getAngularAcceleration() const { return WpsiP; }
00084 virtual void init(InitStage stage);
00085 #ifdef HAVE_OPENMBVCPPINTERFACE
00086 BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBV, tag, (optional (size,(double),1)(offset,(double),1)(transparency,(double),0))) {
00087 OpenMBVFrame ombv(size,offset,"[-1;1;1]",transparency);
00088 openMBVFrame=ombv.createOpenMBV();
00089 }
00090 void setOpenMBVFrame(OpenMBV::Frame* frame) { openMBVFrame = frame; }
00091 OpenMBV::Frame* getOpenMBVFrame() {return openMBVFrame; }
00092 #endif
00093
00094
00095
00096 void sethSize(int size, int i=0) { hSize[i] = size; }
00097 void sethInd(int ind, int i=0) { hInd[i] = ind; }
00098
00099 fmatvec::Vec3& getVelocity() { return WvP; }
00100 fmatvec::Vec3& getAngularVelocity() { return WomegaP; }
00101 void setVelocity(const fmatvec::Vec3 &v) { WvP = v; }
00102 void setAngularVelocity(const fmatvec::Vec3 &omega) { WomegaP = omega; }
00103
00104 void setJacobianOfTranslation(const fmatvec::Mat3xV &WJP_, int j=0) { WJP[j]=WJP_; }
00105 void setGyroscopicAccelerationOfTranslation(const fmatvec::Vec3 &WjP_, int j=0) { WjP[j]=WjP_; }
00106 void setJacobianOfRotation(const fmatvec::Mat3xV &WJR_, int j=0) { WJR[j]=WJR_; }
00107 void setGyroscopicAccelerationOfRotation(const fmatvec::Vec3 &WjR_, int j=0) { WjR[j]=WjR_; }
00108 fmatvec::Mat3xV& getJacobianOfTranslation(int j=0) { return WJP[j]; }
00109 fmatvec::Mat3xV& getJacobianOfRotation(int j=0) { return WJR[j]; }
00110 fmatvec::Vec3& getGyroscopicAccelerationOfTranslation(int j=0) { return WjP[j]; }
00111 fmatvec::Vec3& getGyroscopicAccelerationOfRotation(int j=0) { return WjR[j]; }
00112 fmatvec::Vec3& getAcceleration() { return WaP; }
00113 fmatvec::Vec3& getAngularAcceleration() { return WpsiP; }
00114 void setAcceleration(const fmatvec::Vec3 &a) { WaP = a; }
00115 void setAngularAcceleration(const fmatvec::Vec3 &psi) { WpsiP = psi; }
00116
00117 virtual void initializeUsingXML(xercesc::DOMElement *element);
00118 virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
00119
00120
00121 virtual Element * getByPathSearch(std::string path);
00122
00123 protected:
00125
00126
00127
00128
00132 int hSize[2], hInd[2];
00133
00137 fmatvec::Vec3 WrOP;
00138
00142 fmatvec::SqrMat3 AWP;
00143
00147 fmatvec::Vec3 WvP, WomegaP;
00148
00152 fmatvec::Mat3xV WJP[2], WJR[2];
00153
00157 fmatvec::Vec3 WjP[2], WjR[2];
00158
00162 fmatvec::Vec3 WaP, WpsiP;
00163
00164 #ifdef HAVE_OPENMBVCPPINTERFACE
00165 OpenMBV::Frame* openMBVFrame;
00166 #endif
00167 };
00168
00173 class FixedRelativeFrame : public Frame {
00174
00175 public:
00176 FixedRelativeFrame(const std::string &name = "dummy", const fmatvec::Vec3 &r=fmatvec::Vec3(), const fmatvec::SqrMat3 &A=fmatvec::SqrMat3(fmatvec::EYE), const Frame *refFrame=0) : Frame(name), R(refFrame), RrRP(r), ARP(A) {}
00177
00178 std::string getType() const { return "FixedRelativeFrame"; }
00179
00180 virtual void init(InitStage stage);
00181
00182 void setRelativePosition(const fmatvec::Vec3 &r) { RrRP = r; }
00183 void setRelativeOrientation(const fmatvec::SqrMat3 &A) { ARP = A; }
00184 void setFrameOfReference(const Frame *frame) { R = frame; }
00185 void setFrameOfReference(const std::string &frame) { saved_frameOfReference = frame; }
00186
00187 const fmatvec::Vec3& getRelativePosition() const { return RrRP; }
00188 const fmatvec::SqrMat3& getRelativeOrientation() const { return ARP; }
00189 const Frame* getFrameOfReference() const { return R; }
00190 const fmatvec::Vec3& getWrRP() const { return WrRP; }
00191
00192 void updateRelativePosition() { WrRP = R->getOrientation()*RrRP; }
00193 void updatePosition() { updateRelativePosition(); setPosition(R->getPosition() + WrRP); }
00194 void updateOrientation() { setOrientation(R->getOrientation()*ARP); }
00195 void updateVelocity() { setVelocity(R->getVelocity() + crossProduct(R->getAngularVelocity(), WrRP)); }
00196 void updateAngularVelocity() { setAngularVelocity(R->getAngularVelocity()); }
00197 void updateStateDependentVariables() {
00198 updatePosition();
00199 updateOrientation();
00200 updateVelocity();
00201 updateAngularVelocity();
00202 }
00203 void updateJacobians(int j=0) {
00204 fmatvec::SqrMat3 tWrRP = tilde(WrRP);
00205 setJacobianOfTranslation(R->getJacobianOfTranslation(j) - tWrRP*R->getJacobianOfRotation(j),j);
00206 setJacobianOfRotation(R->getJacobianOfRotation(j),j);
00207 setGyroscopicAccelerationOfTranslation(R->getGyroscopicAccelerationOfTranslation(j) - tWrRP*R->getGyroscopicAccelerationOfRotation(j) + crossProduct(R->getAngularVelocity(),crossProduct(R->getAngularVelocity(),WrRP)),j);
00208 setGyroscopicAccelerationOfRotation(R->getGyroscopicAccelerationOfRotation(j),j);
00209 }
00210 void updateStateDerivativeDependentVariables(const fmatvec::Vec &ud) {
00211 setAcceleration(getJacobianOfTranslation()*ud + getGyroscopicAccelerationOfTranslation());
00212 setAngularAcceleration(getJacobianOfRotation()*ud + getGyroscopicAccelerationOfRotation());
00213 }
00214
00215 virtual void initializeUsingXML(xercesc::DOMElement *element);
00216 virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
00217
00218 protected:
00219 const Frame *R;
00220 fmatvec::Vec3 RrRP, WrRP;
00221 fmatvec::SqrMat3 ARP;
00222 std::string saved_frameOfReference;
00223 };
00224
00225 }
00226
00227 #endif
00228