Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WorldState Class Reference

The state of the robot and its environment. More...

#include <WorldState.h>


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 127 of file WorldState.h.

List of all members.

Public Member Functions

 WorldState ()
 constructor - sets everything to zeros
void read (const SensorState &sensor, bool sendEvents)
 processes incoming sensor data, generating events for buttons

Static Public Member Functions

static const 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 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::applyCalibration (  )  [protected]

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

Definition at line 462 of file WorldState.cc.

void WorldState::calcDers ( double  next,
double &  cur,
double &  vel,
double &  acc,
double  invtimediff 
) [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 206 of file WorldState.h.

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 439 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] 
) [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 189 of file WorldState.h.

const WorldState * WorldState::getCurrent (  )  [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 248 of file WorldState.h.

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

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

this shouldn't be called...

void WorldState::read ( const SensorState &  sensor,
bool  sendEvents 
)

processes incoming sensor data, generating events for buttons

Definition at line 379 of file WorldState.cc.


Member Data Documentation

controls whether status events are generated for the boolean buttons

Definition at line 132 of file WorldState.h.

Referenced by chkEvent().

bitmask, see OPENR/OPower.h

Definition at line 146 of file WorldState.h.

unsigned int WorldState::button_times[NumButtons]

value is time of current press, 0 if not down

Definition at line 149 of file WorldState.h.

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

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 135 of file WorldState.h.

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

unsigned int WorldState::curtime [protected]

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

Definition at line 178 of file WorldState.h.

Referenced by chkEvent(), and read().

the serial number of the currently available frame

Definition at line 152 of file WorldState.h.

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

the number of sensor updates which have been processed

Definition at line 153 of file WorldState.h.

Referenced by read().

const double WorldState::g = 9.80665 [static]

the gravitational acceleration of objects on earth

Definition at line 155 of file WorldState.h.

const double WorldState::IROORDist = 900.0 [static]

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

Definition at line 156 of file WorldState.h.

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

Definition at line 151 of file WorldState.h.

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

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 134 of file WorldState.h.

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

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 138 of file WorldState.h.

Referenced by PostureEngine::getBinSize(), 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 137 of file WorldState.h.

Referenced by WorldState().

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 147 of file WorldState.h.

Referenced by chkPowerEvent(), and WorldState().

bitmask, see OPENR/OPower.h

Definition at line 145 of file WorldState.h.

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 136 of file WorldState.h.

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

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

Definition at line 142 of file WorldState.h.

unsigned int WorldState::vel_time

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

Definition at line 143 of file WorldState.h.

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

Definition at line 140 of file WorldState.h.

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

Definition at line 141 of file WorldState.h.


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:18 2016 by Doxygen 1.6.3