Simbody  3.4 (development)
MobilizedBody_Custom.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_MOBILIZED_BODY_CUSTOM_H_
00002 #define SimTK_SIMBODY_MOBILIZED_BODY_CUSTOM_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                               Simbody(tm)                                  *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2008-13 Stanford University and the Authors.        *
00013  * Authors: Peter Eastman, Michael Sherman                                    *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00031 #include "simbody/internal/MobilizedBody.h"
00032 
00033 namespace SimTK {
00034 
00035 //==============================================================================
00036 //                        MOBILIZED BODY :: CUSTOM  
00037 //==============================================================================
00072 class SimTK_SIMBODY_EXPORT MobilizedBody::Custom : public MobilizedBody {
00073 public:
00074     class Implementation;
00075     class ImplementationImpl;
00076 
00079     Custom() {}
00080 
00098     Custom(MobilizedBody& parent, Implementation* implementation, 
00099            const Transform& X_PF, const Body& bodyInfo, const Transform& X_BM,
00100            Direction direction=Forward);
00101     
00104     Custom(MobilizedBody& parent, Implementation* implementation, 
00105            const Body& bodyInfo, Direction direction=Forward);
00106  // hide from Doxygen
00108     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Custom, CustomImpl, MobilizedBody);
00110 protected:
00111     const Implementation& getImplementation() const;
00112     Implementation&       updImplementation();
00113 
00114 };
00115 
00116 // We only want the template instantiation to occur once. This symbol is 
00117 // defined in the Simbody compilation unit that defines the MobilizedBody class
00118 // but should not be defined any other time.
00119 #ifndef SimTK_SIMBODY_DEFINING_MOBILIZED_BODY
00120     extern template class PIMPLHandle<MobilizedBody::Custom::Implementation, 
00121                                       MobilizedBody::Custom::ImplementationImpl>;
00122 #endif
00123 
00124 
00125 //==============================================================================
00126 //                  MOBILIZED BODY :: CUSTOM :: IMPLEMENTATION
00127 //==============================================================================
00130 class SimTK_SIMBODY_EXPORT MobilizedBody::Custom::Implementation 
00131   : public PIMPLHandle<Implementation,ImplementationImpl> 
00132 {
00133 public:
00134     // No default constructor because you have to supply at least the SimbodyMatterSubsystem
00135     // to which this MobilizedBody belongs.
00136 
00138     virtual ~Implementation();
00139 
00144     virtual Implementation* clone() const = 0;
00145 
00169     Implementation(SimbodyMatterSubsystem&, int nu, int nq, int nAngles=0);
00170 
00174     Vector getQ(const State& s) const;
00175     
00177     Vector getU(const State& s) const;
00178 
00182     Vector getQDot(const State& s) const;
00183 
00185     Vector getUDot(const State& s) const;
00186     
00190     Vector getQDotDot(const State& s) const;
00191 
00196     Transform getMobilizerTransform(const State& s) const;
00197 
00204     SpatialVec getMobilizerVelocity(const State& s) const;
00205 
00214     bool getUseEulerAngles(const State& s) const;
00215 
00222     void invalidateTopologyCache() const;
00223 
00228 
00229 
00237     virtual Transform calcMobilizerTransformFromQ(const State& s, int nq, const Real* q) const = 0;
00238 
00239 
00256     virtual SpatialVec multiplyByHMatrix(const State& s, int nu, const Real* u) const = 0;
00257 
00266     virtual void multiplyByHTranspose(const State& s, const SpatialVec& F, int nu, Real* f) const = 0;
00267 
00277     virtual SpatialVec multiplyByHDotMatrix(const State& s, int nu, const Real* u) const = 0;
00278 
00287     virtual void multiplyByHDotTranspose(const State& s, const SpatialVec& F, int nu, Real* f) const = 0;
00288 
00299     virtual void multiplyByN(const State& s, bool transposeMatrix, 
00300                              int nIn, const Real* in, int nOut, Real* out) const;
00301 
00312     virtual void multiplyByNInv(const State& s, bool transposeMatrix, 
00313                                 int nIn, const Real* in, int nOut, Real* out) const;
00314 
00325     virtual void multiplyByNDot(const State& s, bool transposeMatrix, 
00326                                 int nIn, const Real* in, int nOut, Real* out) const;
00327 
00328         // Methods for setting Mobilizer initial conditions. Note -- I've stripped this
00329         // down to the two basic routines but the built-ins have 8 so that you can 
00330         // specify only rotations or translations. I'm not sure that's needed here and
00331         // I suppose you could add more routines later if needed.
00332         // Eventually it might be nice to provide default implementation here that would
00333         // use a root finder to attempt to solve these initial condition problems. For
00334         // most joints there is a much more direct way to do it, and sometimes there
00335         // are behavioral choices to make, which is why it is nice to have mobilizer-specific
00336         // overrides for these.
00337 
00346     virtual void setQToFitTransform(const State&, const Transform& X_FM, int nq, Real* q) const;
00347 
00359     virtual void setUToFitVelocity(const State&, const SpatialVec& V_FM, int nu, Real* u) const;
00360 
00367     virtual void calcDecorativeGeometryAndAppend
00368        (const State& s, Stage stage, Array_<DecorativeGeometry>& geom) const
00369     {
00370     }
00372 
00373 
00382 
00384 
00385 
00386 
00387 
00388 
00389 
00390 
00391 
00392     virtual void realizeTopology(State&) const { }
00393 
00402     virtual void realizeModel(State&) const { }
00403 
00407     virtual void realizeInstance(const State&) const { }
00408 
00413     virtual void realizeTime(const State&) const { }
00414 
00421     virtual void realizePosition(const State&) const { }
00422 
00429     virtual void realizeVelocity(const State&) const { }
00430 
00437     virtual void realizeDynamics(const State&) const { }
00438 
00445     virtual void realizeAcceleration(const State&) const { }
00446 
00452     virtual void realizeReport(const State&) const { }
00454 
00455     friend class MobilizedBody::CustomImpl;
00456 };
00457 
00458 } // namespace SimTK
00459 
00460 #endif // SimTK_SIMBODY_MOBILIZED_BODY_CUSTOM_H_
00461 
00462 
00463 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines