Simbody  3.7
Motion.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMBODY_MOTION_H_
2 #define SimTK_SIMBODY_MOTION_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) 2009-13 Stanford University and the Authors. *
13  * Authors: 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 
31 #include "SimTKcommon.h"
33 
34 namespace SimTK {
35 
36 class SimbodyMatterSubsystem;
37 class MobilizedBody;
38 class Motion;
39 class MotionImpl;
40 
41 // We only want the template instantiation to occur once. This symbol is defined
42 // in the Simbody compilation unit that defines the Motion class but should not
43 // be defined any other time.
44 #ifndef SimTK_SIMBODY_DEFINING_MOTION
45  extern template class PIMPLHandle<Motion, MotionImpl, true>;
46 #endif
47 
48 
49 //==============================================================================
50 // MOTION
51 //==============================================================================
108 public:
109 
112 enum Level {
113  NoLevel = -1,
114  Acceleration = 0,
115  Velocity = 1,
116  Position = 2
117 };
121 static const char* nameOfLevel(Level);
122 
126 enum Method {
127  NoMethod = -1,
128  Zero = 0,
129  Discrete = 1,
130  Prescribed = 2,
131  Free = 3,
132  Fast = 4
133 };
137 static const char* nameOfMethod(Method);
138 
141 Motion() {}
142 
146 Level getLevel(const State&) const;
151 
152 //------------------------------------------------------------------------------
173 void disable(State& state) const;
174 
184 void enable(State& state) const;
185 
187 bool isDisabled(const State& state) const;
188 
193 void setDisabledByDefault(bool shouldBeDisabled);
194 
198 bool isDisabledByDefault() const;
201 //------------------------------------------------------------------------------
207 
208 
212 void calcAllMethods(const State& s, Method& qMethod, Method& uMethod,
213  Method& udotMethod) const;
216 class Steady;
217 class Linear;
218 class Sinusoid;
219 class Polynomial;
220 class Custom;
221 
222 class SteadyImpl;
223 class LinearImpl;
224 class SinusoidImpl;
225 class PolynomialImpl;
226 class CustomImpl;
227 
228 protected:
231 explicit Motion(MotionImpl* r) : HandleBase(r) { }
232 };
233 
234 
235 //==============================================================================
236 // MOTION :: SINUSOID
237 //==============================================================================
241 public:
260  Real amplitude, Real rate, Real phase);
261 
264  Sinusoid() {}
265  // hide from Doxygen
269 };
270 
271 
272 //==============================================================================
273 // MOTION :: STEADY
274 //==============================================================================
278 public:
283 
289  template <int N> SimTK_SIMBODY_EXPORT
290  Steady(MobilizedBody& mobod, const Vec<N>& u); // instantiated in library
291 
294  Steady() {}
295 
305  template <int N> SimTK_SIMBODY_EXPORT
306  Steady& setDefaultRates(const Vec<N>& u); // instantiated in library
307 
310 
313  void setRate(State& state, Real u) const; // all axes set to u
317  void setOneRate(State& state, MobilizerUIndex ux, Real u) const;
318 
320  Real getOneRate(const State& state, MobilizerUIndex ux) const;
321  // hide from Doxygen
325 };
326 
327 
328 
329 //==============================================================================
330 // MOTION :: CUSTOM
331 //==============================================================================
363 public:
364  class Implementation;
365 
372  Custom(MobilizedBody& mobod, Implementation* implementation);
373 
376  Custom() {}
377  // hide from Doxygen
381 protected:
384 };
385 
386 
387 //==============================================================================
388 // MOTION :: CUSTOM :: IMPLEMENTATION
389 //==============================================================================
393 public:
396  virtual ~Implementation() { }
397 
399  virtual Implementation* clone() const {
400  SimTK_ERRCHK_ALWAYS(!"unimplemented",
401  "Motion::Custom::Implementation::clone()",
402  "Concrete Implementation did not supply a clone() method, "
403  "but a copy operation was attempted.");
404  /*NOTREACHED*/
405  return 0;
406  }
407 
416  virtual Motion::Level getLevel(const State&) const = 0;
417 
419  virtual Motion::Method getLevelMethod(const State&) const {
420  return Motion::Prescribed;
421  }
422 
435  (const State& s, int nq, Real* q) const;
436 
449  (const State& s, int nq, Real* qdot) const;
450 
464  (const State& s, int nq, Real* qdotdot) const;
466 
481  (const State& s, int nu, Real* u) const;
482 
494  (const State& s, int nu, Real* udot) const;
496 
511  (const State& s, int nu, Real* udot) const;
513 
520  virtual void realizeTopology (State& state) const {}
521  virtual void realizeModel (State& state) const {}
522  virtual void realizeInstance (const State& state) const {}
523  virtual void realizeTime (const State& state) const {}
524  virtual void realizePosition (const State& state) const {}
525  virtual void realizeVelocity (const State& state) const {}
526  virtual void realizeDynamics (const State& state) const {}
527  virtual void realizeAcceleration(const State& state) const {}
528  virtual void realizeReport (const State& state) const {}
530 };
531 
532 
533 } // namespace SimTK
534 
535 #endif // SimTK_SIMBODY_MOTION_H_
SimTK::State
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
SimTK::Motion::Steady::Steady
Steady()
Default constructor creates an empty handle than can be assigned to reference any Motion::Steady obje...
Definition: Motion.h:294
SimTK::Motion::Motion
Motion()
Default constructor creates an empty Motion handle that can be assigned to reference any kind of Moti...
Definition: Motion.h:141
SimTK::Motion::Custom::Implementation::realizeDynamics
virtual void realizeDynamics(const State &state) const
Definition: Motion.h:526
SimTK::Motion::disable
void disable(State &state) const
Disable this Motion, effectively removing it from the mobilizer to which it belongs and allowing the ...
SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS
#define SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(DERIVED, DERIVED_IMPL, PARENT)
Definition: PrivateImplementation.h:343
SimTK::Motion::isDisabled
bool isDisabled(const State &state) const
Test whether this Motion is currently disabled in the supplied State.
SimTK::Motion::Custom
This class can be used to define new motions.
Definition: Motion.h:362
SimTK::Motion::Custom::Implementation::calcPrescribedVelocityDot
virtual void calcPrescribedVelocityDot(const State &s, int nu, Real *udot) const
Calculate the time derivative of the prescribed velocity.
SimTK::Motion::Sinusoid
Prescribe position, velocity, or acceleration motion as a sinusoidal function of time,...
Definition: Motion.h:240
SimTK::Motion::Custom::Implementation::clone
virtual Implementation * clone() const
Override this if you want your Motion objects to be copyable.
Definition: Motion.h:399
SimTK::Motion::getLevel
Level getLevel(const State &) const
Get the highest level being driven by this Motion.
SimTK::Motion::Custom::getImplementation
const Implementation & getImplementation() const
SimTK::Motion::Prescribed
@ Prescribed
motion is function of time and state; <level is derivative
Definition: Motion.h:130
MobilizerUIndex
SimTK::Motion::Custom::Implementation::calcPrescribedAcceleration
virtual void calcPrescribedAcceleration(const State &s, int nu, Real *udot) const
This operator is called during the MatterSubsystem's realize(Dynamics) computation.
SimTK
This is a System that represents the dynamics of a particle moving along a smooth surface.
Definition: Assembler.h:37
SimTK::Motion
A Motion object belongs to a particular MobilizedBody and prescribes how the associated motion is to ...
Definition: Motion.h:107
SimTK::Motion::Custom::Implementation::getLevel
virtual Motion::Level getLevel(const State &) const =0
A Motion prescribes either position, velocity, or acceleration.
SimTK::Motion::Custom::Custom
Custom(MobilizedBody &mobod, Implementation *implementation)
Create a Custom Motion.
SimTK::Motion::Steady::setOneDefaultRate
Steady & setOneDefaultRate(MobilizerUIndex, Real u)
Change the default rate this Motion will prescribe for one mobility, unless overridden in a particula...
SimTK::Motion::Custom::Implementation::calcPrescribedPositionDot
virtual void calcPrescribedPositionDot(const State &s, int nq, Real *qdot) const
Calculate the time derivative of the prescribed positions.
SimTK::Motion::Steady::setOneRate
void setOneRate(State &state, MobilizerUIndex ux, Real u) const
Change the rate this Motion will prescribe for one mobility when used with the given State.
SimTK::Motion::Custom::Implementation::realizeAcceleration
virtual void realizeAcceleration(const State &state) const
Definition: Motion.h:527
SimTKcommon.h
SimTK::Vec< N >
SimTK::Motion::Custom::Implementation::getLevelMethod
virtual Motion::Method getLevelMethod(const State &) const
Override this if the method is not Motion::Prescribed.
Definition: Motion.h:419
SimTK::Motion::Sinusoid::Sinusoid
Sinusoid()
Default constructor creates an empty handle that can be assigned to reference any Motion::Sinusoid ob...
Definition: Motion.h:264
SimTK::Motion::Steady
This non-holonomic Motion object imposes a constant rate on all mobilities.
Definition: Motion.h:277
SimTK::Motion::Custom::Implementation::calcPrescribedPositionDotDot
virtual void calcPrescribedPositionDotDot(const State &s, int nq, Real *qdotdot) const
Calculate the 2nd time derivative of the prescribed positions.
SimTK::Motion::Custom::Implementation::realizePosition
virtual void realizePosition(const State &state) const
Definition: Motion.h:524
SimTK::Motion::Custom::Implementation::realizeVelocity
virtual void realizeVelocity(const State &state) const
Definition: Motion.h:525
SimTK::Motion::calcAllMethods
void calcAllMethods(const State &s, Method &qMethod, Method &uMethod, Method &udotMethod) const
(Advanced) This implements the above table.
SimTK::Motion::Custom::Implementation::realizeTopology
virtual void realizeTopology(State &state) const
Definition: Motion.h:520
SimTK::Motion::Custom::Custom
Custom()
Default constructor creates an empty handle that can be assigned to reference any Motion::Custom obje...
Definition: Motion.h:376
SimTK_ERRCHK_ALWAYS
#define SimTK_ERRCHK_ALWAYS(cond, whereChecked, msg)
Definition: ExceptionMacros.h:281
SimTK::Motion::Level
Level
What is the highest level of motion that is driven? Lower levels are also driven; higher levels are d...
Definition: Motion.h:112
SimTK::Motion::Steady::Steady
Steady(MobilizedBody &mobod, const Vec< N > &u)
Create a Motion::Steady with different velocities for each mobility specified.
SimTK::Motion::Custom::updImplementation
Implementation & updImplementation()
SimTK::Motion::Motion
Motion(MotionImpl *r)
For internal use: construct a new Motion handle referencing a particular implementation object.
Definition: Motion.h:231
SimTK::Motion::isDisabledByDefault
bool isDisabledByDefault() const
Test whether this Motion is disabled by default in which case it must be explicitly enabled before it...
SimTK::PIMPLHandle< Motion, MotionImpl, true >
SimTK::MobilizedBody
A MobilizedBody is Simbody's fundamental body-and-joint object used to parameterize a system's motion...
Definition: MobilizedBody.h:169
SimTK::Motion::getMobilizedBody
const MobilizedBody & getMobilizedBody() const
Get the MobilizedBody to which this Motion belongs.
SimTK_SIMBODY_EXPORT
#define SimTK_SIMBODY_EXPORT
Definition: Simbody/include/simbody/internal/common.h:68
SimTK::Motion::enable
void enable(State &state) const
Enable this Motion, without necessarily satisfying it.
SimTK::Motion::getLevelMethod
Method getLevelMethod(const State &) const
Get the method being used to control the indicated Level.
SimTK::Real
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
SimTK::Motion::Method
Method
There are several ways to specify the motion at this Level, and the selected method also determines l...
Definition: Motion.h:126
SimTK::Motion::Custom::Implementation::calcPrescribedVelocity
virtual void calcPrescribedVelocity(const State &s, int nu, Real *u) const
This operator is called during the MatterSubsystem's realize(Position) computation.
SimTK::Motion::nameOfMethod
static const char * nameOfMethod(Method)
Returns a human-readable name corresponding to the given Method; useful for debugging.
SimTK::Motion::Custom::Implementation::realizeModel
virtual void realizeModel(State &state) const
Definition: Motion.h:521
SimTK::Motion::Custom::Implementation
This is the abstract base class for Custom Motion implementations.
Definition: Motion.h:392
SimTK::Motion::Steady::getOneRate
Real getOneRate(const State &state, MobilizerUIndex ux) const
Get the rate setting for one mobility.
SimTK::Motion::Custom::Implementation::~Implementation
virtual ~Implementation()
Destructor is virtual; be sure to provide one in you concrete class if there is anything to destruct.
Definition: Motion.h:396
SimTK::Motion::Steady::setRate
void setRate(State &state, Real u) const
Change the rate to be prescribed by this Motion when used with the given State.
SimTK::Motion::Custom::Implementation::calcPrescribedPosition
virtual void calcPrescribedPosition(const State &s, int nq, Real *q) const
This operator is called during the MatterSubsystem's realize(Time) computation.
SimTK::Motion::Sinusoid::Sinusoid
Sinusoid(MobilizedBody &mobod, Motion::Level level, Real amplitude, Real rate, Real phase)
Create a sinusoidal prescribed motion applied at position, velocity, or acceleration level.
SimTK::Motion::Custom::Implementation::realizeTime
virtual void realizeTime(const State &state) const
Definition: Motion.h:523
SimTK::Motion::Custom::Implementation::realizeReport
virtual void realizeReport(const State &state) const
Definition: Motion.h:528
SimTK::Motion::Steady::setDefaultRates
Steady & setDefaultRates(const Vec< N > &u)
Change the default rates this Motion will prescribe, supplying separate rates for each mobility as a ...
SimTK::Motion::nameOfLevel
static const char * nameOfLevel(Level)
Returns a human-readable name corresponding to the given Level; useful for debugging.
SimTK::Motion::Steady::Steady
Steady(MobilizedBody &mobod, Real u)
Create a Motion::Steady where all mobilities have the same velocity.
SimTK::Zero
const Real Zero
Real(0)
common.h
SimTK::Motion::Steady::getOneDefaultRate
Real getOneDefaultRate(MobilizerUIndex ux) const
Get the default rate setting for one mobility.
SimTK::Motion::Custom::Implementation::realizeInstance
virtual void realizeInstance(const State &state) const
Definition: Motion.h:522
SimTK::Motion::Steady::setDefaultRate
Steady & setDefaultRate(Real u)
Change the default rate this Motion will prescribe unless overridden in a particular State.
SimTK::Motion::setDisabledByDefault
void setDisabledByDefault(bool shouldBeDisabled)
Specify that a Motion is to be inactive by default.