Simbody  3.4 (development)
Motion.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_MOTION_H_
00002 #define SimTK_SIMBODY_MOTION_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) 2009-13 Stanford University and the Authors.        *
00013  * Authors: 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 "SimTKcommon.h"
00032 #include "simbody/internal/common.h"
00033 
00034 namespace SimTK {
00035 
00036 class SimbodyMatterSubsystem;
00037 class MobilizedBody;
00038 class Motion;
00039 class MotionImpl;
00040 
00041 // We only want the template instantiation to occur once. This symbol is defined 
00042 // in the Simbody compilation unit that defines the Motion class but should not 
00043 // be defined any other time.
00044 #ifndef SimTK_SIMBODY_DEFINING_MOTION
00045     extern template class PIMPLHandle<Motion, MotionImpl, true>;
00046 #endif
00047 
00048 
00049 //==============================================================================
00050 //                                 MOTION
00051 //==============================================================================
00107 class SimTK_SIMBODY_EXPORT Motion : public PIMPLHandle<Motion,MotionImpl,true> {
00108 public:
00109 
00112 enum Level {
00113     NoLevel      = -1,  
00114     Acceleration = 0,   
00115     Velocity     = 1,   
00116     Position     = 2    
00117 };
00121 static const char* nameOfLevel(Level);
00122 
00126 enum Method {
00127     NoMethod    = -1,
00128     Zero        = 0, 
00129     Discrete    = 1, 
00130     Prescribed  = 2, 
00131     Free        = 3, 
00132     Fast        = 4  
00133 };
00137 static const char* nameOfMethod(Method);
00138 
00141 Motion() {}
00142 
00146 Level getLevel(const State&) const;
00150 Method getLevelMethod(const State&) const;
00151 
00152 //------------------------------------------------------------------------------
00173 void disable(State& state) const;
00174 
00184 void enable(State& state) const;
00185 
00187 bool isDisabled(const State& state) const;
00188 
00193 void setDisabledByDefault(bool shouldBeDisabled);
00194 
00198 bool isDisabledByDefault() const;
00201 //------------------------------------------------------------------------------
00206 const MobilizedBody& getMobilizedBody() const;
00207 
00208 
00212 void calcAllMethods(const State& s, Method& qMethod, Method& uMethod, 
00213                     Method& udotMethod) const;
00216 class Steady;
00217 class Linear;
00218 class Sinusoid;
00219 class Polynomial;
00220 class Custom;
00221 
00222 class SteadyImpl;
00223 class LinearImpl;
00224 class SinusoidImpl;
00225 class PolynomialImpl;
00226 class CustomImpl;
00227 
00228 protected:
00231 explicit Motion(MotionImpl* r) : HandleBase(r) { }
00232 };
00233 
00234 
00235 //==============================================================================
00236 //                            MOTION :: SINUSOID
00237 //==============================================================================
00240 class SimTK_SIMBODY_EXPORT Motion::Sinusoid : public Motion {
00241 public:
00259     Sinusoid(MobilizedBody& mobod, Motion::Level level,
00260              Real amplitude, Real rate, Real phase);
00261   
00264     Sinusoid() {}
00265  // hide from Doxygen
00267     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Sinusoid, SinusoidImpl, Motion);
00269 };
00270 
00271 
00272 //==============================================================================
00273 //                            MOTION :: STEADY
00274 //==============================================================================
00277 class SimTK_SIMBODY_EXPORT Motion::Steady : public Motion {
00278 public:
00282     Steady(MobilizedBody& mobod, Real u);
00283 
00289     template <int N> SimTK_SIMBODY_EXPORT 
00290     Steady(MobilizedBody& mobod, const Vec<N>& u); // instantiated in library
00291     
00294     Steady() {}
00295 
00298     Steady& setDefaultRate(Real u);
00302     Steady& setOneDefaultRate(MobilizerUIndex, Real u);
00305     template <int N> SimTK_SIMBODY_EXPORT 
00306     Steady& setDefaultRates(const Vec<N>& u); // instantiated in library
00307 
00309     Real getOneDefaultRate(MobilizerUIndex ux) const;
00310 
00313     void setRate(State& state, Real u) const; // all axes set to u
00317     void setOneRate(State& state, MobilizerUIndex ux, Real u) const;
00318 
00320     Real getOneRate(const State& state, MobilizerUIndex ux) const;
00321  // hide from Doxygen
00323     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Steady, SteadyImpl, Motion);
00325 };
00326 
00327 
00328 
00329 //==============================================================================
00330 //                            MOTION :: CUSTOM
00331 //==============================================================================
00362 class SimTK_SIMBODY_EXPORT Motion::Custom : public Motion {
00363 public:
00364     class Implementation;
00365 
00372     Custom(MobilizedBody& mobod, Implementation* implementation);
00373 
00376     Custom() {}
00377  // hide from Doxygen
00379     SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Custom, CustomImpl, Motion);
00381 protected:
00382     const Implementation& getImplementation() const;
00383     Implementation& updImplementation();
00384 };
00385 
00386 
00387 //==============================================================================
00388 //                     MOTION :: CUSTOM :: IMPLEMENTATION
00389 //==============================================================================
00392 class SimTK_SIMBODY_EXPORT Motion::Custom::Implementation {
00393 public:
00396     virtual ~Implementation() { }
00397 
00399     virtual Implementation* clone() const {
00400         SimTK_ERRCHK_ALWAYS(!"unimplemented",
00401             "Motion::Custom::Implementation::clone()",
00402             "Concrete Implementation did not supply a clone() method, "
00403             "but a copy operation was attempted.");
00404         /*NOTREACHED*/
00405         return 0;
00406     }
00407 
00416     virtual Motion::Level getLevel(const State&) const = 0;
00417 
00419     virtual Motion::Method getLevelMethod(const State&) const {
00420         return Motion::Prescribed;
00421     }
00422 
00434     virtual void calcPrescribedPosition
00435                    (const State& s, int nq, Real* q) const;
00436 
00448     virtual void calcPrescribedPositionDot
00449                    (const State& s, int nq, Real* qdot) const;
00450 
00463     virtual void calcPrescribedPositionDotDot
00464                    (const State& s, int nq, Real* qdotdot) const;
00466 
00480     virtual void calcPrescribedVelocity
00481                    (const State& s, int nu, Real* u) const;
00482 
00493     virtual void calcPrescribedVelocityDot
00494                    (const State& s, int nu, Real* udot) const;
00496 
00510     virtual void calcPrescribedAcceleration
00511                    (const State& s, int nu, Real* udot) const;
00513 
00520     virtual void realizeTopology    (State&       state) const {}
00521     virtual void realizeModel       (State&       state) const {}
00522     virtual void realizeInstance    (const State& state) const {}
00523     virtual void realizeTime        (const State& state) const {}
00524     virtual void realizePosition    (const State& state) const {}
00525     virtual void realizeVelocity    (const State& state) const {}
00526     virtual void realizeDynamics    (const State& state) const {}
00527     virtual void realizeAcceleration(const State& state) const {}
00528     virtual void realizeReport      (const State& state) const {}
00530 };
00531 
00532 
00533 } // namespace SimTK
00534 
00535 #endif // SimTK_SIMBODY_MOTION_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines