Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Simulation Class Referenceabstract

#include <simulation.h>

Inheritance diagram for Simulation:
Collaboration diagram for Simulation:

Public Types

enum  SimulationState { none, initialised, running, closed }
 
enum  CameraMode { Static =0, Follow, TV, Race }
 
- Public Types inherited from Configurable
typedef std::string paramkey
 
typedef std::string paramdescr
 
typedef double paramval
 
typedef std::list< std::pair
< paramkey, paramval > > 
paramlist
 
typedef std::map< paramkey,
paramval * > 
parammap
 
typedef bool parambool
 
typedef std::list< std::pair
< paramkey, parambool > > 
paramboollist
 
typedef std::map< paramkey,
parambool * > 
paramboolmap
 
typedef int paramint
 
typedef std::list< std::pair
< paramkey, paramint > > 
paramintlist
 
typedef std::map< paramkey,
paramint * > 
paramintmap
 
typedef std::map< paramkey,
paramdescr
paramdescrmap
 
typedef std::pair< paramval,
paramval
paramvalBounds
 
typedef std::map< paramkey,
paramvalBounds
paramvalBoundsMap
 
typedef std::pair< paramint,
paramint
paramintBounds
 
typedef std::map< paramkey,
paramintBounds
paramintBoundsMap
 
typedef std::pair< paramkey,
paramval * > 
paramvalpair
 
typedef std::pair< paramkey,
parambool * > 
paramboolpair
 
typedef std::pair< paramkey,
paramint * > 
paramintpair
 
typedef std::vector
< Configurable * > 
configurableList
 
- Public Types inherited from BackCaller
typedef unsigned long CallbackableType
 

Public Member Functions

 Simulation ()
 
virtual ~Simulation ()
 
bool run (int argc, char **argv)
 starts the Simulation. More...
 
virtual void start (const OdeHandle &, const OsgHandle &, GlobalData &globalData)=0
 start() is called at the first start of the cycles and should create all the object (obstacles, agents...). More...
 
virtual bool restart (const OdeHandle &, const OsgHandle &, GlobalData &globalData)
 restart() is called at the second and all following starts of the cylce The end of a cycle is determined by (simulation_time_reached==true) More...
 
virtual void end (GlobalData &globalData)
 end() is called at the end and should tidy up More...
 
virtual bool config (GlobalData &globalData)
 config() is called when the user presses Ctrl-C More...
 
virtual bool command (const OdeHandle &, const OsgHandle &, GlobalData &globalData, int key, bool down)
 is called if a key was pressed. More...
 
virtual void bindingDescription (osg::ApplicationUsage &au) const
 this can be used to describe the key bindings used by command() More...
 
virtual void usage () const
 this can be used to print additional usage information (cmd-line options) More...
 
virtual bool collCallback (const OdeHandle &, void *data, dGeomID o1, dGeomID o2)
 collCallback() can be used to overload the standart collision handling. More...
 
virtual void addCallback (GlobalData &globalData, bool draw, bool pause, bool control)
 optional additional callback function which is called every simulation step. More...
 
virtual void addPaletteFile (const std::string &filename, bool verbose=false)
 adds a palette file to be loaded at initialization time Call this before run()! More...
 
virtual void addColorAliasFile (const std::string &filename, bool verbose=false)
 adds a color alias file to be loaded at initialization time Call this before run()! More...
 
virtual void odeStep ()
 
virtual void osgStep ()
 
virtual void doOnCallBack (BackCaller *src, BackCaller::CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE) override
 This method is invoked when a callback is done from the class where this class is for callback registered. More...
 
- Public Member Functions inherited from Base
 Base (const std::string &caption="LpzRobots Simulator (Martius et al)")
 
virtual void makePhysicsScene ()
 create the ground plane More...
 
virtual void makeScene (OsgScene *scene, const OsgConfig &config)
 creates the base scene graph with world, sky and floor and shadow and HUD and stores it in scene More...
 
virtual osg::Node * makeSky (const OsgConfig &config)
 
virtual osg::Node * makeGround (const OsgConfig &config)
 
virtual osg::Node * createHUD (OsgScene *scene, const OsgConfig &config)
 creates hud and is supposed to return the camera to it and adds the geode of the hud to the scene More...
 
virtual void createHUDManager (osg::Geode *geode, osgText::Font *font)
 
virtual void makeLights (osg::Group *node, const OsgConfig &config)
 adds light to the node More...
 
virtual osgShadow::ShadowedScene * createShadowedScene (osg::Node *sceneToShadow, osg::LightSource *lightSource, int shadowType)
 Shadow types: 1 - ShadowVolume 2 - ShadowTextue 3 - ParallelSplitShadowMap 4 - SoftShadowMap 5 - ShadowMap. More...
 
virtual void setGroundTexture (const char *filename)
 
virtual Substance getGroundSubstance ()
 
virtual void setGroundSubstance (const Substance &substance)
 
virtual void setCaption (const std::string &caption)
 sets the cpation that is printed at the right of the status line More...
 
virtual void setTitle (const std::string &title)
 sets the title that is printed in the center of the status line More...
 
virtual StatLineProperties getStatLineProperties ()
 
virtual void setStatLineProperties (const StatLineProperties &statlineprop)
 sets the properties of the status line, do it before the scene is initialized More...
 
virtual HUDStatisticsManagergetHUDSM ()
 Create HUDStatisticsManager and register it for being called back every step. More...
 
virtual ~Base ()
 
- Public Member Functions inherited from Configurable
 Configurable ()
 
 Configurable (const std::string &name, const std::string &revision)
 intialise with name and revision (use "$ID$") More...
 
virtual ~Configurable ()
 
virtual void notifyOnChange (const paramkey &key)
 Is called when a parameter was changes via setParam(). More...
 
virtual void addParameter (const paramkey &key, paramval *val, paramval minBound, paramval maxBound, const paramdescr &descr=paramdescr())
 This is the new style for adding configurable parameters. More...
 
virtual void addParameter (const paramkey &key, paramval *val, const paramdescr &descr=paramdescr())
 See addParameter(const paramkey& key, paramval* val, paramval minBound, paramval maxBound, const paramdescr& descr) More...
 
virtual void addParameter (const paramkey &key, parambool *val, const paramdescr &descr=paramdescr())
 See addParameter(const paramkey& key, paramval* val) but for bool values. More...
 
virtual void addParameter (const paramkey &key, paramint *val, paramint minBound, paramint maxBound, const paramdescr &descr=paramdescr())
 See addParameter(const paramkey& key, paramval* val) but for int values. More...
 
virtual void addParameter (const paramkey &key, paramint *val, const paramdescr &descr=paramdescr())
 
virtual void addParameterDef (const paramkey &key, paramval *val, paramval def, paramval minBound, paramval maxBound, const paramdescr &descr=paramdescr())
 This function is only provided for convenience. More...
 
virtual void addParameterDef (const paramkey &key, paramval *val, paramval def, const paramdescr &descr=paramdescr())
 
virtual void addParameterDef (const paramkey &key, parambool *val, parambool def, const paramdescr &descr=paramdescr())
 See addParameterDef(const paramkey&, paramval*, paramval) More...
 
virtual void addParameterDef (const paramkey &key, paramint *val, paramint def, paramint minBound, paramint maxBound, const paramdescr &descr=paramdescr())
 See addParameterDef(const paramkey&, paramval*, paramval) More...
 
virtual void addParameterDef (const paramkey &key, paramint *val, paramint def, const paramdescr &descr=paramdescr())
 
virtual void setParamDescr (const paramkey &key, const paramdescr &descr, bool traverseChildren=true)
 sets a description for the given parameter More...
 
int getId () const
 return the id of the configurable objects, which is created by random on initialisation More...
 
virtual paramkey getName () const
 return the name of the object More...
 
virtual paramkey getRevision () const
 returns the revision of the object More...
 
virtual void setName (const paramkey &name, bool callSetNameOfInspectable=true)
 Sets the name of the configurable. More...
 
virtual void setRevision (const paramkey &revision)
 sets the revision Hint: { return "$ID$"; } More...
 
virtual paramval getParam (const paramkey &key, bool traverseChildren=true) const
 returns the value of the requested parameter or 0 (+ error message to stderr) if unknown. More...
 
virtual bool hasParam (const paramkey &key, bool traverseChildren=true) const
 Returns if the requested parameter is part of the configurable or their children. More...
 
virtual bool setParam (const paramkey &key, paramval val, bool traverseChildren=true)
 sets the value of the given parameter or does nothing if unknown. More...
 
virtual void setParamBounds (const paramkey &key, paramval minBound, paramval maxBound, bool traverseChildren=true)
 Sets the bounds (minBound and maxBound) of the given parameter. More...
 
virtual void setParamBounds (const paramkey &key, paramint minBound, paramint maxBound, bool traverseChildren=true)
 
virtual void setParamBounds (const paramkey &key, paramvalBounds bounds, bool traverseChildren=true)
 
virtual void setParamBounds (const paramkey &key, paramintBounds bounds, bool traverseChildren=true)
 
virtual paramlist getParamList () const
 The list of all parameters with there value as allocated lists. More...
 
virtual std::list< paramkeygetAllParamNames (bool traverseChildren=true)
 returns all names that are configureable More...
 
virtual parammap getParamValMap () const
 
virtual paramintmap getParamIntMap () const
 
virtual paramboolmap getParamBoolMap () const
 
virtual paramdescr getParamDescr (const paramkey &key, bool traverseChildren=true) const
 returns the description for the given parameter More...
 
virtual paramvalBounds getParamvalBounds (const paramkey &key, bool traverseChildren=true) const
 
virtual paramintBounds getParamintBounds (const paramkey &key, bool traverseChildren=true) const
 
virtual bool hasParamDescr (const paramkey &key, bool traverseChildren=true) const
 
virtual bool hasParamvalBounds (const paramkey &key, bool traverseChildren=true) const
 
virtual bool hasParamintBounds (const paramkey &key, bool traverseChildren=true) const
 
virtual bool storeCfg (const char *filenamestem, const std::list< std::string > &comments=std::list< std::string >())
 stores the key values paires into the file : filenamestem.cfg including the comments given in the list More...
 
virtual bool restoreCfg (const char *filenamestem)
 restores the key values paires from the file : filenamestem.cfg More...
 
void print (FILE *f, const char *prefix, int columns=90, bool traverseChildren=true) const
 prints the keys, values and descriptions to the file. Each line is prefixed More...
 
bool parse (FILE *f, const char *prefix=0, bool traverseChildren=true)
 parses the configuration from the given file More...
 
virtual void addConfigurable (Configurable *conf)
 Adds a configurable as a child object. More...
 
virtual void removeConfigurable (Configurable *conf)
 Removes a configurable as a child object. More...
 
virtual const configurableListgetConfigurables () const
 Returns the list containing all configurable children. More...
 
virtual void configurableChanged ()
 Indicates that the configurable itself or the configurable children attached to this configurable have changed. More...
 
- Public Member Functions inherited from BackCaller
 BackCaller ()
 
virtual ~BackCaller ()
 
virtual void addCallbackable (Callbackable *callbackableInstance, CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
 Adds a Callbackable instance to this caller instance. More...
 
virtual void removeCallbackable (Callbackable *callbackableInstance, CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
 Removes a Callbackable instance from this caller instance. More...
 
virtual void removeAllCallbackables (CallbackableType type)
 Removes all Callbackable instances from this caller instance. More...
 
virtual void callBack (CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
 Calls all registered callbackable classes of the determined type. More...
 
virtual void callBackQMP (CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
 Calls all registered callbackable classes of the determined type. More...
 
- Public Member Functions inherited from Callbackable
 Callbackable ()
 
virtual ~Callbackable ()
 

Protected Member Functions

virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &)
 
virtual void getUsage (osg::ApplicationUsage &au) const
 
virtual void accept (osgGA::GUIEventHandlerVisitor &v)
 
virtual bool init (int argc, char **argv)
 
virtual void updateGraphics ()
 update the graphics objects More...
 
void setCameraHomePos (const osg::Vec3 &eye, const osg::Vec3 &view)
 define the home position and view orientation of the camera. More...
 
void setCameraMode (CameraMode mode)
 Sets the mode of the camera, the numbers are the same like the keys. More...
 
bool startVideoRecording (const char *name)
 start video recording (write frames to name(XXX) folder) More...
 
bool stopVideoRecording ()
 stop video recording More...
 
void setWatchedAgent (OdeAgent *agent)
 Sets the agent to be watched with the camera. More...
 
OdeAgentgetWatchedAgent () const
 returns the watched agent (or 0) More...
 
bool control_c_pressed ()
 
 __attribute__ ((deprecated)) void showParams(const ConfigList &configs)
 shows all parameters of all given configurable objects More...
 
virtual bool processCmdLine (int argc, char **argv)
 returns false if the program is to exit More...
 
void resetSyncTimer ()
 
long timeOfDayinMS ()
 
std::list< std::pair
< std::string, double > > 
parseKeyValuePairs (std::string kv)
 
- Protected Member Functions inherited from Base
virtual void setTimeStats (double time, double realtimefactor, double truerealtimefactor, bool pause)
 
virtual void changeShadowTechnique ()
 Changes the currently used shadow technique. More...
 
virtual void base_close ()
 deletes the stuff that is created on makescene and the like More...
 
- Protected Member Functions inherited from Configurable
void copyParameters (const Configurable &, bool traverseChildren=true)
 copies the internal params of the given configurable More...
 
void printdescr (FILE *f, const char *prefix, const paramkey &key, int columns, int indent) const
 

Static Protected Member Functions

static void nearCallback_TopLevel (void *data, dGeomID o1, dGeomID o2)
 
static void nearCallback (void *data, dGeomID o1, dGeomID o2)
 

Protected Attributes

std::list< PlotOption > & plotoptions
 
GlobalData globalData
 
osg::ref_ptr< VideoStreamvideostream
 
long realtimeoffset
 
long simtimeoffset
 
double truerealtimefactor
 
bool justresettimes
 
bool drawContacts
 
paramint windowWidth
 
paramint windowHeight
 
paramint defaultFPS
 
bool pause
 
bool simulation_time_reached
 
long int simulation_time
 
bool noGraphics
 
bool useKeyHandler
 
int guiloggerinterval
 
int filelogginginterval
 
int matrixvizinterval
 
std::string initConfParams
 parameters for configurables set on commandline More...
 
char odeRobotsCfg [256]
 
int currentCycle
 < filename of config file More...
 
CameraHandle cameraHandle
 
parambool useOdeThread
 
parambool useOsgThread
 
parambool useQMPThreads
 
parambool inTaskedMode
 
std::string windowName
 
SimulationState state
 
osg::ArgumentParser * arguments
 
LPZViewerviewer
 
osgGA::KeySwitchMatrixManipulator * keyswitchManipulator
 
char ** orig_argv
 
std::list< std::string > paletteFiles
 
std::list< std::string > colorAliasFiles
 
bool verboseColorLoading
 
bool startConfigurator
 
pthread_t odeThread
 
pthread_t osgThread
 
bool odeThreadCreated
 
bool osgThreadCreated
 
- Protected Attributes inherited from Base
dGeomID ground
 
OsgHandle osgHandle
 
OdeHandle odeHandle
 
std::string caption
 
std::string title
 
std::string groundTexture
 
osg::Group * dummy
 
osg::Node * hud
 
osgText::Text * timestats
 
osgText::Text * captionline
 
osgText::Text * titleline
 
StatLineProperties statlineprop
 
Primitiveplane
 
HUDStatisticsManagerhUDStatisticsManager
 this manager provides methods for displaying statistics on the graphical window! More...
 
int ReceivesShadowTraversalMask
 
int CastsShadowTraversalMask
 
int shadowTexSize
 
bool useNVidia
 

Static Protected Attributes

static int ctrl_C = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from Base
static int contains (char **list, int len, const char *str)
 returns the index+1 if the list contains the given string or 0 if not More...
 
- Static Public Attributes inherited from Base
static const int PHYSICS_CALLBACKABLE = 1
 called each ode/physics step More...
 
static const int GRAPHICS_CALLBACKABLE = 2
 called each osg/draw step More...
 
- Static Public Attributes inherited from Configurable
static const CallbackableType CALLBACK_CONFIGURABLE_CHANGED = 11
 
- Static Public Attributes inherited from BackCaller
static const CallbackableType DEFAULT_CALLBACKABLE_TYPE = 0
 This is the default Callbackable type. More...
 

Member Enumeration Documentation

enum CameraMode
Enumerator
Static 
Follow 
TV 
Race 
Enumerator
none 
initialised 
running 
closed 

Constructor & Destructor Documentation

~Simulation ( )
virtual

Member Function Documentation

__attribute__ ( (deprecated)  ) const
inlineprotected

shows all parameters of all given configurable objects

Deprecated:
this is handled by simulation itself, do not call this function anymore
void accept ( osgGA::GUIEventHandlerVisitor &  v)
protectedvirtual
virtual void addCallback ( GlobalData globalData,
bool  draw,
bool  pause,
bool  control 
)
inlinevirtual

optional additional callback function which is called every simulation step.

Called between physical simulation step and drawing.

Parameters
drawindicates that objects are drawn in this timestep
pausealways false (only called of simulation is running)
controlindicates that robots have been controlled this timestep

Reimplemented in ThisSim, and ThisSim.

void addColorAliasFile ( const std::string &  filename,
bool  verbose = false 
)
virtual

adds a color alias file to be loaded at initialization time Call this before run()!

void addPaletteFile ( const std::string &  filename,
bool  verbose = false 
)
virtual

adds a palette file to be loaded at initialization time Call this before run()!

virtual void bindingDescription ( osg::ApplicationUsage &  au) const
inlinevirtual

this can be used to describe the key bindings used by command()

Reimplemented in ThisSim, and ThisSim.

virtual bool collCallback ( const OdeHandle ,
void *  data,
dGeomID  o1,
dGeomID  o2 
)
inlinevirtual

collCallback() can be used to overload the standart collision handling.

However it is called after the robots collision handling.

Returns
true if collision is treated, false otherwise
virtual bool command ( const OdeHandle ,
const OsgHandle ,
GlobalData globalData,
int  key,
bool  down 
)
inlinevirtual

is called if a key was pressed.

For keycodes see: osgGA::GUIEventAdapter

Returns
true if the key was handled

Reimplemented in ThisSim, and ThisSim.

bool config ( GlobalData globalData)
virtual

config() is called when the user presses Ctrl-C

Returns
false to exit program, true otherwise
bool control_c_pressed ( )
protected
void doOnCallBack ( BackCaller source,
BackCaller::CallbackableType  type = BackCaller::DEFAULT_CALLBACKABLE_TYPE 
)
overridevirtual

This method is invoked when a callback is done from the class where this class is for callback registered.

Parameters
sourcethe caller instance which did the callback.
typethis type can be used to differ from varying types of callback.
See Also
BackCaller

Implements Callbackable.

void end ( GlobalData globalData)
virtual

end() is called at the end and should tidy up

void getUsage ( osg::ApplicationUsage &  au) const
protectedvirtual
OdeAgent * getWatchedAgent ( ) const
protected

returns the watched agent (or 0)

bool handle ( const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &   
)
protectedvirtual
bool init ( int  argc,
char **  argv 
)
protectedvirtual
void nearCallback ( void *  data,
dGeomID  o1,
dGeomID  o2 
)
staticprotected

use the new method with substances

void nearCallback_TopLevel ( void *  data,
dGeomID  o1,
dGeomID  o2 
)
staticprotected
void odeStep ( )
virtual
void osgStep ( )
virtual
list< pair< string, double > > parseKeyValuePairs ( std::string  kv)
protected
bool processCmdLine ( int  argc,
char **  argv 
)
protectedvirtual

returns false if the program is to exit

void resetSyncTimer ( )
protected
bool restart ( const OdeHandle ,
const OsgHandle ,
GlobalData globalData 
)
virtual

restart() is called at the second and all following starts of the cylce The end of a cycle is determined by (simulation_time_reached==true)

restart() is called at the second and all following starts of the cylces

Parameters
theodeHandle
theosgHandle
globalData
Returns
if the simulation should be restarted; this is false by default
bool run ( int  argc,
char **  argv 
)

starts the Simulation.

Do not overload it. This function returns of the simulation is terminated.

Returns
: true if closed regulary, false on error
void setCameraHomePos ( const osg::Vec3 eye,
const osg::Vec3 view 
)
protected

define the home position and view orientation of the camera.

view.x is the heading angle in degree. view.y is the tilt angle in degree (nick), view.z is ignored

void setCameraMode ( CameraMode  mode)
protected

Sets the mode of the camera, the numbers are the same like the keys.

Parameters
modesee CameraMode
void setWatchedAgent ( OdeAgent agent)
protected

Sets the agent to be watched with the camera.

Parameters
agentto set
virtual void start ( const OdeHandle ,
const OsgHandle ,
GlobalData globalData 
)
pure virtual

start() is called at the first start of the cycles and should create all the object (obstacles, agents...).

Implemented in ThisSim, and ThisSim.

bool startVideoRecording ( const char *  name)
protected

start video recording (write frames to name(XXX) folder)

bool stopVideoRecording ( )
protected

stop video recording

long timeOfDayinMS ( )
protected
void updateGraphics ( )
protectedvirtual

update the graphics objects

virtual void usage ( ) const
inlinevirtual

this can be used to print additional usage information (cmd-line options)

Reimplemented in ThisSim.

Member Data Documentation

osg::ArgumentParser* arguments
protected
CameraHandle cameraHandle
protected
std::list<std::string> colorAliasFiles
protected
int ctrl_C = 0
staticprotected
int currentCycle
protected

< filename of config file

the current cycle; the simulation restarts if restart() returns true

paramint defaultFPS
protected
bool drawContacts
protected
int filelogginginterval
protected
GlobalData globalData
protected
int guiloggerinterval
protected
std::string initConfParams
protected

parameters for configurables set on commandline

parambool inTaskedMode
protected
bool justresettimes
protected
osgGA::KeySwitchMatrixManipulator* keyswitchManipulator
protected
int matrixvizinterval
protected
bool noGraphics
protected
char odeRobotsCfg[256]
protected
pthread_t odeThread
protected
bool odeThreadCreated
protected
char** orig_argv
protected
pthread_t osgThread
protected
bool osgThreadCreated
protected
std::list<std::string> paletteFiles
protected
bool pause
protected
std::list<PlotOption>& plotoptions
protected
long realtimeoffset
protected
long simtimeoffset
protected
long int simulation_time
protected
bool simulation_time_reached
protected
bool startConfigurator
protected
SimulationState state
protected
double truerealtimefactor
protected
bool useKeyHandler
protected
parambool useOdeThread
protected
parambool useOsgThread
protected
parambool useQMPThreads
protected
bool verboseColorLoading
protected
osg::ref_ptr<VideoStream> videostream
protected
LPZViewer* viewer
protected
paramint windowHeight
protected
std::string windowName
protected
paramint windowWidth
protected

The documentation for this class was generated from the following files: