Simbody 3.7
Loading...
Searching...
No Matches
MobilizedBody_Custom.h
Go to the documentation of this file.
1#ifndef SimTK_SIMBODY_MOBILIZED_BODY_CUSTOM_H_
2#define SimTK_SIMBODY_MOBILIZED_BODY_CUSTOM_H_
3
4/* -------------------------------------------------------------------------- *
5 * Simbody(tm) *
6 * -------------------------------------------------------------------------- *
7 * This is part of the SimTK biosimulation toolkit originating from *
8 * Simbios, the NIH National Center for Physics-Based Simulation of *
9 * Biological Structures at Stanford, funded under the NIH Roadmap for *
10 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11 * *
12 * Portions copyright (c) 2008-13 Stanford University and the Authors. *
13 * Authors: Peter Eastman, Michael Sherman *
14 * Contributors: *
15 * *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17 * not use this file except in compliance with the License. You may obtain a *
18 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19 * *
20 * Unless required by applicable law or agreed to in writing, software *
21 * distributed under the License is distributed on an "AS IS" BASIS, *
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23 * See the License for the specific language governing permissions and *
24 * limitations under the License. *
25 * -------------------------------------------------------------------------- */
26
32
33namespace SimTK {
34
35//==============================================================================
36// MOBILIZED BODY :: CUSTOM
37//==============================================================================
73public:
74 class Implementation;
75 class ImplementationImpl;
76
79 Custom() {}
80
98 Custom(MobilizedBody& parent, Implementation* implementation,
99 const Transform& X_PF, const Body& bodyInfo, const Transform& X_BM,
100 Direction direction=Forward);
101
104 Custom(MobilizedBody& parent, Implementation* implementation,
105 const Body& bodyInfo, Direction direction=Forward);
106
// hide from Doxygen
110protected:
113
114};
115
116// We only want the template instantiation to occur once. This symbol is
117// defined in the Simbody compilation unit that defines the MobilizedBody class
118// but should not be defined any other time.
119#ifndef SimTK_SIMBODY_DEFINING_MOBILIZED_BODY
121 MobilizedBody::Custom::ImplementationImpl>;
122#endif
123
124
125//==============================================================================
126// MOBILIZED BODY :: CUSTOM :: IMPLEMENTATION
127//==============================================================================
131 : public PIMPLHandle<Implementation,ImplementationImpl>
132{
133public:
134 // No default constructor because you have to supply at least the SimbodyMatterSubsystem
135 // to which this MobilizedBody belongs.
136
139
144 virtual Implementation* clone() const = 0;
145
169 Implementation(SimbodyMatterSubsystem&, int nu, int nq, int nAngles=0);
170
174 Vector getQ(const State& s) const;
175
177 Vector getU(const State& s) const;
178
182 Vector getQDot(const State& s) const;
183
185 Vector getUDot(const State& s) const;
186
190 Vector getQDotDot(const State& s) const;
191
197
205
214 bool getUseEulerAngles(const State& s) const;
215
223
228
229
237 virtual Transform calcMobilizerTransformFromQ(const State& s, int nq, const Real* q) const = 0;
238
239
256 virtual SpatialVec multiplyByHMatrix(const State& s, int nu, const Real* u) const = 0;
257
266 virtual void multiplyByHTranspose(const State& s, const SpatialVec& F, int nu, Real* f) const = 0;
267
277 virtual SpatialVec multiplyByHDotMatrix(const State& s, int nu, const Real* u) const = 0;
278
287 virtual void multiplyByHDotTranspose(const State& s, const SpatialVec& F, int nu, Real* f) const = 0;
288
299 virtual void multiplyByN(const State& s, bool transposeMatrix,
300 int nIn, const Real* in, int nOut, Real* out) const;
301
312 virtual void multiplyByNInv(const State& s, bool transposeMatrix,
313 int nIn, const Real* in, int nOut, Real* out) const;
314
325 virtual void multiplyByNDot(const State& s, bool transposeMatrix,
326 int nIn, const Real* in, int nOut, Real* out) const;
327
328 // Methods for setting Mobilizer initial conditions. Note -- I've stripped this
329 // down to the two basic routines but the built-ins have 8 so that you can
330 // specify only rotations or translations. I'm not sure that's needed here and
331 // I suppose you could add more routines later if needed.
332 // Eventually it might be nice to provide default implementation here that would
333 // use a root finder to attempt to solve these initial condition problems. For
334 // most joints there is a much more direct way to do it, and sometimes there
335 // are behavioral choices to make, which is why it is nice to have mobilizer-specific
336 // overrides for these.
337
346 virtual void setQToFitTransform(const State&, const Transform& X_FM, int nq, Real* q) const;
347
359 virtual void setUToFitVelocity(const State&, const SpatialVec& V_FM, int nu, Real* u) const;
360
368 (const State& s, Stage stage, Array_<DecorativeGeometry>& geom) const
369 {
370 }
372
373
382
384
392 virtual void realizeTopology(State&) const { }
393
402 virtual void realizeModel(State&) const { }
403
407 virtual void realizeInstance(const State&) const { }
408
413 virtual void realizeTime(const State&) const { }
414
421 virtual void realizePosition(const State&) const { }
422
429 virtual void realizeVelocity(const State&) const { }
430
437 virtual void realizeDynamics(const State&) const { }
438
445 virtual void realizeAcceleration(const State&) const { }
446
452 virtual void realizeReport(const State&) const { }
454
455 friend class MobilizedBody::CustomImpl;
456};
457
458} // namespace SimTK
459
460#endif // SimTK_SIMBODY_MOBILIZED_BODY_CUSTOM_H_
461
462
463
This defines the MobilizedBody class, which associates a new body (the "child", "outboard",...
#define SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(DERIVED, DERIVED_IMPL, PARENT)
Definition PrivateImplementation.h:343
#define SimTK_SIMBODY_EXPORT
Definition Simbody/include/simbody/internal/common.h:68
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library ...
Definition Array.h:1520
The Body class represents a reference frame that can be used to describe mass properties and geometry...
Definition Body.h:55
This is the implementation class for Custom mobilizers.
Definition MobilizedBody_Custom.h:132
virtual void realizeModel(State &) const
The Matter Subsystem's realizeModel() method will call this method along with the built-in MobilizedB...
Definition MobilizedBody_Custom.h:402
virtual void realizeVelocity(const State &) const
The Matter Subsystem's realizeVelocity() method will call this method along with the built-in Mobiliz...
Definition MobilizedBody_Custom.h:429
virtual Transform calcMobilizerTransformFromQ(const State &s, int nq, const Real *q) const =0
Given values for this mobilizer's nq generalized coordinates q, compute X_FM(q), that is,...
Vector getU(const State &s) const
Return a Vector containing all the generalized speeds u currently in use by this mobilizer.
Vector getUDot(const State &s) const
Return a Vector containing all the generalized accelerations udot currently in use by this mobilizer.
void invalidateTopologyCache() const
Call this if you want to make sure that the next realizeTopology() call does something.
virtual SpatialVec multiplyByHMatrix(const State &s, int nu, const Real *u) const =0
Calculate V_FM(u) = H*u where H=H(q) is the joint transition matrix mapping the mobilities to the rel...
virtual void realizePosition(const State &) const
The Matter Subsystem's realizePosition() method will call this method along with the built-in Mobiliz...
Definition MobilizedBody_Custom.h:421
virtual void realizeTopology(State &) const
The Matter Subsystem's realizeTopology() method will call this method along with the built-in Mobiliz...
Definition MobilizedBody_Custom.h:392
virtual void setQToFitTransform(const State &, const Transform &X_FM, int nq, Real *q) const
Find a set of q's for this mobilizer that best approximate the supplied Transform which requests a pa...
virtual void realizeAcceleration(const State &) const
The Matter Subsystem's realizeAcceleration() method will call this method along with the built-in Mob...
Definition MobilizedBody_Custom.h:445
virtual ~Implementation()
Destructor is virtual so derived classes get a chance to clean up if necessary.
virtual void realizeTime(const State &) const
The Matter Subsystem's realizeTime() method will call this method along with the built-in MobilizedBo...
Definition MobilizedBody_Custom.h:413
SpatialVec getMobilizerVelocity(const State &s) const
Get the cross-mobilizer velocity V_FM, the relative velocity of this body's "moving" mobilizer frame ...
virtual void multiplyByHTranspose(const State &s, const SpatialVec &F, int nu, Real *f) const =0
Calculate f = ~H*F where F is a spatial force (torque+force) and f is its mapping onto the mobilities...
Transform getMobilizerTransform(const State &s) const
Get the cross-mobilizer transform X_FM, the body's "moving" mobilizer frame M measured and expressed ...
virtual void multiplyByN(const State &s, bool transposeMatrix, int nIn, const Real *in, int nOut, Real *out) const
Calculate out_q = N(q)*in_u (e.g., qdot=N*u) or out_u = ~N*in_q.
virtual void setUToFitVelocity(const State &, const SpatialVec &V_FM, int nu, Real *u) const
Find a set of u's (generalized speeds) for this mobilizer that best approximate the supplied spatial ...
Vector getQDot(const State &s) const
Return a Vector containing all the generalized coordinate derivatives qdot currently in use by this m...
virtual SpatialVec multiplyByHDotMatrix(const State &s, int nu, const Real *u) const =0
Calculate A0_FM = HDot*u where HDot=HDot(q,u) is the time derivative of H.
Vector getQDotDot(const State &s) const
Return a Vector containing all the generalized coordinate second derivatives qdotdot currently in use...
virtual void calcDecorativeGeometryAndAppend(const State &s, Stage stage, Array_< DecorativeGeometry > &geom) const
Implement this optional method if you would like your MobilizedBody to generate any suggestions for g...
Definition MobilizedBody_Custom.h:368
virtual void realizeInstance(const State &) const
The Matter Subsystem's realizeInstance() method will call this method along with the built-in Mobiliz...
Definition MobilizedBody_Custom.h:407
virtual void realizeDynamics(const State &) const
The Matter Subsystem's realizeDynamics() method will call this method along with the built-in Mobiliz...
Definition MobilizedBody_Custom.h:437
virtual void multiplyByNInv(const State &s, bool transposeMatrix, int nIn, const Real *in, int nOut, Real *out) const
Calculate out_u = NInv(q)*in_q (e.g., u=NInv*qdot) or out_q = ~NInv*in_u.
bool getUseEulerAngles(const State &s) const
Get whether rotations are being represented as quaternions or Euler angles.
Vector getQ(const State &s) const
Return a Vector containing all the generalized coordinates q currently in use by this mobilizer.
virtual Implementation * clone() const =0
This method should produce a deep copy identical to the concrete derived Implementation object underl...
virtual void multiplyByNDot(const State &s, bool transposeMatrix, int nIn, const Real *in, int nOut, Real *out) const
Calculate out_q = NDot(q)*in_u or out_u = ~NDot*in_q.
virtual void realizeReport(const State &) const
The Matter Subsystem's realizeReport() method will call this method along with the built-in Mobilized...
Definition MobilizedBody_Custom.h:452
virtual void multiplyByHDotTranspose(const State &s, const SpatialVec &F, int nu, Real *f) const =0
Calculate f = ~HDot*F where F is a spatial vector and f is its mapping onto the mobilities.
Implementation(SimbodyMatterSubsystem &, int nu, int nq, int nAngles=0)
This Implementation base class constructor sets the topological defaults for the number of mobilities...
The handle class MobilizedBody::Custom (dataless) and its companion class MobilizedBody::Custom::Impl...
Definition MobilizedBody_Custom.h:72
Custom(MobilizedBody &parent, Implementation *implementation, const Transform &X_PF, const Body &bodyInfo, const Transform &X_BM, Direction direction=Forward)
Create a Custom mobilizer between an existing parent (inboard) body P and a new child (outboard) body...
Implementation & updImplementation()
Custom()
Default constructor provides an empty handle that can be assigned to reference any MobilizedBody::Cus...
Definition MobilizedBody_Custom.h:79
const Implementation & getImplementation() const
Custom(MobilizedBody &parent, Implementation *implementation, const Body &bodyInfo, Direction direction=Forward)
Abbreviated constructor you can use if the mobilizer frames are coincident with the parent and child ...
A MobilizedBody is Simbody's fundamental body-and-joint object used to parameterize a system's motion...
Definition MobilizedBody.h:169
Direction
Constructors can take an argument of this type to indicate that the mobilizer is being defined in the...
Definition MobilizedBody.h:181
This class provides some infrastructure useful in making SimTK Private Implementation (PIMPL) classes...
Definition PrivateImplementation.h:106
This subsystem contains the bodies ("matter") in the multibody system, the mobilizers (joints) that d...
Definition SimbodyMatterSubsystem.h:133
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition Stage.h:66
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition State.h:280
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double.
Definition SimTKcommon/include/SimTKcommon/internal/common.h:606