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 Frame *outputFrame { nullptr };
37 std::shared_ptr<OpenMBVInteractionArrow> ombvForce, ombvMoment;
38 std::shared_ptr<OpenMBVArrow> ombvWeight, ombvAxisOfRotation, ombvMomentum, ombvAngularMomentum, ombvDerivativeOfMomentum, ombvDerivativeOfAngularMomentum;
39 std::vector<std::shared_ptr<OpenMBV::Arrow>> FArrow, MArrow;
40 std::shared_ptr<OpenMBV::Arrow> FWeight, openMBVAxisOfRotation, openMBVMomentum, openMBVAngularMomentum, openMBVDerivativeOfMomentum, openMBVDerivativeOfAngularMomentum;
41 std::string saved_body;
42 std::string saved_frameOfReference;
43 std::string saved_outputFrame;
44
45 //#ifndef SWIG
46 // double (RigidBodyObserver::*evalOMBVForceColorRepresentation[2])();
47 // double (RigidBodyObserver::*evalOMBVMomentColorRepresentation[2])();
48 // double (RigidBodyObserver::*evalOMBVWeightColorRepresentation[2])();
49 // double (RigidBodyObserver::*evalOMBVAxisOfRotationColorRepresentation[2])();
50 // double (RigidBodyObserver::*evalOMBVMomentumColorRepresentation[2])();
51 // double (RigidBodyObserver::*evalOMBVAngularMomentumColorRepresentation[2])();
52 // double (RigidBodyObserver::*evalOMBVDerivativeOfMomentumColorRepresentation[2])();
53 // double (RigidBodyObserver::*evalOMBVDerivativeOfAngularMomentumColorRepresentation[2])();
54 //#endif
55 // double evalNoneGreen() { return 0.5; }
56 // double evalNoneRed() { return 1; }
57 // double evalAbsoluteForce();
58 // double evalAbsoluteMoment();
59 // double evalAbsoluteWeight();
60 // double evalAbsoluteMomentum();
61
62 public:
63 RigidBodyObserver(const std::string &name="");
64 void setRigidBody(RigidBody *body_) { body = body_; }
65 void setFrameOfReference(Frame *frameOfReference_) { frameOfReference = frameOfReference_; }
66 void setOutputFrame(Frame *outputFrame_) { outputFrame = outputFrame_; }
67
68 void init(InitStage stage, const InitConfigSet &config);
69 void initializeUsingXML(xercesc::DOMElement *element);
70 void plot();
71
73 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))) {
74 ombvWeight = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
75 }
76
78 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))) {
79 ombvForce = std::shared_ptr<OpenMBVInteractionArrow>(new OpenMBVInteractionArrow(sideOfInteraction,scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
80 }
81
83 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))) {
84 ombvMoment = std::shared_ptr<OpenMBVInteractionArrow>(new OpenMBVInteractionArrow(sideOfInteraction,scaleLength,scaleSize,OpenMBVArrow::toDoubleHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
85 }
86
88 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))) {
89 ombvAxisOfRotation = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
90 }
91
92 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))) {
93 ombvMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
94 }
95
96 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))) {
97 ombvAngularMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toDoubleHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
98 }
99
100 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))) {
101 ombvDerivativeOfMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
102 }
103
104 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))) {
105 ombvDerivativeOfAngularMomentum = std::shared_ptr<OpenMBVArrow>(new OpenMBVArrow(scaleLength,scaleSize,OpenMBVArrow::toDoubleHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
106 }
107 };
108
109 }
110
111 #endif
MBSim::RigidBodyObserver::BOOST_PARAMETER_MEMBER_FUNCTION
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:78
MBSim::OpenMBVArrow
Definition: openmbv_utils.h:79
MBSim::OpenMBVInteractionArrow
Definition: openmbv_utils.h:111
MBSim::RigidBodyObserver
Definition: rigid_body_observer.h:32
MBSim::RigidBodyObserver::BOOST_PARAMETER_MEMBER_FUNCTION
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:73
MBSim::RigidBodyObserver::BOOST_PARAMETER_MEMBER_FUNCTION
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:83
MBSim::Element::InitStage
InitStage
The stages of the initialization.
Definition: element.h:62
MBSim::RigidBodyObserver::plot
void plot()
plots time dependent data
Definition: rigid_body_observer.cc:156
MBSim::Element::name
std::string name
name of element
Definition: element.h:260
MBSim::RigidBodyObserver::BOOST_PARAMETER_MEMBER_FUNCTION
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:88
MBSim::Frame
cartesian frame on bodies used for application of e.g. links and loads
Definition: frame.h:39
MBSim::Observer
Definition: observer.h:26
MBSim::RigidBody
rigid bodies with arbitrary kinematics
Definition: rigid_body.h:50
MBSim
namespace MBSim
Definition: bilateral_constraint.cc:30
MBSim::RigidBodyObserver::init
void init(InitStage stage, const InitConfigSet &config)
plots time series header
Definition: rigid_body_observer.cc:48