Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Simulator Class Reference

#include <Simulator.h>

Inheritance diagram for Simulator:

Detailed Description

Definition at line 22 of file Simulator.h.

List of all members.

Classes

class  CommandThread
class  FrameCounter
 subscribed by Simulator to message queue's send; ensures that SharedGlobals::MotionSimConfig::frameNumber stays in sync with the message serial number More...
class  MotionMonitorThread
class  SyncDataThread

Public Member Functions

 Simulator ()
 constructor
 ~Simulator ()
virtual void doStart ()
virtual void doStop ()
virtual void run ()
virtual void plistValueChanged (const plist::PrimitiveBase &pl)
virtual void plistCollectionEntryAdded (plist::Collection &col, plist::ObjectBase &primitive)
virtual void plistCollectionEntryRemoved (plist::Collection &col, plist::ObjectBase &primitive)
virtual void plistCollectionEntriesChanged (plist::Collection &col)
virtual void messagesRead (MessageQueueBase &mq, unsigned int n)

Static Public Member Functions

static const char * getClassName ()
static ProcessID::ProcessID_t getID ()
static const char * getCameraQueueID ()
static const char * getSensorQueueID ()
static const char * getTimerWakeupID ()
static const char * getMotionWakeupID ()
static const char * getStatusRequestID ()
static const char * getCommandQueueID ()
static void sendCommand (const std::string &cmd)
static void registerMotionHook (MotionHook &h)
 Registers the MotionHook to have its motionCheck() called following each motion update.
static void deregisterMotionHook (MotionHook &h)
 Removes the MotionHook from the list, no longer receives any notifications.
static void clearMotionHooks ()
static void setMotionStarting ()
static void setMotionStopping ()
static void updateMotion (const float outputs[][NumOutputs])
static void updatePIDs (const std::vector< MotionHook::PIDUpdate > &pids)
static void setMotionLeavingRealtime (bool isFullSpeed)
static void setMotionEnteringRealtime ()

Static Public Attributes

static MotionMonitorThreadmotionHookMonitor = NULL

Protected Types

enum  step_t {
  STEP_NONE, STEP_CAMERA, STEP_SENSOR, STEP_TIMER,
  STEP_MOTION
}
typedef void(DeviceDriver::* getDataSources_t )(std::map< std::string, DataSource * > &)
typedef MessageQueue< 10 > CommandQueue_t

Protected Member Functions

template<typename T >
void abortable (const T &fn)
 blocks until the thread is either aborted by the user via cmdThread (i.e. shutdown) or completes successfully
template<typename T , typename C >
void abortable (const T &fn, C &userdata)
 blocks until the thread is either aborted by the user via cmdThread (i.e. shutdown) or completes successfully
template<typename T , typename C >
void abortable (const T &fn, const C &userdata)
 blocks until the thread is either aborted by the user via cmdThread (i.e. shutdown) or completes successfully
bool sendSensor (bool syncCall)
unsigned int nextVisionTime ()
unsigned int nextSensorTime ()
void incrementTime ()
void sendTimerWakeup ()
unsigned int getNextFrame ()
void resetSpeedMode ()
void processRunlevel (SharedGlobals::runlevel_t curRunLevel)
bool processCommand (const std::string &line, bool addToHistory)
 process an individual command
void updateDataSources (std::set< std::string > &active, std::set< DataSource * > &activeSrcs, const plist::ArrayOf< plist::Primitive< std::string > > &requested, getDataSources_t getDataSources)
void lookupDataSource (const std::string &name, getDataSources_t getDataSources, std::set< DataSource * > &dataSrcs, std::string &errStr)
std::string lookupDataSourceName (const DataSource *src) const
void cmdQuit (const std::vector< std::string > &args)
void cmdLoad (const std::vector< std::string > &args)
void cmdSave (const std::vector< std::string > &args)
void cmdRunlevel (const std::vector< std::string > &args)
bool cmdPrint (const std::vector< std::string > &args)
bool cmdSet (const std::vector< std::string > &args)
void cmdRun (const std::vector< std::string > &args, bool isRelative)
void cmdRun (const std::vector< std::string > &args)
void cmdPause (const std::vector< std::string > &args)
void cmdHelp (const std::vector< std::string > &args)
void cmdStep (const std::vector< std::string > &args)
void cmdStatus (const std::vector< std::string > &args)
void cmdAdvance (const std::vector< std::string > &args)
void cmdFreeze (bool v, const std::vector< std::string > &args)
void cmdReset (const std::vector< std::string > &args)
void cmdNew (const std::vector< std::string > &args)
void cmdDelete (const std::vector< std::string > &args)
void cmdPost (const std::vector< std::string > &args)
void cmdMsg (const std::vector< std::string > &args)

Static Protected Member Functions

static void replaceEntry (const std::string &name, plist::Dictionary &d, const std::string &comment)
static void syncSensors ()
 this is registered as a callback with DataSource::resourceSync so we send notifications immediately following updates, cutting latency
static bool gotCommand (RCRegion *msg)
 for commands coming from other processes via commandQueue and commandrecv
static bool gotMotion (RCRegion *msg)
 when running in multi-process mode, receives output value updates from motion process
static bool gotMotionPIDs (RCRegion *msg)
 when running in multi-process mode, receives output PID updates from motion process

Protected Attributes

Simulator::FrameCounter frameCounter
 subscribed by Simulator to message queue's send; ensures that SharedGlobals::MotionSimConfig::frameNumber stays in sync with the message serial number
Simulator::CommandThread cmdThread
SyncDataThread sensorThread
bool sendSensorSent
SharedObject< sim::CameraQueue_tcameraQueue
SharedObject< sim::SensorQueue_tsensorQueue
SharedObject< sim::TimerWakeup_ttimerWakeup
SharedObject< sim::MotionWakeup_tmotionWakeup
SharedObject
< sim::StatusRequest_t
statusRequest
SharedObject< SoundManagersoundmanager
SharedObject
< sim::SoundPlayQueue_t
sounds
SharedObject< sim::EventQueue_tevents
SharedObject< sim::MotionOutput_tmotionout
SharedObject
< sim::MotionOutputPIDs_t
motionoutpids
SharedObject< CommandQueue_tcommandQueue
MessageQueueStatusThread cameraStatus
MessageQueueStatusThread sensorStatus
MessageQueueStatusThread timerStatus
MessageQueueStatusThread motionStatus
MessageQueueStatusThread eventsStatus
IPCEventTranslatoretrans
MessageReceivercommandrecv
MessageReceivermotionrecv
MessageReceivermotionpidsrecv
std::set< unsigned int > frameTimes
double runSpeed
double lastTimeScale
step_t step
unsigned int waitingSteps
SharedGlobals::runlevel_t curLevel
std::set< std::string > activeSensors
std::set< DataSource * > activeSensorSrcs
std::set< std::string > activeCameras
std::set< DataSource * > activeCameraSrcs
TimeET fullspeedWallStart
 "real" wall-clock time that full-speed mode was entered
unsigned int fullspeedSimStart
 simulator time at which full-speed mode was entered
TimeET lastFrameWallStart
 "real" wall-clock time that processing started on last frame (only valid in full-speed mode)
float avgWallTime
 running average of frame processing time
float avgSimTime
 running average of frame increments
Thread::Lock simLock

Static Protected Attributes

static SimulatortheSim = NULL
static std::set< MotionHook * > motionHooks
static const float avgSpeedupGamma = .99f
 gamma parameter for calculating running average in avgWallTime and avgSimTime

Private Member Functions

 Simulator (const Simulator &)
 don't call (copy constructor)
Simulatoroperator= (const Simulator &)
 don't call (assignment operator)

Member Typedef Documentation

typedef MessageQueue<10> CommandQueue_t [protected]

Definition at line 227 of file Simulator.h.

typedef void(DeviceDriver::* getDataSources_t)(std::map< std::string, DataSource * > &) [protected]

Definition at line 192 of file Simulator.h.


Member Enumeration Documentation

enum step_t [protected]
Enumerator:
STEP_NONE 
STEP_CAMERA 
STEP_SENSOR 
STEP_TIMER 
STEP_MOTION 

Definition at line 173 of file Simulator.h.


Constructor & Destructor Documentation

Simulator (  ) 

constructor

Definition at line 41 of file Simulator.cc.

~Simulator (  ) 

Definition at line 149 of file Simulator.cc.

Simulator ( const Simulator  )  [private]

don't call (copy constructor)


Member Function Documentation

void abortable ( const T fn,
const C &  userdata 
) [protected]

blocks until the thread is either aborted by the user via cmdThread (i.e. shutdown) or completes successfully

Definition at line 134 of file Simulator.h.

void abortable ( const T fn,
C &  userdata 
) [protected]

blocks until the thread is either aborted by the user via cmdThread (i.e. shutdown) or completes successfully

Definition at line 128 of file Simulator.h.

void abortable ( const T fn  )  [protected]

blocks until the thread is either aborted by the user via cmdThread (i.e. shutdown) or completes successfully

Definition at line 122 of file Simulator.h.

Referenced by doStart(), and run().

static void clearMotionHooks (  )  [static]

Definition at line 66 of file Simulator.h.

void cmdAdvance ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1521 of file Simulator.cc.

Referenced by processCommand().

void cmdDelete ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1692 of file Simulator.cc.

Referenced by processCommand().

void cmdFreeze ( bool  v,
const std::vector< std::string > &  args 
) [protected]

Definition at line 1593 of file Simulator.cc.

Referenced by processCommand().

void cmdHelp ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1255 of file Simulator.cc.

Referenced by processCommand().

void cmdLoad ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1115 of file Simulator.cc.

Referenced by processCommand().

void cmdMsg ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1797 of file Simulator.cc.

Referenced by processCommand().

void cmdNew ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1642 of file Simulator.cc.

Referenced by processCommand().

void cmdPause ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1246 of file Simulator.cc.

Referenced by processCommand().

void cmdPost ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1742 of file Simulator.cc.

Referenced by processCommand().

bool cmdPrint ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1170 of file Simulator.cc.

Referenced by processCommand().

void cmdQuit ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1110 of file Simulator.cc.

Referenced by processCommand(), and CommandThread::run().

void cmdReset ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1619 of file Simulator.cc.

Referenced by processCommand().

void cmdRun ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1232 of file Simulator.cc.

void cmdRun ( const std::vector< std::string > &  args,
bool  isRelative 
) [protected]

Definition at line 1220 of file Simulator.cc.

Referenced by processCommand().

void cmdRunlevel ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1138 of file Simulator.cc.

Referenced by processCommand().

void cmdSave ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1128 of file Simulator.cc.

Referenced by processCommand().

bool cmdSet ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1193 of file Simulator.cc.

Referenced by processCommand(), and Simulator().

void cmdStatus ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1426 of file Simulator.cc.

Referenced by processCommand().

void cmdStep ( const std::vector< std::string > &  args  )  [protected]

Definition at line 1383 of file Simulator.cc.

Referenced by processCommand().

static void deregisterMotionHook ( MotionHook h  )  [static]

Removes the MotionHook from the list, no longer receives any notifications.

Responsibility for memory (de)allocation is NOT assumed by registration, so this doesn't affect h directly.

Definition at line 61 of file Simulator.h.

Referenced by Motion::doStop().

void doStart (  )  [virtual]

Reimplemented from Process.

Definition at line 168 of file Simulator.cc.

void doStop (  )  [virtual]

Reimplemented from Process.

Definition at line 568 of file Simulator.cc.

static const char* getCameraQueueID (  )  [static]

Definition at line 36 of file Simulator.h.

static const char* getClassName (  )  [static]

Definition at line 33 of file Simulator.h.

static const char* getCommandQueueID (  )  [static]

Definition at line 41 of file Simulator.h.

Referenced by sendCommand().

static ProcessID::ProcessID_t getID (  )  [static]

Definition at line 34 of file Simulator.h.

Referenced by doStart(), and doStop().

static const char* getMotionWakeupID (  )  [static]

Definition at line 39 of file Simulator.h.

unsigned int getNextFrame (  )  [protected]

Definition at line 829 of file Simulator.cc.

Referenced by cmdStep(), and incrementTime().

static const char* getSensorQueueID (  )  [static]

Definition at line 37 of file Simulator.h.

static const char* getStatusRequestID (  )  [static]

Definition at line 40 of file Simulator.h.

static const char* getTimerWakeupID (  )  [static]

Definition at line 38 of file Simulator.h.

bool gotCommand ( RCRegion msg  )  [static, protected]

for commands coming from other processes via commandQueue and commandrecv

Definition at line 964 of file Simulator.cc.

Referenced by doStart().

bool gotMotion ( RCRegion msg  )  [static, protected]

when running in multi-process mode, receives output value updates from motion process

Definition at line 971 of file Simulator.cc.

Referenced by run().

bool gotMotionPIDs ( RCRegion msg  )  [static, protected]

when running in multi-process mode, receives output PID updates from motion process

Definition at line 980 of file Simulator.cc.

Referenced by run().

void incrementTime (  )  [protected]

Definition at line 788 of file Simulator.cc.

Referenced by cmdStep(), messagesRead(), plistValueChanged(), and run().

void lookupDataSource ( const std::string &  name,
getDataSources_t  getDataSources,
std::set< DataSource * > &  dataSrcs,
std::string &  errStr 
) [protected]

Definition at line 1056 of file Simulator.cc.

Referenced by cmdAdvance(), cmdFreeze(), cmdReset(), and updateDataSources().

std::string lookupDataSourceName ( const DataSource src  )  const [protected]

Definition at line 1082 of file Simulator.cc.

Referenced by cmdAdvance(), and cmdStatus().

void messagesRead ( MessageQueueBase mq,
unsigned int  n 
) [virtual]

Implements StatusListener.

Definition at line 421 of file Simulator.cc.

unsigned int nextSensorTime (  )  [protected]

Definition at line 783 of file Simulator.cc.

Referenced by cmdStatus(), and getNextFrame().

unsigned int nextVisionTime (  )  [protected]

Definition at line 774 of file Simulator.cc.

Referenced by cmdStatus(), and getNextFrame().

Simulator& operator= ( const Simulator  )  [private]

don't call (assignment operator)

void plistCollectionEntriesChanged ( plist::Collection col  )  [virtual]

Reimplemented from CollectionListener.

Definition at line 379 of file Simulator.cc.

Referenced by driversChangedFunctor().

void plistCollectionEntryAdded ( plist::Collection col,
plist::ObjectBase primitive 
) [virtual]

Reimplemented from CollectionListener.

Definition at line 308 of file Simulator.cc.

void plistCollectionEntryRemoved ( plist::Collection col,
plist::ObjectBase primitive 
) [virtual]

Reimplemented from CollectionListener.

Definition at line 346 of file Simulator.cc.

void plistValueChanged ( const plist::PrimitiveBase pl  )  [virtual]

Implements PrimitiveListener.

Definition at line 284 of file Simulator.cc.

bool processCommand ( const std::string &  line,
bool  addToHistory 
) [protected]

process an individual command

Definition at line 868 of file Simulator.cc.

Referenced by gotCommand(), CommandThread::run(), and Simulator().

void processRunlevel ( SharedGlobals::runlevel_t  curRunLevel  )  [protected]

Definition at line 859 of file Simulator.cc.

Referenced by doStart(), doStop(), Simulator(), and ~Simulator().

static void registerMotionHook ( MotionHook h  )  [static]

Registers the MotionHook to have its motionCheck() called following each motion update.

Responsibility for memory (de)allocation is NOT assumed by registration.

Definition at line 54 of file Simulator.h.

Referenced by Motion::doStart().

void replaceEntry ( const std::string &  name,
plist::Dictionary d,
const std::string &  comment 
) [static, protected]

Definition at line 731 of file Simulator.cc.

Referenced by Simulator().

void resetSpeedMode (  )  [protected]

Definition at line 676 of file Simulator.cc.

Referenced by plistValueChanged(), and run().

void run (  )  [virtual]

Reimplemented from Process.

Definition at line 203 of file Simulator.cc.

void sendCommand ( const std::string &  cmd  )  [static]

Definition at line 450 of file Simulator.cc.

Referenced by SharedGlobals::get_time(), and sim::sim().

bool sendSensor ( bool  syncCall  )  [protected]

Definition at line 742 of file Simulator.cc.

Referenced by cmdAdvance(), incrementTime(), and run().

void sendTimerWakeup (  )  [protected]
void setMotionEnteringRealtime (  )  [static]

Definition at line 519 of file Simulator.cc.

Referenced by Motion::doStart(), Motion::gotWakeup(), and resetSpeedMode().

void setMotionLeavingRealtime ( bool  isFullSpeed  )  [static]

Definition at line 502 of file Simulator.cc.

Referenced by Motion::doStop(), Motion::gotWakeup(), resetSpeedMode(), and run().

void setMotionStarting (  )  [static]

Definition at line 460 of file Simulator.cc.

Referenced by Motion::doStart().

void setMotionStopping (  )  [static]

Definition at line 471 of file Simulator.cc.

Referenced by doStop(), and Motion::doStop().

static void syncSensors (  )  [static, protected]

this is registered as a callback with DataSource::resourceSync so we send notifications immediately following updates, cutting latency

Definition at line 171 of file Simulator.h.

Referenced by setMotionEnteringRealtime().

void updateDataSources ( std::set< std::string > &  active,
std::set< DataSource * > &  activeSrcs,
const plist::ArrayOf< plist::Primitive< std::string > > &  requested,
getDataSources_t  getDataSources 
) [protected]
void updateMotion ( const float  outputs[][NumOutputs]  )  [static]

Definition at line 482 of file Simulator.cc.

Referenced by gotMotion(), and MotionExecThread::poll().

void updatePIDs ( const std::vector< MotionHook::PIDUpdate > &  pids  )  [static]

Definition at line 492 of file Simulator.cc.

Referenced by gotMotionPIDs().


Member Data Documentation

std::set<std::string> activeCameras [protected]
std::set<std::string> activeSensors [protected]
float avgSimTime [protected]

running average of frame increments

Definition at line 259 of file Simulator.h.

Referenced by cmdStatus(), incrementTime(), and resetSpeedMode().

const float avgSpeedupGamma = .99f [static, protected]

gamma parameter for calculating running average in avgWallTime and avgSimTime

Definition at line 260 of file Simulator.h.

Referenced by incrementTime().

float avgWallTime [protected]

running average of frame processing time

Definition at line 258 of file Simulator.h.

Referenced by cmdStatus(), incrementTime(), and resetSpeedMode().

Definition at line 230 of file Simulator.h.

Referenced by resetSpeedMode(), and run().

Definition at line 228 of file Simulator.h.

Referenced by doStart(), and Simulator().

Definition at line 237 of file Simulator.h.

Referenced by doStart(), and doStop().

IPCEventTranslator* etrans [protected]

Definition at line 236 of file Simulator.h.

Referenced by doStart(), and doStop().

Definition at line 224 of file Simulator.h.

Referenced by cmdMsg(), cmdPost(), doStart(), and messagesRead().

Definition at line 234 of file Simulator.h.

Referenced by doStart(), and resetSpeedMode().

subscribed by Simulator to message queue's send; ensures that SharedGlobals::MotionSimConfig::frameNumber stays in sync with the message serial number

Referenced by Simulator().

std::set<unsigned int> frameTimes [protected]

Definition at line 242 of file Simulator.h.

Referenced by getNextFrame(), and incrementTime().

unsigned int fullspeedSimStart [protected]

simulator time at which full-speed mode was entered

Definition at line 256 of file Simulator.h.

Referenced by cmdStatus(), and resetSpeedMode().

TimeET fullspeedWallStart [protected]

"real" wall-clock time that full-speed mode was entered

Definition at line 255 of file Simulator.h.

Referenced by cmdStatus(), and resetSpeedMode().

TimeET lastFrameWallStart [protected]

"real" wall-clock time that processing started on last frame (only valid in full-speed mode)

Definition at line 257 of file Simulator.h.

Referenced by incrementTime(), and resetSpeedMode().

double lastTimeScale [protected]

Definition at line 244 of file Simulator.h.

Referenced by resetSpeedMode().

Definition at line 225 of file Simulator.h.

Referenced by run().

Definition at line 226 of file Simulator.h.

Referenced by run().

Definition at line 239 of file Simulator.h.

Referenced by doStop(), and run().

Definition at line 238 of file Simulator.h.

Referenced by doStop(), and run().

Definition at line 233 of file Simulator.h.

Referenced by resetSpeedMode(), and run().

double runSpeed [protected]

Definition at line 243 of file Simulator.h.

Referenced by cmdPause(), cmdRun(), and run().

bool sendSensorSent [protected]

Definition at line 165 of file Simulator.h.

Referenced by cmdAdvance(), incrementTime(), run(), and sendSensor().

Definition at line 231 of file Simulator.h.

Referenced by resetSpeedMode(), and run().

Definition at line 164 of file Simulator.h.

Referenced by cmdAdvance(), resetSpeedMode(), run(), and syncSensors().

Definition at line 222 of file Simulator.h.

Definition at line 223 of file Simulator.h.

Referenced by doStart().

Definition at line 221 of file Simulator.h.

Referenced by cmdStatus(), and Simulator().

step_t step [protected]

Definition at line 245 of file Simulator.h.

Referenced by cmdStep(), and incrementTime().

Definition at line 232 of file Simulator.h.

Referenced by resetSpeedMode(), and run().

unsigned int waitingSteps [protected]

Definition at line 246 of file Simulator.h.

Referenced by incrementTime(), and messagesRead().


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

Tekkotsu Hardware Abstraction Layer 5.1CVS
Generated Mon May 9 05:01:42 2016 by Doxygen 1.6.3