Moby
ControlledBody.h
1 /****************************************************************************
2  * Copyright 2005 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _CONTROLLED_BODY_H
8 #define _CONTROLLED_BODY_H
9 
10 #include <boost/shared_ptr.hpp>
11 #include <boost/foreach.hpp>
12 #include <Moby/Base.h>
13 #include <Moby/Constants.h>
14 #include <Moby/Log.h>
15 #include <Moby/Visualizable.h>
16 #include <Moby/RecurrentForce.h>
17 
18 namespace Moby {
19 
21 class ControlledBody : public virtual Visualizable
22 {
23  friend class Simulator;
24 
25  public:
26 
28  {
29  controller = NULL;
30  }
31 
32  virtual ~ControlledBody() {}
33  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
34  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
35 
37  Ravelin::VectorNd& (*controller)(boost::shared_ptr<ControlledBody> body, Ravelin::VectorNd&, double, void*);
38 
41 
43  const std::list<RecurrentForcePtr>& get_recurrent_forces() const { return _rfs; }
44 
46  std::list<RecurrentForcePtr>& get_recurrent_forces() { return _rfs; }
47 
49  virtual void prepare_to_calc_ode_sustained_constraints(Ravelin::SharedConstVectorNd& x, double t, double dt, void* data) = 0;
50 
52  virtual void prepare_to_calc_ode(Ravelin::SharedConstVectorNd& x, double t, double dt, void* data) = 0;
53 
55  virtual void ode(double t, double dt, void* data, Ravelin::SharedVectorNd& dx) = 0;
56 
57  private:
58 
60  std::list<RecurrentForcePtr> _rfs;
61 
62  protected:
63 
65  boost::weak_ptr<Simulator> simulator;
66 }; // end class
67 
68 } // end namespace
69 
70 #endif
Class that allows for visualizing simulation data.
Definition: Visualizable.h:29
const std::list< RecurrentForcePtr > & get_recurrent_forces() const
Gets the set of recurrent forces applied to this body.
Definition: ControlledBody.h:43
virtual void prepare_to_calc_ode(Ravelin::SharedConstVectorNd &x, double t, double dt, void *data)=0
Prepares to compute the derivative of the body.
Ravelin::VectorNd &(* controller)(boost::shared_ptr< ControlledBody > body, Ravelin::VectorNd &, double, void *)
The controller callback, if any, for this body.
Definition: ControlledBody.h:37
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
std::list< RecurrentForcePtr > & get_recurrent_forces()
Gets the set of recurrent forces applied to this body.
Definition: ControlledBody.h:46
virtual void save_to_xml(XMLTreePtr node, std::list< boost::shared_ptr< const Base > > &shared_objects) const
Implements Base::save_to_xml()
Definition: ControlledBody.cpp:137
Simulator for both unarticulated and articulated rigid bodies without contact.
Definition: Simulator.h:40
Superclass for controlled bodies.
Definition: ControlledBody.h:21
virtual void load_from_xml(boost::shared_ptr< const XMLTree > node, std::map< std::string, BasePtr > &id_map)
Loads the body's state via XML.
Definition: ControlledBody.cpp:91
virtual void prepare_to_calc_ode_sustained_constraints(Ravelin::SharedConstVectorNd &x, double t, double dt, void *data)=0
Prepares to compute the derivative of the body (sustained constraints)
boost::weak_ptr< Simulator > simulator
Pointer to the simulator (necessary for applying impulses w/constraints)
Definition: ControlledBody.h:65
virtual void ode(double t, double dt, void *data, Ravelin::SharedVectorNd &dx)=0
Computes the derivative of the body.
void * controller_arg
Argument to be passed to the controller.
Definition: ControlledBody.h:40