Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SharedGlobals Class Reference

A class to hold various simulator parameters which need to be accessed from multiple processes. More...

#include <SharedGlobals.h>


Detailed Description

A class to hold various simulator parameters which need to be accessed from multiple processes.

Definition at line 14 of file SharedGlobals.h.

List of all members.

Classes

class  MotionSimConfig
 holds configuration parameters for the motion process More...
class  StreamSimConfig

Public Member Functions

 SharedGlobals ()
 constructor
 ~SharedGlobals ()
 destructor
bool setNextTimer (unsigned int t)
 sets nextTimer, returns true if the new value differs from previous value
unsigned int getNextTimer ()
 gets nextTimer
void setNextMotion (unsigned int t)
 sets nextMotion
unsigned int getNextMotion ()
 gets nextMotion
void setNextSensorUpdate (unsigned int t)
 sets nextSensorUpdate
unsigned int getNextSensorUpdate ()
 gets nextSensorUpdate
void resetBootTime ()
Shutdown Control

void signalShutdown ()
 call this to cause "system shutdown" -- clean halt of the simulator (not actually the host system)
bool isShutdown () const
 test to see if the shutdown flag has been set (non-blocking)
bool waitShutdown ()
 blocks until shutdown flag has been set
bool hadFault () const
 access to semgr, returns SemaphoreManager::hadFault()
void faultShutdown ()
 access to semgr's SemaphoreManager::faultShutdown() -- call this *after* a fault has occured from the signal handler; doesn't signal the fault itself

Public Attributes

MutexLock
< ProcessID::NumProcesses
lock
 allows mutually exclusive access to the fields of SharedObject
pid_t pids [ProcessID::NumProcesses]
 holds the host system's process ID for each simulator process
char processNames [ProcessID::NumProcesses][MAX_PROCESS_NAME_LEN]
 each process should set a string version of its name for user feedback
SensorState sensorState
Configuration Parameters

SharedGlobals::MotionSimConfig motion
 holds configuration parameters for the motion process
StreamSimConfig sensors
 holds configuration parameters for the motion process
StreamSimConfig vision
 holds configuration parameters for the motion process

Static Public Attributes

static const unsigned int MAX_PROCESS_NAME_LEN = 32
 maximum storage size of strings in processNames

Protected Member Functions

unsigned int get_real_time (double scale) const
 this returns time since boot (bootTime), scaled by scale, relative to timeOffset

Protected Attributes

unsigned int nextTimer
 set by setNextTimer, called with the current value of EventRouter::getNextTimer() after each user code section, indicates time of next timer event
unsigned int nextMotion
 updated by Motion process after each motion update
unsigned int nextSensorUpdate
 updated by Main process after each sensor update
TimeET bootTime
 real time since simulator startup (or, at least, since SharedGlobals was constructed... close enough)
double timeOffset
 the scaled value of bootTime at which isRealTime was last activated, allows you to start and stop realtime fluidly
double lastTimeScale
 updated by each call to get_time(), if timeScale differs, allows timeOffset to be updated fluidly
unsigned int autoPauseTime
 if simulatorTime is about to move past this value, timeScale is set to 0 instead, and simulatorTime is set to this
SemaphoreManager semgr
 a semaphore set, only used for running and sensorValid
SemaphoreManager::semid_t running
 the semaphore within semgr to communicate shutdown status between processes -- when the semaphore is set to 0, shutdown is requested
SemaphoreManager::semid_t sensorValid
 the semaphore within semgr to notify processes when the first sensor frame is available

Runlevel Communication



enum  runlevel_t {
  CREATED = 0, CONSTRUCTING, STARTING, RUNNING,
  STOPPING, DESTRUCTING, DESTRUCTED
}
 

defines the runlevels that each process passes through; runlevels should monotonically increase (can't go backwards)

More...
unsigned int level_count [NUM_RUNLEVELS]
 a count of the number of processes which have passed through each runlevel
static const unsigned int NUM_RUNLEVELS = DESTRUCTED+1
 symbolic access to the total number of runlevel stages
static const char *const runlevel_names [NUM_RUNLEVELS+1]
 string versions of runlevel_t for runtime user-feedback

Startup Control



plist::Primitive< boolwaitForSensors
 Controls whether to wait for initial sensor readings before triggering the startup behavior or starting the motion polling thread.
void signalHaveSensors ()
 Called by Main when the first sensorEGID event is generated.
bool haveSensors () const
 test to see if the initial sensor event has been generated
void waitSensors ()
 blocks until the initial sensor event has been generated

Time Control



unsigned int simulatorTime
 the current time within the simulation, only applicable when timeScale is negative (non-realtime)
plist::Primitive< double > timeScale
 Controls the speed at which time from get_time() will move.
unsigned int get_time ()
 returns the current simulator time, in milliseconds since startup
float getTimeScale () const
 returns the current simulator timeScale (speed factor), as a ratio of real time (e.g. '2' means simulation is running two times wall clock)
void setAutoPauseTime (unsigned int t)
 sets autoPauseTime
unsigned int getAutoPauseTime () const
 returns autoPauseTime

Member Enumeration Documentation

enum runlevel_t

defines the runlevels that each process passes through; runlevels should monotonically increase (can't go backwards)

Enumerator:
CREATED 

corresponding element of level_count is incremented prior to each fork -- not strictly a runlevel per se

CONSTRUCTING 

currently initializing

STARTING 

setting up shared memory regions with other processes

RUNNING 

full activity, stay here until the running semaphore is set to 0

STOPPING 

dereferencing shared regions, waiting for threads to finish

DESTRUCTING 

destructors are in progress

DESTRUCTED 

destruction has completed, corresponding element of level_count is incremented immediately prior to process completion

Definition at line 133 of file SharedGlobals.h.


Constructor & Destructor Documentation

SharedGlobals (  ) 

constructor

Definition at line 17 of file SharedGlobals.h.

~SharedGlobals (  ) 

destructor

Definition at line 29 of file SharedGlobals.h.


Member Function Documentation

void faultShutdown (  ) 

access to semgr's SemaphoreManager::faultShutdown() -- call this *after* a fault has occured from the signal handler; doesn't signal the fault itself

Definition at line 82 of file SharedGlobals.h.

Referenced by sim::badExitCleanup().

unsigned int get_real_time ( double  scale  )  const [protected]

this returns time since boot (bootTime), scaled by scale, relative to timeOffset

Definition at line 244 of file SharedGlobals.h.

Referenced by get_time().

unsigned int get_time (  ) 

returns the current simulator time, in milliseconds since startup

the simulator should set project_get_time::get_time_callback to call this, so calls to get_time() will be forwarded here. That wall all processes will share the same time

Definition at line 18 of file SharedGlobals.cc.

Referenced by sim::sim_get_time().

unsigned int getAutoPauseTime (  )  const

returns autoPauseTime

Definition at line 123 of file SharedGlobals.h.

Referenced by Simulator::incrementTime().

unsigned int getNextMotion (  ) 
unsigned int getNextSensorUpdate (  ) 

gets nextSensorUpdate

Definition at line 236 of file SharedGlobals.h.

float getTimeScale (  )  const

returns the current simulator timeScale (speed factor), as a ratio of real time (e.g. '2' means simulation is running two times wall clock)

the simulator should set project_get_time::get_timeScale_callback to call this, so calls to getTimeScale() will be forwarded here.

Definition at line 56 of file SharedGlobals.cc.

Referenced by sim::sim_getTimeScale().

bool hadFault (  )  const

access to semgr, returns SemaphoreManager::hadFault()

Definition at line 79 of file SharedGlobals.h.

Referenced by sim::badExitCleanup().

bool haveSensors (  )  const

test to see if the initial sensor event has been generated

Definition at line 48 of file SharedGlobals.h.

Referenced by Simulator::run(), Main::run(), and signalShutdown().

bool isShutdown (  )  const

test to see if the shutdown flag has been set (non-blocking)

Definition at line 70 of file SharedGlobals.h.

Referenced by Simulator::processRunlevel(), Simulator::run(), Motion::run(), and Main::run().

void resetBootTime (  ) 

Definition at line 238 of file SharedGlobals.h.

Referenced by Simulator::Simulator().

void setAutoPauseTime ( unsigned int  t  ) 
void setNextMotion ( unsigned int  t  ) 
void setNextSensorUpdate ( unsigned int  t  ) 

sets nextSensorUpdate

Definition at line 235 of file SharedGlobals.h.

bool setNextTimer ( unsigned int  t  ) 

sets nextTimer, returns true if the new value differs from previous value

Definition at line 229 of file SharedGlobals.h.

Referenced by Main::gotCamera(), Main::gotEvent(), Main::gotSensors(), Main::gotThreadedEvent(), Main::gotTimer(), TimerExecThread::poll(), and Main::run().

void signalHaveSensors (  ) 

Called by Main when the first sensorEGID event is generated.

When the waitForSensors setting is enabled, the startupBehavior is not activated until this occurs

Definition at line 44 of file SharedGlobals.h.

Referenced by Simulator::plistValueChanged(), Main::processEvent(), Simulator::run(), and signalShutdown().

void signalShutdown (  ) 

call this to cause "system shutdown" -- clean halt of the simulator (not actually the host system)

Definition at line 64 of file SharedGlobals.h.

Referenced by sim::badExitCleanup(), Simulator::cmdQuit(), Simulator::cmdRunlevel(), Simulator::run(), and Simulator::Simulator().

void waitSensors (  ) 

blocks until the initial sensor event has been generated

Definition at line 52 of file SharedGlobals.h.

Referenced by Simulator::run(), Motion::run(), and Main::run().

bool waitShutdown (  ) 

blocks until shutdown flag has been set

Definition at line 74 of file SharedGlobals.h.

Referenced by Process::run().


Member Data Documentation

unsigned int autoPauseTime [protected]

if simulatorTime is about to move past this value, timeScale is set to 0 instead, and simulatorTime is set to this

Definition at line 267 of file SharedGlobals.h.

Referenced by get_time(), getAutoPauseTime(), and setAutoPauseTime().

TimeET bootTime [protected]

real time since simulator startup (or, at least, since SharedGlobals was constructed... close enough)

Definition at line 258 of file SharedGlobals.h.

Referenced by get_real_time(), get_time(), and resetBootTime().

double lastTimeScale [protected]

updated by each call to get_time(), if timeScale differs, allows timeOffset to be updated fluidly

Definition at line 264 of file SharedGlobals.h.

Referenced by get_time().

unsigned int level_count[NUM_RUNLEVELS]

a count of the number of processes which have passed through each runlevel

Definition at line 148 of file SharedGlobals.h.

Referenced by sim::badExitCleanup(), sim::fork_process(), sim::manage_process(), sim::run(), SharedGlobals(), and sim::wait_runlevel().

allows mutually exclusive access to the fields of SharedObject

Definition at line 218 of file SharedGlobals.h.

Referenced by sim::badExitCleanup(), sim::manage_process(), Process::statusReport(), and sim::wait_runlevel().

const unsigned int MAX_PROCESS_NAME_LEN = 32 [static]

maximum storage size of strings in processNames

Definition at line 224 of file SharedGlobals.h.

Referenced by Process::Process().

unsigned int nextMotion [protected]

updated by Motion process after each motion update

Definition at line 252 of file SharedGlobals.h.

Referenced by getNextMotion(), and setNextMotion().

unsigned int nextSensorUpdate [protected]

updated by Main process after each sensor update

Definition at line 255 of file SharedGlobals.h.

Referenced by getNextSensorUpdate(), and setNextSensorUpdate().

unsigned int nextTimer [protected]

set by setNextTimer, called with the current value of EventRouter::getNextTimer() after each user code section, indicates time of next timer event

Definition at line 249 of file SharedGlobals.h.

Referenced by getNextTimer(), and setNextTimer().

const unsigned int NUM_RUNLEVELS = DESTRUCTED+1 [static]

symbolic access to the total number of runlevel stages

Definition at line 142 of file SharedGlobals.h.

Referenced by Simulator::cmdHelp(), Simulator::cmdRunlevel(), and SharedGlobals().

holds the host system's process ID for each simulator process

Definition at line 221 of file SharedGlobals.h.

Referenced by Process::Process(), and Simulator::run().

each process should set a string version of its name for user feedback

Definition at line 227 of file SharedGlobals.h.

Referenced by Process::Process(), and Simulator::run().

const char *const runlevel_names [static]
Initial value:
 {
  "CREATED",
  "CONSTRUCTING",
  "STARTING",
  "RUNNING",
  "STOPPING",
  "DESTRUCTING",
  "DESTRUCTED",
  NULL
}

string versions of runlevel_t for runtime user-feedback

Definition at line 145 of file SharedGlobals.h.

Referenced by Simulator::cmdHelp(), Simulator::cmdRunlevel(), and sim::wait_runlevel().

the semaphore within semgr to communicate shutdown status between processes -- when the semaphore is set to 0, shutdown is requested

Definition at line 270 of file SharedGlobals.h.

Referenced by isShutdown(), SharedGlobals(), signalShutdown(), waitShutdown(), and ~SharedGlobals().

the semaphore within semgr to notify processes when the first sensor frame is available

Definition at line 271 of file SharedGlobals.h.

Referenced by haveSensors(), SharedGlobals(), signalHaveSensors(), waitSensors(), and ~SharedGlobals().

unsigned int simulatorTime

the current time within the simulation, only applicable when timeScale is negative (non-realtime)

Definition at line 103 of file SharedGlobals.h.

Referenced by Simulator::cmdStatus(), get_time(), Simulator::incrementTime(), resetBootTime(), Simulator::resetSpeedMode(), and sim::sim().

double timeOffset [protected]

the scaled value of bootTime at which isRealTime was last activated, allows you to start and stop realtime fluidly

Definition at line 261 of file SharedGlobals.h.

Referenced by get_real_time(), get_time(), and resetBootTime().

Controls the speed at which time from get_time() will move.

You can use this to pretend your hardware is faster or slower than it actually is. For instance, a value of .5 means time will move at half speed (pretending your hardware is twice as fast) This can be useful for "slow motion" analysis, or you can speed up time to simulate a more processor-restrictive platform.

Negative values indicate full-speed processing -- time will be incremented only as quickly as it can be without dropping any video or sensor frames. (may be faster or slower than realtime) in this case, simulatorTime is used by calls to get_time()

A value of zero halts time.

Definition at line 118 of file SharedGlobals.h.

Referenced by TimerExecThread::calcSleepTime(), SyncDataThread::cancelled(), Simulator::cmdAdvance(), Simulator::cmdPause(), Simulator::cmdRun(), Simulator::cmdStatus(), Simulator::cmdStep(), Motion::doStart(), Motion::doStop(), get_time(), getTimeScale(), Main::gotTimer(), Motion::gotWakeup(), Simulator::incrementTime(), SyncDataThread::interrupted(), MotionExecThread::interrupted(), TimerExecThread::launched(), SyncDataThread::launched(), MotionExecThread::launched(), Simulator::messagesRead(), Simulator::plistCollectionEntriesChanged(), Simulator::plistCollectionEntryAdded(), Simulator::plistCollectionEntryRemoved(), Simulator::plistValueChanged(), TimerExecThread::reset(), MotionExecThread::reset(), resetBootTime(), Simulator::resetSpeedMode(), Simulator::run(), Simulator::setMotionEnteringRealtime(), sim::sim(), Simulator::Simulator(), and Simulator::updateDataSources().

Controls whether to wait for initial sensor readings before triggering the startup behavior or starting the motion polling thread.

This can avoid jumping to the 0-point on simulator launch. Changes after initial launch are ignored.

Definition at line 40 of file SharedGlobals.h.

Referenced by Main::doStart(), Simulator::plistValueChanged(), Simulator::run(), Motion::run(), Main::run(), signalShutdown(), and sim::sim().


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

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