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 (OSensorFrameVectorData &sensor, WorldState *lastState, EventRouter *er) |
| | will process a sensor reading as given by OPEN-R
|
| void | read (const OPowerStatus &power, EventRouter *er) |
| | will process a power status update as given by OPEN-R
|
Static Public Member Functions |
| static WorldState * | getCurrent () |
| | 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
|
|
static void | setWorldStateLookup (WorldState *curMap[ProcessID::NumProcesses]) |
| | sets the lookup table (held in a shared region, WorldStatePool::stateMap) used by getCurrent under Aperios
|
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 [PowerSourceID::NumPowerSIDs] |
| | bitmasks of similarly-grouped items from previous two masks, corresponds to the PowerSourceID::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
|
| unsigned int | robotDesign |
| | bitmask corresponding to OPENR::GetRobotDesign()
|
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.
|
|
static const unsigned int | ERS210Mask = 1<<0 |
| | use this to test for ERS-210 features
|
|
static const unsigned int | ERS220Mask = 1<<1 |
| | use this to test for ERS-220 features
|
|
static const unsigned int | ERS2xxMask = ERS210Mask | ERS220Mask |
| | use this to test for ERS-2xx features
|
|
static const unsigned int | ERS7Mask = 1<<2 |
| | use this to test for ERS-7 features
|
|
static const unsigned int | LynxArm6Mask = 1<<3 |
| | use this to test for ERS-7 features
|
|
static const unsigned int | QwerkMask = 1<<4 |
| | use this to test for ERS-7 features
|
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 | chkPowerEvent (unsigned int sid, unsigned int cur, unsigned int mask, const char *name, std::string actname[PowerSourceID::NumPowerSIDs], std::string dename[PowerSourceID::NumPowerSIDs], unsigned int summask[PowerSourceID::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
|
Static Protected Attributes |
|
static WorldState ** | stateLookupMap = NULL |
| | array used by getCurrent()/setCurrent() to store the state in use by each process -- should be initialized by setWorldStateLookup() to point into a shared memory region
|
Private Member Functions |
|
| WorldState (const WorldState &) |
| | this shouldn't be called...
|
|
WorldState & | operator= (const WorldState &) |
| | this shouldn't be called...
|
Member Function Documentation
| 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 | in seconds |
Definition at line 257 of file WorldState.h.
| void WorldState::chkPowerEvent |
( |
unsigned int |
sid, |
|
|
unsigned int |
cur, |
|
|
unsigned int |
mask, |
|
|
const char * |
name, |
|
|
std::string |
actname[PowerSourceID::NumPowerSIDs], |
|
|
std::string |
dename[PowerSourceID::NumPowerSIDs], |
|
|
unsigned int |
summask[PowerSourceID::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 240 of file WorldState.h.
Referenced by read().
| 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 195 of file WorldState.h.
Referenced by LedEngine::displayNumber(), MotionCommand::StateRedirect::operator->(), MotionSequenceEngine::resume(), MotionSequenceEngine::setNextFrameTime(), LedEngine::setOneOfTwo(), MotionSequenceEngine::setTime(), PostureEngine::takeSnapshot(), and EmergencyStopMC::trigger().
| void WorldState::read |
( |
const OPowerStatus & |
power, |
|
|
EventRouter * |
er | |
|
) |
| | |
will process a power status update as given by OPEN-R
This will cause events to be posted
Definition at line 400 of file WorldState.cc.
will process a sensor reading as given by OPEN-R
This will cause events to be posted
process changes
process changes
process changes
Definition at line 100 of file WorldState.cc.
Member Data Documentation
bitmask corresponding to OPENR::GetRobotDesign()
This allows you to efficiently test different combinations, like any 2x0 model vs. any 7 model or any 3xx model (when/if the 3xx's are supported).
Testing this will give more accurate feedback as to whether features exist than checking RobotInfo values - to achieve dual booting, RobotInfo may, for instance, tell you there are two ears, but if you're running on a 220 the value you set them to will be ignored
Definition at line 221 of file WorldState.h.
Referenced by LedEngine::displayNumber(), Controller::init(), ValueEditControl< T >::pause(), VisualTargetCloseTrans::processEvent(), ValueEditControl< T >::processEvent(), read(), BatteryMonitorBehavior::setFlipper(), LedEngine::setOneOfTwo(), EmergencyStopMC::trigger(), MotionManager::updateWorldState(), and WorldState().
The documentation for this class was generated from the following files:
|