In file /home/blah/darwin2k/src/d2k/d2kcore/d2kSimulator.h:

class d2kSimulator

base class for robot simulation and evaluation.

Inheritance:


Public Fields

[more]dynamicSystem* ds
the dynamicSystems used for simulation
[more]configuration* cfg
when only one configuration is used, cfg points to it
[more]ptrList cfgs
list of configurations
[more]ptrList d2kComponents
a list of d2kComponents.
[more]double dt
desired stepsize for calls to dynamicSystem::stepForward
[more]double maxRealtime
the maximum wall-clock time to allow for a simulation
[more]d2kDisplayHook* display
a pointer to the display class being used, or NULL if no display
[more]double simTimeout
maximum simulated time for a simulation
[more]ulong startSecs
starting time (wall-clock time) for the current evaluation
[more]triple gravity
gravitational acceleration vector
[more]uniformField* gravityInfluence
dyno influence for gravity.
[more]int useGravity
indicates whether gravity should be used
[more]int useDynamicSimulation
indicates whether dynamic simulation (rather than kinematic) should be used.

Public Methods

[more] d2kSimulator(void)
constructor
[more]virtual ~d2kSimulator(void)
destructor
[more]virtual int readParams(const char* fname)
reads d2kSimulator-specific parameters from fname.
[more]virtual int init(ptrList* cfgs)
allocates memory, instantiates the configuration, and sets initial configuration state.
[more]virtual int cleanup(void)
called after evaluateConfiguration to free memory allocated in init().
[more]virtual int dynoCleanup(void)
Deletes the d2kSimulator's dynamic system and cleans up any dangling pointers to dyno objects.
[more]virtual int minCfgs(void) const
Returns the minimum number of configurations required for the simulator.
[more]virtual int maxCfgs(void) const
Returns the maximum number of configurations required for the simulator, or -1 if there is no maximum.
[more] Hooks for derived classes


Inherited from synObject:

Public Fields

ostatic int staticClassID
oint objectID
oint verboseLevel

Public Methods

ovirtual const char* className(void) const
ovirtual synObject* copy(void) const
ovirtual int isOfType(int typeNum, int derivedOk)
ostatic int setStaticClassID(void)
ovirtual int classID(void) const


Documentation

base class for robot simulation and evaluation. D2kSimulators perform simulation book-keeping (such as allocating dynamicSystems and instantiating configurations), coordinate multiple d2kComponents, and keep track of the metrics being used to evaluate configurations.

All of the above functionality is present in the d2kSimulator base class. Derived classes can take advantage of this functionality while overriding the evaluateConfiguration() method, which allows the user to write application-specific simulation control (such as sequentially simulating multiple scenarios, or changing controllers as the simulation progresses). If no special interactions with (or between) d2kComponents is required, then the user can just use the d2kSimulator to perform initialization and bookkeeping. In this case, the user can access the d2kSimulator's dynamicSystem (ds) to control the physical simulation directly.

Virtual methods for derived classes Derived d2kSimulators may override the following methods:

For all of the above functions except evaluateConfiguration, the derived methods must call the parent class's method (e.g. init() should call the parent class's init() method).

Users writing their own d2kSimulator class should start with (or at least look at) the dummy versions created by darwin2k-makemod.

odynamicSystem* ds
the dynamicSystems used for simulation

oconfiguration* cfg
when only one configuration is used, cfg points to it

optrList cfgs
list of configurations

optrList d2kComponents
a list of d2kComponents. d2kComponents are added to the list in the order they appear in the p-file, and the init() and simInit() methods will be called for the d2kComponents in the same order.

odouble dt
desired stepsize for calls to dynamicSystem::stepForward

odouble maxRealtime
the maximum wall-clock time to allow for a simulation

od2kDisplayHook* display
a pointer to the display class being used, or NULL if no display

odouble simTimeout
maximum simulated time for a simulation

oulong startSecs
starting time (wall-clock time) for the current evaluation

otriple gravity
gravitational acceleration vector

ouniformField* gravityInfluence
dyno influence for gravity. May be NULL if no gravity is used.

oint useGravity
indicates whether gravity should be used

oint useDynamicSimulation
indicates whether dynamic simulation (rather than kinematic) should be used.

o d2kSimulator(void)
constructor

ovirtual ~d2kSimulator(void)
destructor

ovirtual int readParams(const char* fname)
reads d2kSimulator-specific parameters from fname. Derived classes should call their parent class's init() method within their own init().

ovirtual int init(ptrList* cfgs)
allocates memory, instantiates the configuration, and sets initial configuration state. Derived classes should call their parent class's init() method within their own init().

ovirtual int cleanup(void)
called after evaluateConfiguration to free memory allocated in init(). Derived classes should call their parent class's cleanup() method within their own cleanup().
Returns:
Returns 1 on success, 0 on failure.

ovirtual int dynoCleanup(void)
Deletes the d2kSimulator's dynamic system and cleans up any dangling pointers to dyno objects. This should be called after d2kSimulator::cleanup and after deleting the configuration. Derived classes do not normally need to provide this method, but those that do should perform their own cleanup before calling their parent class's dynoCleanup() method.

ovirtual int minCfgs(void) const
Returns the minimum number of configurations required for the simulator. Defaults to 1, but derived classes can override.

ovirtual int maxCfgs(void) const
Returns the maximum number of configurations required for the simulator, or -1 if there is no maximum. Defaults to -1, but derived classes can override.

o Hooks for derived classes

ovirtual int postComponentCreationHook(void)
A hook that gets called at the end of readParams(). Derived classes should call their parent class's createComponents() method at the end of their own createComponents().
Returns:
Returns 1 on success, 0 on failure.

ovirtual int postCfgInitHook(void)
A hook that gets called after calling d2kComponent::init() for all components

ovirtual int postCfgComponentInitHook(void)
A hook that gets called after all cfgComponents have been initialized

ovirtual int createComponents(paramParser &p)
creates and initializes all d2kComponents whose descriptions have been parsed by 'p'. This method creates d2kComponents specified in p, calls d2kComponent::readParams() for each component, and then calls d2kComponent::simInit() for each component. The order of components in p is maintained so that any dependencies between components (say, that one d2kComponent's simInit() method is called before another's) are preserved.

ovoid resetTimer(void)
resets the real-time clock

oint checkTimeout(void)
checks the real-time clock to see if the timeout specified by maxRealTime has been reached. Returns 1 if the timeout has been reached, or 0 if not. Note: this method always returns 0 when a display is being used so that leaving the simulation paused (or running on a particularly slow machine) will not cause a timeout.

ovirtual int initializeAll(const char* pfilename)
parses the indicated p-file and then calls d2kSimulator::readParams and d2kSimulator::createComponents.

ovirtual int doSimulation(void)
main simulation loop. This may be overridden by derived classes. evaluators are expected to override evaluator::evaluateConfiguration() instead of this method.

ovirtual int update(int &violated, int shortCircuit)
updates d2kComponents and the configuration during simulation. This calls configuration::updateConstraintDynamicValues and d2kComponent::update for each d2kComponent. If shortCircuit is non-zero, then any d2kComponent whose update() method sets violated() to -1 will cause an immediate return.

ovirtual int addComponent(d2kComponent* c)
convenience function for adding an d2kComponent. Adds the d2kComponent to the end of the list of d2kComponents.

ovirtual int updateDisplay(void)
convenience function for updating display. Returns 1 if the display object has signalled a user exit event

od2kComponent* getComponent(int i)
returns the i'th d2kComponent

ostatic d2kSimulator* createD2kSimulatorFromFile(const char* pfilename)
Creates an d2kSimulator and d2kComponents as specified in a p-file. This is the easiest way to parse a p-file, create an d2kSimulator, and create and initialize a number of d2kComponents. Even if you do not actually need an d2kSimulator, it is often easiest to specify an d2kSimulator (of the 'd2kSimulator' class, not a derived class) in the p-file along with any d2kComponents you need, as the d2kSimulator will handle initialization for the d2kComponents.

od2kComponent* getComponentByLabel(const char* label)
returns the first d2kComponent having the indicated label, or NULL if no matching d2kComponent was found.

od2kComponent* getComponentByClassID(int classID, int derivedOk = 1)
returns the first d2kComponent having the given classID, or if derivedOk = 1 having the classID of a subclass.

oint getComponentsByClassID(int classID, ptrList* l, int derivedOk = 1)
adds all d2kComponents having the given classID (or classID of a derived class, if derivedOk is 1) to l. Returns 1 if any matching d2kComponents were found, or 0 otherwise.

o#define getD2kComponentByType(sim, classname, derivedOk)
A cover for getComponentByClassID that uses the classID for the supplied class name and typecasts the returned result.

o#define getComponentsByType(classname, l, derivedOk)
A cover for getComponentsByClassID that uses the classID for the supplied class name.


Direct child classes:
evaluator

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.