Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SharedGlobals Class Reference

#include <SharedGlobals.h>

List of all members.


Detailed Description

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

Definition at line 13 of file SharedGlobals.h.


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< bool > waitForSensors
 Controls whether to wait for initial sensor readings before triggering the startup behavior or starting the motion polling thread.
void signalHaveSensors ()
 call this to cause "system shutdown" -- clean halt of the simulator (not actually the host system)
bool haveSensors () const
 test to see if the shutdown flag has been set (non-blocking)
bool waitSensors ()
 blocks until shutdown flag has been set

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

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
Configuration Parameters
SharedGlobals::MotionSimConfig motion

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

Classes

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

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 130 of file SharedGlobals.h.


Constructor & Destructor Documentation

SharedGlobals (  )  [inline]

constructor

Definition at line 16 of file SharedGlobals.h.

~SharedGlobals (  )  [inline]

destructor

Definition at line 27 of file SharedGlobals.h.


Member Function Documentation

void signalHaveSensors (  )  [inline]

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

Definition at line 41 of file SharedGlobals.h.

Referenced by Main::processEvent(), and signalShutdown().

bool haveSensors (  )  const [inline]

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

Definition at line 45 of file SharedGlobals.h.

Referenced by signalShutdown().

bool waitSensors (  )  [inline]

blocks until shutdown flag has been set

Definition at line 49 of file SharedGlobals.h.

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

void signalShutdown (  )  [inline]

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

Definition at line 61 of file SharedGlobals.h.

Referenced by Simulator::cmdQuit(), sim::handle_exit(), sim::handle_signal(), Simulator::run(), and Simulator::Simulator().

bool isShutdown (  )  const [inline]

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

Definition at line 67 of file SharedGlobals.h.

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

bool waitShutdown (  )  [inline]

blocks until shutdown flag has been set

Definition at line 71 of file SharedGlobals.h.

Referenced by Process::run().

bool hadFault (  )  const [inline]

access to semgr, returns SemaphoreManager::hadFault()

Definition at line 76 of file SharedGlobals.h.

Referenced by sim::handle_exit(), and sim::handle_signal().

void faultShutdown (  )  [inline]

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 79 of file SharedGlobals.h.

Referenced by sim::handle_exit(), and sim::handle_signal().

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().

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().

void setAutoPauseTime ( unsigned int  t  )  [inline]

sets autoPauseTime

Definition at line 118 of file SharedGlobals.h.

Referenced by Simulator::incrementTime(), and Simulator::resetSpeedMode().

unsigned int getAutoPauseTime (  )  const [inline]

returns autoPauseTime

Definition at line 120 of file SharedGlobals.h.

Referenced by Simulator::incrementTime().

bool setNextTimer ( unsigned int  t  )  [inline]

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

Definition at line 207 of file SharedGlobals.h.

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

unsigned int getNextTimer (  )  [inline]

void setNextMotion ( unsigned int  t  )  [inline]

unsigned int getNextMotion (  )  [inline]

void setNextSensorUpdate ( unsigned int  t  )  [inline]

sets nextSensorUpdate

Definition at line 213 of file SharedGlobals.h.

unsigned int getNextSensorUpdate (  )  [inline]

gets nextSensorUpdate

Definition at line 214 of file SharedGlobals.h.

void resetBootTime (  )  [inline]

Definition at line 216 of file SharedGlobals.h.

Referenced by Simulator::Simulator().

unsigned int get_real_time ( double  scale  )  const [inline, protected]

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

Definition at line 220 of file SharedGlobals.h.

Referenced by get_time().


Member Data Documentation

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 38 of file SharedGlobals.h.

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

unsigned int simulatorTime

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

Definition at line 100 of file SharedGlobals.h.

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

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 115 of file SharedGlobals.h.

Referenced by TimerExecThread::calcSleepTime(), Motion::DoStart(), Motion::DoStop(), get_time(), getTimeScale(), Main::gotTimer(), Motion::gotWakeup(), Simulator::incrementTime(), MotionExecThread::interrupted(), TimerExecThread::launched(), MotionExecThread::launched(), Simulator::messagesRead(), Simulator::plistCollectionEntriesChanged(), Simulator::plistCollectionEntryAdded(), Simulator::plistValueChanged(), TimerExecThread::reset(), MotionExecThread::reset(), resetBootTime(), Simulator::resetSpeedMode(), Simulator::run(), sim::sim(), Simulator::Simulator(), and Simulator::~Simulator().

const unsigned int NUM_RUNLEVELS = DESTRUCTED+1 [static]

symbolic access to the total number of runlevel stages

Definition at line 139 of file SharedGlobals.h.

Referenced by SharedGlobals().

const char *const runlevel_names [static]

Initial value:

 {
  "CREATED",
  "CONSTRUCTING",
  "STARTING",
  "RUNNING",
  "STOPPING",
  "DESTRUCTING",
  "DESTRUCTED",
  ""
}
string versions of runlevel_t for runtime user-feedback

Definition at line 142 of file SharedGlobals.h.

Referenced by sim::run(), and sim::wait_runlevel().

unsigned int level_count[NUM_RUNLEVELS]

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

Definition at line 145 of file SharedGlobals.h.

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

allows mutually exclusive access to the fields of SharedObject

Definition at line 196 of file SharedGlobals.h.

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

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

Definition at line 199 of file SharedGlobals.h.

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

const unsigned int MAX_PROCESS_NAME_LEN = 32 [static]

maximum storage size of strings in processNames

Definition at line 202 of file SharedGlobals.h.

Referenced by Process::Process().

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

Definition at line 205 of file SharedGlobals.h.

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

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 225 of file SharedGlobals.h.

Referenced by getNextTimer(), and setNextTimer().

unsigned int nextMotion [protected]

updated by Motion process after each motion update

Definition at line 228 of file SharedGlobals.h.

Referenced by getNextMotion(), and setNextMotion().

unsigned int nextSensorUpdate [protected]

updated by Main process after each sensor update

Definition at line 231 of file SharedGlobals.h.

Referenced by getNextSensorUpdate(), and setNextSensorUpdate().

TimeET bootTime [protected]

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

Definition at line 234 of file SharedGlobals.h.

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

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 237 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 240 of file SharedGlobals.h.

Referenced by get_time().

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 243 of file SharedGlobals.h.

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

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

Definition at line 246 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 247 of file SharedGlobals.h.

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


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

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:01:23 2007 by Doxygen 1.5.4