00001 #ifdef PLATFORM_APERIOS
00002 #include <OPENR/core_macro.h>
00003 #include <OPENR/ObjcommTypes.h>
00004 #include <OPENR/OPENR.h>
00005 #include <OPENR/OPENRAPI.h>
00006 #include <OPENR/OPENRMessages.h>
00007 #include <OPENR/OPower.h>
00008 #endif
00009
00010 #include "WorldState.h"
00011 #include "Shared/get_time.h"
00012 #include "Events/EventRouter.h"
00013 #include "ERS210Info.h"
00014 #include "ERS220Info.h"
00015 #include "ERS7Info.h"
00016
00017 #define GETD(cpc) (((float)sensor.GetData(cpc)->frame[lastFrame].value) / 1.0E6f)
00018 #define GETB(cpc) ((bool)sensor.GetData(cpc)->frame[lastFrame].value)
00019 #define GETSENSOR(cpc) ((float)sensor.GetData(cpc)->frame[lastFrame].value)
00020 #define GETSIG(cpc) ((word)sensor.GetData(cpc)->frame[lastFrame].signal)
00021 #define GETDUTY(cpc) ((float)((OJointValue*)&sensor.GetData(cpc)->frame[lastFrame])->pwmDuty/512.0f)
00022
00023 const double WorldState::g=9.80665;
00024 const double WorldState::IROORDist = 900.0;
00025
00026 WorldState * state=NULL;
00027
00028 WorldState::WorldState()
00029 : alwaysGenerateStatus(false), vel_x(0), vel_y(0), vel_a(0), vel_time(0),
00030 robotStatus(0), batteryStatus(0),
00031 lastSensorUpdateTime(0), mainProfile(), motionProfile(),
00032 robotDesign(0), curtime(get_time())
00033 {
00034 for(unsigned int i=0; i< NumOutputs; i++)
00035 outputs[i]=0;
00036 for(unsigned int i=0; i< NumButtons; i++)
00037 buttons[i]=0;
00038 for(unsigned int i=0; i< NumSensors; i++)
00039 sensors[i]=0;
00040 for(unsigned int i=0; i< NumPIDJoints; i++)
00041 for(unsigned int j=0; j<3; j++)
00042 pids[i][j]=0;
00043 for(unsigned int i=0; i< NumPIDJoints; i++)
00044 pidduties[i]=0;
00045 memset(powerFlags,0,sizeof(unsigned int)*PowerSourceID::NumPowerSIDs);
00046 memset(button_times,0,sizeof(unsigned int)*NumButtons);
00047
00048
00049 char robotDesignStr[orobotdesignNAME_MAX];
00050 memset(robotDesignStr, 0, sizeof(robotDesignStr));
00051 if (OPENR::GetRobotDesign(robotDesignStr) != oSUCCESS) {
00052 cout << "OPENR::GetRobotDesign() failed." << endl;
00053 } else {
00054 if(strcmp(robotDesignStr,"ERS-210")==0)
00055 robotDesign=ERS210Mask;
00056 else if(strcmp(robotDesignStr,"ERS-220")==0)
00057 robotDesign=ERS220Mask;
00058 else if(strcmp(robotDesignStr,"ERS-7")==0)
00059 robotDesign=ERS7Mask;
00060 else {
00061 cout << "ERROR: Unrecognized model: "<<robotDesignStr<<"\nTrying ERS-210..."<<endl;
00062 robotDesign=ERS210Mask;
00063 }
00064 }
00065 }
00066
00067 #ifdef PLATFORM_APERIOS
00068
00069
00070
00071 void WorldState::read(OSensorFrameVectorData& sensor, EventRouter* er) {
00072 curtime=get_time();
00073
00074 unsigned int lastFrame=sensor.GetInfo(0)->numFrames-1;
00075
00076 if(robotDesign&ERS210Mask) {
00077 outputs[LFrLegOffset + RotatorOffset ] = GETD(ERS210Info::CPCJointLFRotator);
00078 outputs[LFrLegOffset + ElevatorOffset ] = GETD(ERS210Info::CPCJointLFElevator);
00079 outputs[LFrLegOffset + KneeOffset ] = GETD(ERS210Info::CPCJointLFKnee);
00080 pidduties[LFrLegOffset + RotatorOffset ] = GETDUTY(ERS210Info::CPCJointLFRotator);
00081 pidduties[LFrLegOffset + ElevatorOffset] = GETDUTY(ERS210Info::CPCJointLFElevator);
00082 pidduties[LFrLegOffset + KneeOffset ] = GETDUTY(ERS210Info::CPCJointLFKnee);
00083
00084 outputs[RFrLegOffset + RotatorOffset ] = GETD(ERS210Info::CPCJointRFRotator);
00085 outputs[RFrLegOffset + ElevatorOffset ] = GETD(ERS210Info::CPCJointRFElevator);
00086 outputs[RFrLegOffset + KneeOffset ] = GETD(ERS210Info::CPCJointRFKnee);
00087 pidduties[RFrLegOffset + RotatorOffset ] = GETDUTY(ERS210Info::CPCJointRFRotator);
00088 pidduties[RFrLegOffset + ElevatorOffset] = GETDUTY(ERS210Info::CPCJointRFElevator);
00089 pidduties[RFrLegOffset + KneeOffset ] = GETDUTY(ERS210Info::CPCJointRFKnee);
00090
00091 outputs[LBkLegOffset + RotatorOffset ] = GETD(ERS210Info::CPCJointLHRotator);
00092 outputs[LBkLegOffset + ElevatorOffset ] = GETD(ERS210Info::CPCJointLHElevator);
00093 outputs[LBkLegOffset + KneeOffset ] = GETD(ERS210Info::CPCJointLHKnee);
00094 pidduties[LBkLegOffset + RotatorOffset ] = GETDUTY(ERS210Info::CPCJointLHRotator);
00095 pidduties[LBkLegOffset + ElevatorOffset] = GETDUTY(ERS210Info::CPCJointLHElevator);
00096 pidduties[LBkLegOffset + KneeOffset ] = GETDUTY(ERS210Info::CPCJointLHKnee);
00097
00098 outputs[RBkLegOffset + RotatorOffset ] = GETD(ERS210Info::CPCJointRHRotator);
00099 outputs[RBkLegOffset + ElevatorOffset ] = GETD(ERS210Info::CPCJointRHElevator);
00100 outputs[RBkLegOffset + KneeOffset ] = GETD(ERS210Info::CPCJointRHKnee);
00101 pidduties[RBkLegOffset + RotatorOffset ] = GETDUTY(ERS210Info::CPCJointRHRotator);
00102 pidduties[RBkLegOffset + ElevatorOffset] = GETDUTY(ERS210Info::CPCJointRHElevator);
00103 pidduties[RBkLegOffset + KneeOffset ] = GETDUTY(ERS210Info::CPCJointRHKnee);
00104
00105
00106 outputs[HeadOffset+TiltOffset] = GETD(ERS210Info::CPCJointNeckTilt);
00107 outputs[HeadOffset+PanOffset ] = GETD(ERS210Info::CPCJointNeckPan);
00108 outputs[HeadOffset+RollOffset] = GETD(ERS210Info::CPCJointNeckRoll);
00109 pidduties[HeadOffset+TiltOffset] = GETDUTY(ERS210Info::CPCJointNeckTilt);
00110 pidduties[HeadOffset+PanOffset ] = GETDUTY(ERS210Info::CPCJointNeckPan);
00111 pidduties[HeadOffset+RollOffset] = GETDUTY(ERS210Info::CPCJointNeckRoll);
00112
00113 outputs[ERS210Info::TailOffset+TiltOffset] = GETD(ERS210Info::CPCJointTailTilt);
00114 outputs[ERS210Info::TailOffset+PanOffset] = GETD(ERS210Info::CPCJointTailPan);
00115 pidduties[ERS210Info::TailOffset+TiltOffset] = GETDUTY(ERS210Info::CPCJointTailTilt);
00116 pidduties[ERS210Info::TailOffset+PanOffset] = GETDUTY(ERS210Info::CPCJointTailPan);
00117
00118 outputs[ERS210Info::MouthOffset] = GETD(ERS210Info::CPCJointMouth);
00119 pidduties[ERS210Info::MouthOffset] = GETDUTY(ERS210Info::CPCJointMouth);
00120
00121
00122 chkEvent(er,LFrPawOffset,GETB(ERS210Info::CPCSensorLFPaw),"LFrPaw");
00123 chkEvent(er,RFrPawOffset,GETB(ERS210Info::CPCSensorRFPaw),"RFrPaw");
00124 chkEvent(er,LBkPawOffset,GETB(ERS210Info::CPCSensorLHPaw),"LBkPaw");
00125 chkEvent(er,RBkPawOffset,GETB(ERS210Info::CPCSensorRHPaw),"RBkPaw");
00126
00127
00128 chkEvent(er,ERS210Info::ChinButOffset, GETB(ERS210Info::CPCSensorChinSwitch),"ChinBut");
00129 chkEvent(er,ERS210Info::BackButOffset, GETB(ERS210Info::CPCSensorBackSwitch),"BackBut");
00130 chkEvent(er,ERS210Info::HeadFrButOffset,GETD(ERS210Info::CPCSensorHeadFrontPressure),"HeadFrBut");
00131 chkEvent(er,ERS210Info::HeadBkButOffset,GETD(ERS210Info::CPCSensorHeadBackPressure),"HeadBkBut");
00132
00133
00134 sensors[ERS210Info::IRDistOffset]=GETSENSOR(ERS210Info::CPCSensorPSD) / 1000.0f;
00135
00136
00137 sensors[BAccelOffset] = GETD(ERS210Info::CPCSensorAccelFB);
00138 sensors[LAccelOffset] = GETD(ERS210Info::CPCSensorAccelLR);
00139 sensors[DAccelOffset] = GETD(ERS210Info::CPCSensorAccelUD);
00140
00141 sensors[ERS210Info::ThermoOffset] = GETD(ERS210Info::CPCSensorThermoSensor);
00142 }
00143
00144
00145 if(robotDesign&ERS220Mask) {
00146 outputs[LFrLegOffset + RotatorOffset ] = GETD(ERS220Info::CPCJointLFRotator);
00147 outputs[LFrLegOffset + ElevatorOffset ] = GETD(ERS220Info::CPCJointLFElevator);
00148 outputs[LFrLegOffset + KneeOffset ] = GETD(ERS220Info::CPCJointLFKnee);
00149 pidduties[LFrLegOffset + RotatorOffset ] = GETDUTY(ERS220Info::CPCJointLFRotator);
00150 pidduties[LFrLegOffset + ElevatorOffset] = GETDUTY(ERS220Info::CPCJointLFElevator);
00151 pidduties[LFrLegOffset + KneeOffset ] = GETDUTY(ERS220Info::CPCJointLFKnee);
00152
00153 outputs[RFrLegOffset + RotatorOffset ] = GETD(ERS220Info::CPCJointRFRotator);
00154 outputs[RFrLegOffset + ElevatorOffset ] = GETD(ERS220Info::CPCJointRFElevator);
00155 outputs[RFrLegOffset + KneeOffset ] = GETD(ERS220Info::CPCJointRFKnee);
00156 pidduties[RFrLegOffset + RotatorOffset ] = GETDUTY(ERS220Info::CPCJointRFRotator);
00157 pidduties[RFrLegOffset + ElevatorOffset] = GETDUTY(ERS220Info::CPCJointRFElevator);
00158 pidduties[RFrLegOffset + KneeOffset ] = GETDUTY(ERS220Info::CPCJointRFKnee);
00159
00160 outputs[LBkLegOffset + RotatorOffset ] = GETD(ERS220Info::CPCJointLHRotator);
00161 outputs[LBkLegOffset + ElevatorOffset ] = GETD(ERS220Info::CPCJointLHElevator);
00162 outputs[LBkLegOffset + KneeOffset ] = GETD(ERS220Info::CPCJointLHKnee);
00163 pidduties[LBkLegOffset + RotatorOffset ] = GETDUTY(ERS220Info::CPCJointLHRotator);
00164 pidduties[LBkLegOffset + ElevatorOffset] = GETDUTY(ERS220Info::CPCJointLHElevator);
00165 pidduties[LBkLegOffset + KneeOffset ] = GETDUTY(ERS220Info::CPCJointLHKnee);
00166
00167 outputs[RBkLegOffset + RotatorOffset ] = GETD(ERS220Info::CPCJointRHRotator);
00168 outputs[RBkLegOffset + ElevatorOffset ] = GETD(ERS220Info::CPCJointRHElevator);
00169 outputs[RBkLegOffset + KneeOffset ] = GETD(ERS220Info::CPCJointRHKnee);
00170 pidduties[RBkLegOffset + RotatorOffset ] = GETDUTY(ERS220Info::CPCJointRHRotator);
00171 pidduties[RBkLegOffset + ElevatorOffset] = GETDUTY(ERS220Info::CPCJointRHElevator);
00172 pidduties[RBkLegOffset + KneeOffset ] = GETDUTY(ERS220Info::CPCJointRHKnee);
00173
00174
00175 outputs[HeadOffset+TiltOffset] = GETD(ERS220Info::CPCJointNeckTilt);
00176 outputs[HeadOffset+PanOffset ] = GETD(ERS220Info::CPCJointNeckPan);
00177 outputs[HeadOffset+RollOffset] = GETD(ERS220Info::CPCJointNeckRoll);
00178 pidduties[HeadOffset+TiltOffset] = GETDUTY(ERS220Info::CPCJointNeckTilt);
00179 pidduties[HeadOffset+PanOffset ] = GETDUTY(ERS220Info::CPCJointNeckPan);
00180 pidduties[HeadOffset+RollOffset] = GETDUTY(ERS220Info::CPCJointNeckRoll);
00181
00182 chkEvent(er, ERS220Info::TailLeftButOffset, GETB(ERS220Info::CPCSensorTailLeftSwitch), "LBkBut");
00183 chkEvent(er, ERS220Info::TailCenterButOffset, GETB(ERS220Info::CPCSensorTailCenterSwitch),"CBkBut");
00184 chkEvent(er, ERS220Info::TailRightButOffset, GETB(ERS220Info::CPCSensorTailRightSwitch), "RBkBut");
00185
00186
00187 chkEvent(er,LFrPawOffset,GETB(ERS220Info::CPCSensorLFPaw),"LFrPaw");
00188 chkEvent(er,RFrPawOffset,GETB(ERS220Info::CPCSensorRFPaw),"RFrPaw");
00189 chkEvent(er,LBkPawOffset,GETB(ERS220Info::CPCSensorLHPaw),"LBkPaw");
00190 chkEvent(er,RBkPawOffset,GETB(ERS220Info::CPCSensorRHPaw),"RBkPaw");
00191
00192
00193 chkEvent(er,ERS220Info::ChinButOffset, GETB(ERS220Info::CPCSensorChinSwitch),"ChinBut");
00194 chkEvent(er,ERS220Info::BackButOffset, GETB(ERS220Info::CPCSensorBackSwitch),"BackBut");
00195 chkEvent(er,ERS220Info::HeadFrButOffset,GETD(ERS220Info::CPCSensorHeadFrontPressure),"HeadFrBut");
00196 chkEvent(er,ERS220Info::HeadBkButOffset,GETD(ERS220Info::CPCSensorHeadBackPressure),"HeadBkBut");
00197
00198
00199 sensors[ERS220Info::IRDistOffset]=GETSENSOR(ERS220Info::CPCSensorPSD) / 1000.0f;
00200
00201
00202 sensors[BAccelOffset] = GETD(ERS220Info::CPCSensorAccelFB);
00203 sensors[LAccelOffset] = GETD(ERS220Info::CPCSensorAccelLR);
00204 sensors[DAccelOffset] = GETD(ERS220Info::CPCSensorAccelUD);
00205
00206 sensors[ERS220Info::ThermoOffset] = GETD(ERS220Info::CPCSensorThermoSensor);
00207 }
00208
00209
00210 if(robotDesign&ERS7Mask) {
00211 outputs[LFrLegOffset + RotatorOffset ] = GETD(ERS7Info::CPCJointLFRotator);
00212 outputs[LFrLegOffset + ElevatorOffset ] = GETD(ERS7Info::CPCJointLFElevator);
00213 outputs[LFrLegOffset + KneeOffset ] = GETD(ERS7Info::CPCJointLFKnee);
00214 pidduties[LFrLegOffset + RotatorOffset ] = GETDUTY(ERS7Info::CPCJointLFRotator);
00215 pidduties[LFrLegOffset + ElevatorOffset] = GETDUTY(ERS7Info::CPCJointLFElevator);
00216 pidduties[LFrLegOffset + KneeOffset ] = GETDUTY(ERS7Info::CPCJointLFKnee);
00217
00218 outputs[RFrLegOffset + RotatorOffset ] = GETD(ERS7Info::CPCJointRFRotator);
00219 outputs[RFrLegOffset + ElevatorOffset ] = GETD(ERS7Info::CPCJointRFElevator);
00220 outputs[RFrLegOffset + KneeOffset ] = GETD(ERS7Info::CPCJointRFKnee);
00221 pidduties[RFrLegOffset + RotatorOffset ] = GETDUTY(ERS7Info::CPCJointRFRotator);
00222 pidduties[RFrLegOffset + ElevatorOffset] = GETDUTY(ERS7Info::CPCJointRFElevator);
00223 pidduties[RFrLegOffset + KneeOffset ] = GETDUTY(ERS7Info::CPCJointRFKnee);
00224
00225 outputs[LBkLegOffset + RotatorOffset ] = GETD(ERS7Info::CPCJointLHRotator);
00226 outputs[LBkLegOffset + ElevatorOffset ] = GETD(ERS7Info::CPCJointLHElevator);
00227 outputs[LBkLegOffset + KneeOffset ] = GETD(ERS7Info::CPCJointLHKnee);
00228 pidduties[LBkLegOffset + RotatorOffset ] = GETDUTY(ERS7Info::CPCJointLHRotator);
00229 pidduties[LBkLegOffset + ElevatorOffset] = GETDUTY(ERS7Info::CPCJointLHElevator);
00230 pidduties[LBkLegOffset + KneeOffset ] = GETDUTY(ERS7Info::CPCJointLHKnee);
00231
00232 outputs[RBkLegOffset + RotatorOffset ] = GETD(ERS7Info::CPCJointRHRotator);
00233 outputs[RBkLegOffset + ElevatorOffset ] = GETD(ERS7Info::CPCJointRHElevator);
00234 outputs[RBkLegOffset + KneeOffset ] = GETD(ERS7Info::CPCJointRHKnee);
00235 pidduties[RBkLegOffset + RotatorOffset ] = GETDUTY(ERS7Info::CPCJointRHRotator);
00236 pidduties[RBkLegOffset + ElevatorOffset] = GETDUTY(ERS7Info::CPCJointRHElevator);
00237 pidduties[RBkLegOffset + KneeOffset ] = GETDUTY(ERS7Info::CPCJointRHKnee);
00238
00239
00240 outputs[HeadOffset+TiltOffset] = GETD(ERS7Info::CPCJointNeckTilt);
00241 outputs[HeadOffset+PanOffset ] = GETD(ERS7Info::CPCJointNeckPan);
00242 outputs[HeadOffset+RollOffset] = GETD(ERS7Info::CPCJointNeckNod);
00243 pidduties[HeadOffset+TiltOffset] = GETDUTY(ERS7Info::CPCJointNeckTilt);
00244 pidduties[HeadOffset+PanOffset ] = GETDUTY(ERS7Info::CPCJointNeckPan);
00245 pidduties[HeadOffset+RollOffset] = GETDUTY(ERS7Info::CPCJointNeckNod);
00246
00247 outputs[ERS7Info::TailOffset+TiltOffset] = GETD(ERS7Info::CPCJointTailTilt);
00248 outputs[ERS7Info::TailOffset+PanOffset] = GETD(ERS7Info::CPCJointTailPan);
00249 pidduties[ERS7Info::TailOffset+TiltOffset] = GETDUTY(ERS7Info::CPCJointTailTilt);
00250 pidduties[ERS7Info::TailOffset+PanOffset] = GETDUTY(ERS7Info::CPCJointTailPan);
00251
00252 outputs[ERS7Info::MouthOffset] = GETD(ERS7Info::CPCJointMouth);
00253 pidduties[ERS7Info::MouthOffset] = GETDUTY(ERS7Info::CPCJointMouth);
00254
00255
00256 chkEvent(er,LFrPawOffset,GETB(ERS7Info::CPCSwitchLFPaw),"LFrPaw");
00257 chkEvent(er,RFrPawOffset,GETB(ERS7Info::CPCSwitchRFPaw),"RFrPaw");
00258 chkEvent(er,LBkPawOffset,GETB(ERS7Info::CPCSwitchLHPaw),"LBkPaw");
00259 chkEvent(er,RBkPawOffset,GETB(ERS7Info::CPCSwitchRHPaw),"RBkPaw");
00260
00261
00262
00263 chkEvent(er, ERS7Info::ChinButOffset, GETSENSOR(ERS7Info::CPCSwitchChin), "ChinBut");
00264 chkEvent(er, ERS7Info::HeadButOffset, GETSENSOR(ERS7Info::CPCSensorHead)/120, "HeadBut");
00265 chkEvent(er, ERS7Info::FrontBackButOffset, GETSENSOR(ERS7Info::CPCSensorBackFront)/150, "BkFrBut");
00266 chkEvent(er, ERS7Info::MiddleBackButOffset, GETSENSOR(ERS7Info::CPCSensorBackMiddle)/150,"BkMdBut");
00267 chkEvent(er, ERS7Info::RearBackButOffset, GETSENSOR(ERS7Info::CPCSensorBackRear)/150, "BkRrBut");
00268 chkEvent(er, ERS7Info::WirelessSwOffset,GETSENSOR(ERS7Info::CPCSwitchWireless), "WirelessSw");
00269
00270
00271 sensors[ERS7Info::NearIRDistOffset] = GETSENSOR(ERS7Info::CPCSensorNearPSD) / 1000.0f;
00272 sensors[ERS7Info::FarIRDistOffset] = GETSENSOR(ERS7Info::CPCSensorFarPSD) / 1000.0f;
00273 sensors[ERS7Info::ChestIRDistOffset] = GETSENSOR(ERS7Info::CPCSensorChestPSD) / 1000.0f;
00274
00275
00276 sensors[BAccelOffset] = GETD(ERS7Info::CPCSensorAccelFB);
00277 sensors[LAccelOffset] = GETD(ERS7Info::CPCSensorAccelLR);
00278 sensors[DAccelOffset] = GETD(ERS7Info::CPCSensorAccelUD);
00279 }
00280
00281 unsigned int dif=curtime-lastSensorUpdateTime;
00282 lastSensorUpdateTime=curtime;
00283 er->postEvent(EventBase::sensorEGID,SensorSourceID::UpdatedSID,EventBase::statusETID,dif);
00284 }
00285
00286
00287 void WorldState::read(const OPowerStatus& power, EventRouter* er) {
00288 std::string actnames[PowerSourceID::NumPowerSIDs];
00289 std::string denames[PowerSourceID::NumPowerSIDs];
00290 unsigned int actmasks[PowerSourceID::NumPowerSIDs];
00291 memset(actmasks,0,sizeof(unsigned int)*PowerSourceID::NumPowerSIDs);
00292
00293
00294 chkPowerEvent(PowerSourceID::PauseSID, power.robotStatus,orsbPAUSE, "Pause",actnames,denames,actmasks);
00295 chkPowerEvent(PowerSourceID::MotorPowerSID, power.robotStatus,orsbMOTOR_POWER, "MotorPower",actnames,denames,actmasks);
00296 chkPowerEvent(PowerSourceID::VibrationSID, power.robotStatus,orsbVIBRATION_DETECT, "Vibration",actnames,denames,actmasks);
00297 chkPowerEvent(PowerSourceID::ExternalPortSID, power.robotStatus,orsbEX_PORT_CONNECTED, "ExternalPort",actnames,denames,actmasks);
00298 chkPowerEvent(PowerSourceID::StationConnectSID, power.robotStatus,orsbSTATION_CONNECTED, "StationConnect",actnames,denames,actmasks);
00299 chkPowerEvent(PowerSourceID::ExternalPowerSID, power.robotStatus,orsbEX_POWER_CONNECTED, "ExternalPower",actnames,denames,actmasks);
00300 chkPowerEvent(PowerSourceID::BatteryConnectSID, power.robotStatus,orsbBATTERY_CONNECTED, "BatteryConnect",actnames,denames,actmasks);
00301 chkPowerEvent(PowerSourceID::ChargingSID, power.robotStatus,orsbBATTERY_CHARGING, "BatteryCharging",actnames,denames,actmasks);
00302 chkPowerEvent(PowerSourceID::BatteryFullSID, power.robotStatus,orsbBATTERY_CAPACITY_FULL, "BatteryFull",actnames,denames,actmasks);
00303 chkPowerEvent(PowerSourceID::LowPowerWarnSID, power.robotStatus,orsbBATTERY_CAPACITY_LOW, "BatteryLow",actnames,denames,actmasks);
00304 chkPowerEvent(PowerSourceID::OverChargedSID, power.robotStatus,orsbBATTERY_OVER_CURRENT, "BatteryOverCurrent",actnames,denames,actmasks);
00305 chkPowerEvent(PowerSourceID::OverheatingSID, power.robotStatus,orsbBATTERY_OVER_TEMP_DISCHARGING,"BatteryOverTempDischarge",actnames,denames,actmasks);
00306 chkPowerEvent(PowerSourceID::OverheatingSID, power.robotStatus,orsbBATTERY_OVER_TEMP_CHARGING, "BatteryOverTempCharge",actnames,denames,actmasks);
00307 chkPowerEvent(PowerSourceID::ErrorSID, power.robotStatus,orsbBATTERY_ERROR_OF_CHARGING, "BatteryChargeError",actnames,denames,actmasks);
00308 chkPowerEvent(PowerSourceID::ErrorSID, power.robotStatus,orsbERROR_OF_PLUNGER, "PlungerError",actnames,denames,actmasks);
00309 chkPowerEvent(PowerSourceID::PowerGoodSID, power.robotStatus,orsbOPEN_R_POWER_GOOD, "PowerGood",actnames,denames,actmasks);
00310 chkPowerEvent(PowerSourceID::ErrorSID, power.robotStatus,orsbERROR_OF_FAN, "FanError",actnames,denames,actmasks);
00311 chkPowerEvent(PowerSourceID::DataFromStationSID,power.robotStatus,orsbDATA_STREAM_FROM_STATION, "DataFromStation",actnames,denames,actmasks);
00312 chkPowerEvent(PowerSourceID::RegisterUpdateSID, power.robotStatus,orsbREGISTER_UPDATED_BY_STATION, "RegisterUpdate",actnames,denames,actmasks);
00313 chkPowerEvent(PowerSourceID::ErrorSID, power.robotStatus,orsbRTC_ERROR, "RTCError",actnames,denames,actmasks);
00314 chkPowerEvent(PowerSourceID::RTCSID, power.robotStatus,orsbRTC_OVERFLOW, "RTCOverflow",actnames,denames,actmasks);
00315 chkPowerEvent(PowerSourceID::RTCSID, power.robotStatus,orsbRTC_RESET, "RTCReset",actnames,denames,actmasks);
00316 chkPowerEvent(PowerSourceID::RTCSID, power.robotStatus,orsbRTC_SET, "RTCSet",actnames,denames,actmasks);
00317 chkPowerEvent(PowerSourceID::SpecialModeSID, power.robotStatus,orsbSPECIAL_MODE, "SpecialMode",actnames,denames,actmasks);
00318 chkPowerEvent(PowerSourceID::BMNDebugModeSID, power.robotStatus,orsbBMN_DEBUG_MODE, "BMNDebugMode",actnames,denames,actmasks);
00319 chkPowerEvent(PowerSourceID::ChargerStatusSID, power.robotStatus,orsbCHARGER_STATUS, "ChargerStatus",actnames,denames,actmasks);
00320 chkPowerEvent(PowerSourceID::PlungerSID, power.robotStatus,orsbPLUNGER, "Plunger",actnames,denames,actmasks);
00321 chkPowerEvent(PowerSourceID::SuspendedSID, power.robotStatus,orsbSUSPENDED, "Suspended",actnames,denames,actmasks);
00322
00323
00324 chkPowerEvent(PowerSourceID::ErrorSID, power.batteryStatus,obsbERROR_CODE_MASK, "BatteryError",actnames,denames,actmasks);
00325 chkPowerEvent(PowerSourceID::BatteryEmptySID, power.batteryStatus,obsbFULLY_DISCHARGED, "FullyDischarged",actnames,denames,actmasks);
00326 chkPowerEvent(PowerSourceID::BatteryFullSID, power.batteryStatus,obsbFULLY_CHARGED, "FullyCharged",actnames,denames,actmasks);
00327 chkPowerEvent(PowerSourceID::DischargingSID, power.batteryStatus,obsbDISCHARGING, "Discharging",actnames,denames,actmasks);
00328 chkPowerEvent(PowerSourceID::BatteryInitSID, power.batteryStatus,obsbINITIALIZED, "BatteryInit",actnames,denames,actmasks);
00329 chkPowerEvent(PowerSourceID::LowPowerWarnSID, power.batteryStatus,obsbREMAINING_TIME_ALARM, "RemainingTimeAlarm",actnames,denames,actmasks);
00330 chkPowerEvent(PowerSourceID::LowPowerWarnSID, power.batteryStatus,obsbREMAINING_CAPACITY_ALARM, "RemainingCapacityAlarm",actnames,denames,actmasks);
00331 chkPowerEvent(PowerSourceID::TermDischargeSID,power.batteryStatus,obsbTERMINATED_DISCHARGING_ALARM,"TermDischargeAlarm",actnames,denames,actmasks);
00332 chkPowerEvent(PowerSourceID::OverheatingSID, power.batteryStatus,obsbOVER_TEMP_ALARM, "OverTempAlarm",actnames,denames,actmasks);
00333 chkPowerEvent(PowerSourceID::TermChargeSID, power.batteryStatus,obsbTERMINATED_CHARGING_ALARM, "TermChargeAlarm",actnames,denames,actmasks);
00334 chkPowerEvent(PowerSourceID::OverChargedSID, power.batteryStatus,obsbOVER_CHARGED_ALARM, "OverChargeAlarm",actnames,denames,actmasks);
00335
00336 sensors[PowerRemainOffset] = power.remainingCapacity/100.0;
00337 sensors[PowerThermoOffset] = power.temperature/100.0;
00338 sensors[PowerCapacityOffset] = power.fullyChargedCapacity;
00339 sensors[PowerVoltageOffset] = power.voltage/1000.0;
00340 sensors[PowerCurrentOffset] = power.current;
00341
00342
00343 for(unsigned int i=0; i<PowerSourceID::NumPowerSIDs; i++) {
00344 if(actmasks[i]) {
00345 if(!powerFlags[i])
00346 er->postEvent(EventBase::powerEGID,i,EventBase::activateETID,0,actnames[i],1);
00347 else if(actmasks[i]!=powerFlags[i])
00348 er->postEvent(EventBase::powerEGID,i,EventBase::statusETID,0,actnames[i],1);
00349 } else {
00350 if(powerFlags[i])
00351 er->postEvent(EventBase::powerEGID,i,EventBase::deactivateETID,0,denames[i],0);
00352 }
00353 powerFlags[i]=actmasks[i];
00354 }
00355
00356 er->postEvent(EventBase::powerEGID,PowerSourceID::UpdatedSID,EventBase::statusETID,0);
00357 }
00358
00359 #endif //PLATFORM_APERIOS
00360
00361 void WorldState::chkEvent(EventRouter* er, unsigned int sid, float newval, const char* name) {
00362 if(newval>=0.1) {
00363 if(buttons[sid]<0.1) {
00364 er->postEvent(EventBase::buttonEGID,sid,EventBase::activateETID,0,name,newval);
00365 button_times[sid]=curtime;
00366 } else if(alwaysGenerateStatus || buttons[sid]!=newval) {
00367 unsigned int dur=curtime-button_times[sid];
00368 er->postEvent(EventBase::buttonEGID,sid,EventBase::statusETID,dur,name,newval);
00369 }
00370 } else {
00371 if(buttons[sid]>=0.1) {
00372 unsigned int dur=curtime-button_times[sid];
00373 button_times[sid]=0;
00374 er->postEvent(EventBase::buttonEGID,sid,EventBase::deactivateETID,dur,name,0);
00375 }
00376 }
00377
00378 buttons[sid]=newval;
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390