Simbody  3.5
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;
150 Method getLevelMethod(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 //------------------------------------------------------------------------------
206 const MobilizedBody& getMobilizedBody() const;
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:
259  Sinusoid(MobilizedBody& mobod, Motion::Level level,
260  Real amplitude, Real rate, Real phase);
261 
264  Sinusoid() {}
265  // hide from Doxygen
269 };
270 
271 
272 //==============================================================================
273 // MOTION :: STEADY
274 //==============================================================================
278 public:
282  Steady(MobilizedBody& mobod, Real u);
283 
289  template <int N> SimTK_SIMBODY_EXPORT
290  Steady(MobilizedBody& mobod, const Vec<N>& u); // instantiated in library
291 
294  Steady() {}
295 
298  Steady& setDefaultRate(Real u);
302  Steady& setOneDefaultRate(MobilizerUIndex, Real u);
305  template <int N> SimTK_SIMBODY_EXPORT
306  Steady& setDefaultRates(const Vec<N>& u); // instantiated in library
307 
309  Real getOneDefaultRate(MobilizerUIndex ux) const;
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:
382  const Implementation& getImplementation() const;
383  Implementation& updImplementation();
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 
434  virtual void calcPrescribedPosition
435  (const State& s, int nq, Real* q) const;
436 
448  virtual void calcPrescribedPositionDot
449  (const State& s, int nq, Real* qdot) const;
450 
463  virtual void calcPrescribedPositionDotDot
464  (const State& s, int nq, Real* qdotdot) const;
466 
480  virtual void calcPrescribedVelocity
481  (const State& s, int nu, Real* u) const;
482 
493  virtual void calcPrescribedVelocityDot
494  (const State& s, int nu, Real* udot) const;
496 
510  virtual void calcPrescribedAcceleration
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_
virtual void realizeDynamics(const State &state) const
Definition: Motion.h:526
This non-holonomic Motion object imposes a constant rate on all mobilities.
Definition: Motion.h:277
Motion(MotionImpl *r)
For internal use: construct a new Motion handle referencing a particular implementation object...
Definition: Motion.h:231
virtual void realizeVelocity(const State &state) const
Definition: Motion.h:525
Steady()
Default constructor creates an empty handle than can be assigned to reference any Motion::Steady obje...
Definition: Motion.h:294
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
const Real Zero
Real(0)
This class can be used to define new motions.
Definition: Motion.h:362
A Motion object belongs to a particular MobilizedBody and prescribes how the associated motion is to ...
Definition: Motion.h:107
Prescribe position, velocity, or acceleration motion as a sinusoidal function of time, m(t) = a * sin( w*t + p ).
Definition: Motion.h:240
Every Simbody header and source file should include this header before any other Simbody header...
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:593
#define SimTK_ERRCHK_ALWAYS(cond, whereChecked, msg)
Definition: ExceptionMacros.h:281
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:276
This is the abstract base class for Custom Motion implementations.
Definition: Motion.h:392
virtual void realizeInstance(const State &state) const
Definition: Motion.h:522
virtual Motion::Method getLevelMethod(const State &) const
Override this if the method is not Motion::Prescribed.
Definition: Motion.h:419
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
Level
What is the highest level of motion that is driven? Lower levels are also driven; higher levels are d...
Definition: Motion.h:112
#define SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(DERIVED, DERIVED_IMPL, PARENT)
Definition: PrivateImplementation.h:343
virtual void realizePosition(const State &state) const
Definition: Motion.h:524
virtual void realizeReport(const State &state) const
Definition: Motion.h:528
Custom()
Default constructor creates an empty handle that can be assigned to reference any Motion::Custom obje...
Definition: Motion.h:376
motion is function of time and state; <level is derivative
Definition: Motion.h:130
virtual Implementation * clone() const
Override this if you want your Motion objects to be copyable.
Definition: Motion.h:399
#define SimTK_SIMBODY_EXPORT
Definition: Simbody/include/simbody/internal/common.h:72
A MobilizedBody is Simbody&#39;s fundamental body-and-joint object used to parameterize a system&#39;s motion...
Definition: MobilizedBody.h:167
virtual void realizeTopology(State &state) const
Definition: Motion.h:520
Method
There are several ways to specify the motion at this Level, and the selected method also determines l...
Definition: Motion.h:126
virtual void realizeModel(State &state) const
Definition: Motion.h:521
virtual void realizeAcceleration(const State &state) const
Definition: Motion.h:527
Sinusoid()
Default constructor creates an empty handle that can be assigned to reference any Motion::Sinusoid ob...
Definition: Motion.h:264
virtual void realizeTime(const State &state) const
Definition: Motion.h:523
The Mobilizer associated with each MobilizedBody, once modeled, has a specific number of generalized ...
virtual ~Implementation()
Destructor is virtual; be sure to provide one in you concrete class if there is anything to destruct...
Definition: Motion.h:396