mbsim  4.0.0
MBSim Kernel
rigid_body_observer.h
1 /* Copyright (C) 2004-2015 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@gmail.com
18  */
19 
20 #ifndef _RIGID_BODY_OBSERVER_H__
21 #define _RIGID_BODY_OBSERVER_H__
22 
23 #include "mbsim/observers/observer.h"
24 
25 #include "mbsim/utils/boost_parameters.h"
26 #include "mbsim/utils/openmbv_utils.h"
27 
28 namespace MBSim {
29 
30  class RigidBody;
31 
32  class RigidBodyObserver: public Observer {
33  private:
34  RigidBody* body;
35  Frame *frameOfReference;
36  std::shared_ptr<OpenMBVInteractionArrow> ombvForce, ombvMoment;
37  std::shared_ptr<OpenMBVArrow> ombvWeight, ombvAxisOfRotation, ombvMomentum, ombvAngularMomentum, ombvDerivativeOfMomentum, ombvDerivativeOfAngularMomentum;
38  std::vector<std::shared_ptr<OpenMBV::Arrow>> FArrow, MArrow;
39  std::shared_ptr<OpenMBV::Arrow> FWeight, openMBVAxisOfRotation, openMBVMomentum, openMBVAngularMomentum, openMBVDerivativeOfMomentum, openMBVDerivativeOfAngularMomentum;
40  std::string saved_body;
41  std::string saved_frameOfReference;
42 
43 //#ifndef SWIG
44 // double (RigidBodyObserver::*evalOMBVForceColorRepresentation[2])();
45 // double (RigidBodyObserver::*evalOMBVMomentColorRepresentation[2])();
46 // double (RigidBodyObserver::*evalOMBVWeightColorRepresentation[2])();
47 // double (RigidBodyObserver::*evalOMBVAxisOfRotationColorRepresentation[2])();
48 // double (RigidBodyObserver::*evalOMBVMomentumColorRepresentation[2])();
49 // double (RigidBodyObserver::*evalOMBVAngularMomentumColorRepresentation[2])();
50 // double (RigidBodyObserver::*evalOMBVDerivativeOfMomentumColorRepresentation[2])();
51 // double (RigidBodyObserver::*evalOMBVDerivativeOfAngularMomentumColorRepresentation[2])();
52 //#endif
53 // double evalNoneGreen() { return 0.5; }
54 // double evalNoneRed() { return 1; }
55 // double evalAbsoluteForce();
56 // double evalAbsoluteMoment();
57 // double evalAbsoluteWeight();
58 // double evalAbsoluteMomentum();
59 
60  public:
61  RigidBodyObserver(const std::string &name="");
62  void setRigidBody(RigidBody *body_) { body = body_; }
63  void setFrameOfReference(Frame *frameOfReference_) { frameOfReference = frameOfReference_; }
64 
65  void init(InitStage stage, const InitConfigSet &config);
66  void initializeUsingXML(xercesc::DOMElement *element);
67  void plot();
68 
70  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVWeight, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
71  ombvWeight = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
72  }
73 
75  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVJointForce, tag, (optional (sideOfInteraction,(OpenMBVInteractionArrow::SideOfInteraction),OpenMBVInteractionArrow::action)(scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
76  ombvForce = std::shared_ptr<OpenMBVInteractionArrow>(new OpenMBVInteractionArrow(sideOfInteraction,scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
77  }
78 
80  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVJointMoment, tag, (optional (sideOfInteraction,(OpenMBVInteractionArrow::SideOfInteraction),OpenMBVInteractionArrow::action)(scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
81  ombvMoment = std::shared_ptr<OpenMBVInteractionArrow>(new OpenMBVInteractionArrow(sideOfInteraction,scaleLength,scaleSize,OpenMBVArrow::toDoubleHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
82  }
83 
85  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVAxisOfRotation, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
86  ombvAxisOfRotation = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
87  }
88 
89  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVMomentum, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::fromPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
90  ombvMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
91  }
92 
93  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVAngularMomentum, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::fromPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
94  ombvAngularMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toDoubleHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
95  }
96 
97  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVDerivativeOfMomentum, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::fromPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
98  ombvDerivativeOfMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
99  }
100 
101  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVDerivativeOfAngularMomentum, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBVArrow::ReferencePoint),OpenMBVArrow::fromPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation),OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
102  ombvDerivativeOfAngularMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toDoubleHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
103  }
104  };
105 
106 }
107 
108 #endif
BOOST_PARAMETER_MEMBER_FUNCTION((void), enableOpenMBVJointForce, tag,(optional(sideOfInteraction,(OpenMBVInteractionArrow::SideOfInteraction), OpenMBVInteractionArrow::action)(scaleLength,(double), 1)(scaleSize,(double), 1)(referencePoint,(OpenMBVArrow::ReferencePoint), OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation), OpenMBVArrow::none)(minimalColorValue,(double), 0)(maximalColorValue,(double), 1)(diffuseColor,(const fmatvec::Vec3 &), fmatvec::Vec3(std::vector< double >{-1, 1, 1}))(transparency,(double), 0)(pointSize,(double), 0)(lineWidth,(double), 0)))
Visualize the joint force.
Definition: rigid_body_observer.h:75
Definition: openmbv_utils.h:79
Definition: openmbv_utils.h:111
Definition: rigid_body_observer.h:32
BOOST_PARAMETER_MEMBER_FUNCTION((void), enableOpenMBVWeight, tag,(optional(scaleLength,(double), 1)(scaleSize,(double), 1)(referencePoint,(OpenMBVArrow::ReferencePoint), OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation), OpenMBVArrow::none)(minimalColorValue,(double), 0)(maximalColorValue,(double), 1)(diffuseColor,(const fmatvec::Vec3 &), fmatvec::Vec3(std::vector< double >{-1, 1, 1}))(transparency,(double), 0)(pointSize,(double), 0)(lineWidth,(double), 0)))
Visualize the weight.
Definition: rigid_body_observer.h:70
BOOST_PARAMETER_MEMBER_FUNCTION((void), enableOpenMBVJointMoment, tag,(optional(sideOfInteraction,(OpenMBVInteractionArrow::SideOfInteraction), OpenMBVInteractionArrow::action)(scaleLength,(double), 1)(scaleSize,(double), 1)(referencePoint,(OpenMBVArrow::ReferencePoint), OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation), OpenMBVArrow::none)(minimalColorValue,(double), 0)(maximalColorValue,(double), 1)(diffuseColor,(const fmatvec::Vec3 &), fmatvec::Vec3(std::vector< double >{-1, 1, 1}))(transparency,(double), 0)(pointSize,(double), 0)(lineWidth,(double), 0)))
Visualize the joint moment.
Definition: rigid_body_observer.h:80
InitStage
The stages of the initialization.
Definition: element.h:62
void plot()
plots time dependent data
Definition: rigid_body_observer.cc:163
std::string name
name of element
Definition: element.h:235
BOOST_PARAMETER_MEMBER_FUNCTION((void), enableOpenMBVAxisOfRotation, tag,(optional(scaleLength,(double), 1)(scaleSize,(double), 1)(referencePoint,(OpenMBVArrow::ReferencePoint), OpenMBVArrow::toPoint)(colorRepresentation,(OpenMBVArrow::ColorRepresentation), OpenMBVArrow::none)(minimalColorValue,(double), 0)(maximalColorValue,(double), 1)(diffuseColor,(const fmatvec::Vec3 &), fmatvec::Vec3(std::vector< double >{-1, 1, 1}))(transparency,(double), 0)(pointSize,(double), 0)(lineWidth,(double), 0)))
Visualize the center of rotation.
Definition: rigid_body_observer.h:85
cartesian frame on bodies used for application of e.g. links and loads
Definition: frame.h:39
Definition: observer.h:26
rigid bodies with arbitrary kinematics
Definition: rigid_body.h:50
namespace MBSim
Definition: eigenanalyzer.cc:47
void init(InitStage stage, const InitConfigSet &config)
plots time series header
Definition: rigid_body_observer.cc:44