Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WorldState Class Reference

#include <WorldState.h>

List of all members.


Detailed Description

The state of the robot and its environment.

Contains sensor readings, current joint positions, etc. Notable members are:

  • outputs - joint positions and current LED values
  • buttons - current button values
  • sensors - values from other sensors (IR, acceleration, temperature, power levels)
  • pids - current PID settings for each joint (more specifically, each PID-controlled joint)
  • pidduties - how hard each of the PID joints is working to get to its target value

Generally you will use enumerated values from a robot-specific namespace to index into these arrays. Each of those members' documentation specifies where to find the list of indices to use with them.

This is a shared memory region between Main, Motion, and possibly others in the future. Be very careful about including structures that use pointers in this class... they will only be valid from the OObject that created them, others may cause a crash if they try to access them.

WorldState takes power and sensor updates from the system and maintains the last known values in its member fields. It throws events when some of these values change, listed in the SensorSourceID, PowerSourceID namespaces, and the ButtonOffset_t enumeration for your robot model's info namespace. (e.g. ERS7Info::ButtonOffset_t)

Status events for buttons only generated if the WorldState::alwaysGenerateStatus flag is turned on. Otherwise, by default, they are only generated when a value has changed. (i.e. when the pressure sensitive buttons get a new pressure reading)

Definition at line 157 of file WorldState.h.


Public Member Functions

 WorldState ()
 constructor - sets everything to zeros
void read (const PostureEngine &pose, WorldState *lastState, EventRouter *er)
 will process the posture's output positions as a new sensor reading

Static Public Member Functions

static WorldStategetCurrent ()
 returns the current WorldState instance for the running process, needed if your code may be in a shared memory region; otherwise you can directly access state

Public Attributes

bool alwaysGenerateStatus
 controls whether status events are generated for the boolean buttons
float outputs [NumOutputs]
 last sensed positions of joints, last commanded value of LEDs; indexes (aka offsets) are defined in the target model's namespace (e.g. "Output Offsets" section of ERS7Info)
float buttons [NumButtons]
 magnitude is pressure for some, 0/1 for others; indexes are defined in the ButtonOffset_t of the target model's namespace (e.g. ERS7Info::ButtonOffset_t)
float sensors [NumSensors]
 IR, Accel, Thermo, Power stuff; indexes are defined in SensorOffset_t of the target model's namespace (e.g. ERS7Info::SensorOffset_t).
float pids [NumPIDJoints][3]
 current PID settings (same ordering as the outputs), not sensed -- updated by MotionManager whenever it sends a PID setting to the system; note this is only valid for PID joints, has NumPIDJoint entries (as opposed to NumOutputs)
float pidduties [NumPIDJoints]
 duty cycles - -1 means the motor is trying to move full power in negative direction, 1 means full power in positive direction, in practice, these values stay rather small - 0.15 is significant force. (same ordering as the outputs); note this is only valid for PID joints, has NumPIDJoint entries (as opposed to NumOutputs)
float vel_x
 the current, egocentric rate of forward locomotion, mm/second
float vel_y
 the current, egocentric rate of sideways (leftward is positive) locomotion, mm/second
float vel_a
 the current, egocentric rate of rotational (counterclockwise is positive) locomotion, radian/second
unsigned int vel_time
 the time at which we began moving along the current velocity vector
unsigned int robotStatus
 bitmask, see OPENR/OPower.h
unsigned int batteryStatus
 bitmask, see OPENR/OPower.h
unsigned int powerFlags [PowerSrcID::NumPowerSIDs]
 bitmasks of similarly-grouped items from previous two masks, corresponds to the PowerSrcID::PowerSourceID_t's
unsigned int button_times [NumButtons]
 value is time of current press, 0 if not down
unsigned int lastSensorUpdateTime
 primarily so calcDers can determine the time difference between updates, but others might want to know this too...
unsigned int frameNumber
 the serial number of the currently available frame
unsigned int framesProcessed
 the number of sensor updates which have been processed

Static Public Attributes

static const double g = 9.80665
 the gravitational acceleration of objects on earth
static const double IROORDist = 900.0
 If IR returns this, we're out of range.

Protected Member Functions

void chkEvent (std::vector< EventBase > &evtBuf, unsigned int off, float newval, const char *name)
 Tests to see if the button status has changed and post events as needed.
void chkEvent (std::vector< EventBase > &evtBuf, WorldState *lastState)
 Tests to see if any button statuses have changed and post events as needed, bases comparison between already filled-in WorldStates.
void applyCalibration ()
 Apply calibration to the sensors and joint positions (reversing motion calibration parameters).
void chkPowerEvent (unsigned int sid, unsigned int cur, unsigned int mask, const char *name, std::string actname[PowerSrcID::NumPowerSIDs], std::string dename[PowerSrcID::NumPowerSIDs], unsigned int summask[PowerSrcID::NumPowerSIDs])
 sets the names of the flags that will be generating events
void calcDers (double next, double &cur, double &vel, double &acc, double invtimediff)
 given the next value, calculates and stores the next current, the velocity, and the acceleration

Protected Attributes

unsigned int curtime
 set by read(OSensorFrameVectorData& sensor, EventRouter* er) for chkEvent() so each call doesn't have to

Private Member Functions

 WorldState (const WorldState &)
 this shouldn't be called...
WorldStateoperator= (const WorldState &)
 this shouldn't be called...

Constructor & Destructor Documentation

WorldState::WorldState (  ) 

constructor - sets everything to zeros

Definition at line 38 of file WorldState.cc.

WorldState::WorldState ( const WorldState  )  [private]

this shouldn't be called...


Member Function Documentation

void WorldState::read ( const PostureEngine pose,
WorldState lastState,
EventRouter er 
)

will process the posture's output positions as a new sensor reading

This version of read() doesn't post the sensor update event -- the caller should do that (this variant is used by the simulator, different parts fill in different sections, the last one should trigger the event)

This function assumes that the pose (and any associated sensor readings) are for the current model robot, and that no calibration has already been applied (so the values must be calibrated)

Definition at line 456 of file WorldState.cc.

static WorldState* WorldState::getCurrent (  )  [inline, static]

returns the current WorldState instance for the running process, needed if your code may be in a shared memory region; otherwise you can directly access state

Generally you can access state directly, but if your code is running as a member of an object in a shared memory region, this handles the shared object context switching problem on Aperios, and simply returns state on non-Aperios.

Definition at line 208 of file WorldState.h.

Referenced by MotionSequenceEngine::resume(), MotionSequenceEngine::setNextFrameTime(), MotionSequenceEngine::setTime(), PostureEngine::takeSnapshot(), and EmergencyStopMC::trigger().

void WorldState::chkEvent ( std::vector< EventBase > &  evtBuf,
unsigned int  off,
float  newval,
const char *  name 
) [protected]

Tests to see if the button status has changed and post events as needed.

Definition at line 549 of file WorldState.cc.

Referenced by read().

void WorldState::chkEvent ( std::vector< EventBase > &  evtBuf,
WorldState lastState 
) [protected]

Tests to see if any button statuses have changed and post events as needed, bases comparison between already filled-in WorldStates.

Definition at line 572 of file WorldState.cc.

void WorldState::applyCalibration (  )  [protected]

Apply calibration to the sensors and joint positions (reversing motion calibration parameters).

Definition at line 594 of file WorldState.cc.

Referenced by read().

void WorldState::chkPowerEvent ( unsigned int  sid,
unsigned int  cur,
unsigned int  mask,
const char *  name,
std::string  actname[PowerSrcID::NumPowerSIDs],
std::string  dename[PowerSrcID::NumPowerSIDs],
unsigned int  summask[PowerSrcID::NumPowerSIDs] 
) [inline, protected]

sets the names of the flags that will be generating events

note that this function does not actually do the event posting, unlike chkEvent()

Definition at line 225 of file WorldState.h.

void WorldState::calcDers ( double  next,
double &  cur,
double &  vel,
double &  acc,
double  invtimediff 
) [inline, protected]

given the next value, calculates and stores the next current, the velocity, and the acceleration

Parameters:
next the new value that's about to be set
cur the previous value
vel the previous 1st derivative
acc the previous 2nd derivative
invtimediff $1/(curtime-prevtime)$ in seconds

Definition at line 242 of file WorldState.h.

WorldState& WorldState::operator= ( const WorldState  )  [private]

this shouldn't be called...


Member Data Documentation

controls whether status events are generated for the boolean buttons

Definition at line 162 of file WorldState.h.

Referenced by chkEvent(), and read().

float WorldState::outputs[NumOutputs]

last sensed positions of joints, last commanded value of LEDs; indexes (aka offsets) are defined in the target model's namespace (e.g. "Output Offsets" section of ERS7Info)

Definition at line 164 of file WorldState.h.

Referenced by WorldStatePool::read(), read(), MotionSequenceEngine::resume(), MotionSequenceEngine::setNextFrameTime(), MotionSequenceEngine::setTime(), PostureEngine::takeSnapshot(), and WorldState().

float WorldState::buttons[NumButtons]

magnitude is pressure for some, 0/1 for others; indexes are defined in the ButtonOffset_t of the target model's namespace (e.g. ERS7Info::ButtonOffset_t)

Definition at line 165 of file WorldState.h.

Referenced by chkEvent(), PostureEngine::getBinSize(), PostureEngine::loadLine(), read(), PostureEngine::saveBuffer(), and WorldState().

float WorldState::sensors[NumSensors]

IR, Accel, Thermo, Power stuff; indexes are defined in SensorOffset_t of the target model's namespace (e.g. ERS7Info::SensorOffset_t).

Definition at line 166 of file WorldState.h.

Referenced by PostureEngine::getBinSize(), PostureEngine::loadLine(), read(), PostureEngine::saveBuffer(), and WorldState().

float WorldState::pids[NumPIDJoints][3]

current PID settings (same ordering as the outputs), not sensed -- updated by MotionManager whenever it sends a PID setting to the system; note this is only valid for PID joints, has NumPIDJoint entries (as opposed to NumOutputs)

Definition at line 167 of file WorldState.h.

Referenced by WorldStatePool::isZeroPID(), and WorldState().

float WorldState::pidduties[NumPIDJoints]

duty cycles - -1 means the motor is trying to move full power in negative direction, 1 means full power in positive direction, in practice, these values stay rather small - 0.15 is significant force. (same ordering as the outputs); note this is only valid for PID joints, has NumPIDJoint entries (as opposed to NumOutputs)

Definition at line 168 of file WorldState.h.

Referenced by PostureEngine::getBinSize(), PostureEngine::loadLine(), read(), PostureEngine::saveBuffer(), and WorldState().

the current, egocentric rate of forward locomotion, mm/second

Definition at line 170 of file WorldState.h.

the current, egocentric rate of sideways (leftward is positive) locomotion, mm/second

Definition at line 171 of file WorldState.h.

the current, egocentric rate of rotational (counterclockwise is positive) locomotion, radian/second

Definition at line 172 of file WorldState.h.

unsigned int WorldState::vel_time

the time at which we began moving along the current velocity vector

Definition at line 173 of file WorldState.h.

bitmask, see OPENR/OPower.h

Definition at line 175 of file WorldState.h.

Referenced by read().

bitmask, see OPENR/OPower.h

Definition at line 176 of file WorldState.h.

Referenced by read().

unsigned int WorldState::powerFlags[PowerSrcID::NumPowerSIDs]

bitmasks of similarly-grouped items from previous two masks, corresponds to the PowerSrcID::PowerSourceID_t's

Definition at line 177 of file WorldState.h.

Referenced by chkPowerEvent(), read(), and WorldState().

unsigned int WorldState::button_times[NumButtons]

value is time of current press, 0 if not down

Definition at line 179 of file WorldState.h.

Referenced by chkEvent(), read(), EmergencyStopMC::trigger(), and WorldState().

primarily so calcDers can determine the time difference between updates, but others might want to know this too...

Definition at line 181 of file WorldState.h.

Referenced by PostureEngine::getBinSize(), PostureEngine::loadLine(), read(), and PostureEngine::saveBuffer().

the serial number of the currently available frame

Definition at line 182 of file WorldState.h.

Referenced by PostureEngine::getBinSize(), PostureEngine::loadLine(), WorldStatePool::read(), read(), and PostureEngine::saveBuffer().

the number of sensor updates which have been processed

Definition at line 183 of file WorldState.h.

Referenced by read().

const double WorldState::g = 9.80665 [static]

the gravitational acceleration of objects on earth

Definition at line 185 of file WorldState.h.

Referenced by AutoGetupBehavior::processEvent().

const double WorldState::IROORDist = 900.0 [static]

If IR returns this, we're out of range.

Definition at line 186 of file WorldState.h.

unsigned int WorldState::curtime [protected]

set by read(OSensorFrameVectorData& sensor, EventRouter* er) for chkEvent() so each call doesn't have to

Definition at line 212 of file WorldState.h.

Referenced by chkEvent(), and read().


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

Tekkotsu v4.0
Generated Thu Nov 22 00:58:49 2007 by Doxygen 1.5.4