Simbody  3.8
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_
#define SimTK_ERRCHK_ALWAYS(cond, whereChecked, msg)
Definition: ExceptionMacros.h:281
#define SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(DERIVED, DERIVED_IMPL, PARENT)
Definition: PrivateImplementation.h:343
Includes internal headers providing declarations for the basic SimTK Core classes,...
Every Simbody header and source file should include this header before any other Simbody header.
#define SimTK_SIMBODY_EXPORT
Definition: Simbody/include/simbody/internal/common.h:68
A MobilizedBody is Simbody's fundamental body-and-joint object used to parameterize a system's motion...
Definition: MobilizedBody.h:169
The Mobilizer associated with each MobilizedBody, once modeled, has a specific number of generalized ...
This is the abstract base class for Custom Motion implementations.
Definition: Motion.h:392
virtual Motion::Level getLevel(const State &) const =0
A Motion prescribes either position, velocity, or acceleration.
virtual void realizeDynamics(const State &state) const
Definition: Motion.h:526
virtual void realizeModel(State &state) const
Definition: Motion.h:521
virtual void realizeInstance(const State &state) const
Definition: Motion.h:522
virtual void realizeVelocity(const State &state) const
Definition: Motion.h:525
virtual void realizeReport(const State &state) const
Definition: Motion.h:528
virtual Motion::Method getLevelMethod(const State &) const
Override this if the method is not Motion::Prescribed.
Definition: Motion.h:419
virtual void calcPrescribedPositionDot(const State &s, int nq, Real *qdot) const
Calculate the time derivative of the prescribed positions.
virtual void calcPrescribedAcceleration(const State &s, int nu, Real *udot) const
This operator is called during the MatterSubsystem's realize(Dynamics) computation.
virtual void realizeTopology(State &state) const
Definition: Motion.h:520
virtual void calcPrescribedVelocityDot(const State &s, int nu, Real *udot) const
Calculate the time derivative of the prescribed velocity.
virtual void realizeTime(const State &state) const
Definition: Motion.h:523
virtual void calcPrescribedPosition(const State &s, int nq, Real *q) const
This operator is called during the MatterSubsystem's realize(Time) computation.
virtual ~Implementation()
Destructor is virtual; be sure to provide one in you concrete class if there is anything to destruct.
Definition: Motion.h:396
virtual void calcPrescribedVelocity(const State &s, int nu, Real *u) const
This operator is called during the MatterSubsystem's realize(Position) computation.
virtual Implementation * clone() const
Override this if you want your Motion objects to be copyable.
Definition: Motion.h:399
virtual void realizePosition(const State &state) const
Definition: Motion.h:524
virtual void realizeAcceleration(const State &state) const
Definition: Motion.h:527
virtual void calcPrescribedPositionDotDot(const State &s, int nq, Real *qdotdot) const
Calculate the 2nd time derivative of the prescribed positions.
This class can be used to define new motions.
Definition: Motion.h:362
Implementation & updImplementation()
Custom()
Default constructor creates an empty handle that can be assigned to reference any Motion::Custom obje...
Definition: Motion.h:376
const Implementation & getImplementation() const
Custom(MobilizedBody &mobod, Implementation *implementation)
Create a Custom Motion.
Prescribe position, velocity, or acceleration motion as a sinusoidal function of time,...
Definition: Motion.h:240
Sinusoid()
Default constructor creates an empty handle that can be assigned to reference any Motion::Sinusoid ob...
Definition: Motion.h:264
Sinusoid(MobilizedBody &mobod, Motion::Level level, Real amplitude, Real rate, Real phase)
Create a sinusoidal prescribed motion applied at position, velocity, or acceleration level.
This non-holonomic Motion object imposes a constant rate on all mobilities.
Definition: Motion.h:277
Real getOneRate(const State &state, MobilizerUIndex ux) const
Get the rate setting for one mobility.
Real getOneDefaultRate(MobilizerUIndex ux) const
Get the default rate setting for one mobility.
Steady & setDefaultRate(Real u)
Change the default rate this Motion will prescribe unless overridden in a particular State.
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.
Steady(MobilizedBody &mobod, const Vec< N > &u)
Create a Motion::Steady with different velocities for each mobility specified.
void setRate(State &state, Real u) const
Change the rate to be prescribed by this Motion when used with the given State.
Steady(MobilizedBody &mobod, Real u)
Create a Motion::Steady where all mobilities have the same velocity.
Steady & setDefaultRates(const Vec< N > &u)
Change the default rates this Motion will prescribe, supplying separate rates for each mobility as a ...
Steady()
Default constructor creates an empty handle than can be assigned to reference any Motion::Steady obje...
Definition: Motion.h:294
Steady & setOneDefaultRate(MobilizerUIndex, Real u)
Change the default rate this Motion will prescribe for one mobility, unless overridden in a particula...
A Motion object belongs to a particular MobilizedBody and prescribes how the associated motion is to ...
Definition: Motion.h:107
static const char * nameOfMethod(Method)
Returns a human-readable name corresponding to the given Method; useful for debugging.
bool isDisabled(const State &state) const
Test whether this Motion is currently disabled in the supplied State.
void disable(State &state) const
Disable this Motion, effectively removing it from the mobilizer to which it belongs and allowing the ...
Method
There are several ways to specify the motion at this Level, and the selected method also determines l...
Definition: Motion.h:126
@ Prescribed
motion is function of time and state; <level is derivative
Definition: Motion.h:130
static const char * nameOfLevel(Level)
Returns a human-readable name corresponding to the given Level; useful for debugging.
void calcAllMethods(const State &s, Method &qMethod, Method &uMethod, Method &udotMethod) const
(Advanced) This implements the above table.
Level
What is the highest level of motion that is driven? Lower levels are also driven; higher levels are d...
Definition: Motion.h:112
const MobilizedBody & getMobilizedBody() const
Get the MobilizedBody to which this Motion belongs.
void enable(State &state) const
Enable this Motion, without necessarily satisfying it.
Method getLevelMethod(const State &) const
Get the method being used to control the indicated Level.
Motion(MotionImpl *r)
For internal use: construct a new Motion handle referencing a particular implementation object.
Definition: Motion.h:231
void setDisabledByDefault(bool shouldBeDisabled)
Specify that a Motion is to be inactive by default.
bool isDisabledByDefault() const
Test whether this Motion is disabled by default in which case it must be explicitly enabled before it...
Level getLevel(const State &) const
Get the highest level being driven by this Motion.
Motion()
Default constructor creates an empty Motion handle that can be assigned to reference any kind of Moti...
Definition: Motion.h:141
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
const Real Zero
Real(0)
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:607