MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman and others 00010 // at MIT 2001-2002 and Oxford University 2003-2005. 00011 // email: pnewman@robots.ox.ac.uk. 00012 // 00013 // This file is part of a MOOS Instrument. 00014 // 00015 // This program is free software; you can redistribute it and/or 00016 // modify it under the terms of the GNU General Public License as 00017 // published by the Free Software Foundation; either version 2 of the 00018 // License, or (at your option) any later version. 00019 // 00020 // This program is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00023 // General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU General Public License 00026 // along with this program; if not, write to the Free Software 00027 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00028 // 02111-1307, USA. 00029 // 00031 // BatteryDriver.cpp: implementation of the CBatteryDriver class. 00032 // 00034 00035 #include "BatteryDriver.h" 00036 00038 // Construction/Destruction 00040 00041 CBatteryDriver::CBatteryStatus::CBatteryStatus() 00042 { 00043 m_dfPercent = -1; 00044 m_dfVoltage = -1; 00045 m_eStatus = UNKNOWN; 00046 m_dfFull = -1; 00047 m_dfEmpty = -1; 00048 m_dfLow = 0; 00049 00050 00051 } 00052 00053 CBatteryDriver::CBatteryDriver() 00054 { 00055 00056 } 00057 00058 CBatteryDriver::~CBatteryDriver() 00059 { 00060 00061 } 00062 00063 bool CBatteryDriver::SetSerialPort(CMOOSSerialPort *pPort) 00064 { 00065 m_pPort = pPort; 00066 00067 return true; 00068 } 00069 00070 bool CBatteryDriver::SetLowVolts(double dfVolts) 00071 { 00072 m_Status.m_dfLow = dfVolts; 00073 return true; 00074 } 00075 00076 00077 bool CBatteryDriver::SetFullVolts(double dfVolts) 00078 { 00079 m_Status.m_dfFull = dfVolts; 00080 return true; 00081 } 00082 00083 bool CBatteryDriver::SetEmptyVolts(double dfVolts) 00084 { 00085 m_Status.m_dfEmpty = dfVolts; 00086 return true; 00087 } 00088 00089 00090 bool CBatteryDriver::GetStatus(CBatteryStatus & Status) 00091 { 00092 if(IsError()) 00093 { 00094 m_Status.m_sError = GetErrorString(); 00095 m_Status.m_eStatus = CBatteryStatus::BAD; 00096 } 00097 else 00098 { 00099 //OK no device specific errors so see if we 00100 //are breaking any rules seet in the mission file... 00101 m_Status.Calculate(); 00102 } 00103 00104 Status = m_Status; 00105 00106 return true; 00107 } 00108 00109 string CBatteryDriver::CBatteryStatus::GetStatusAsString() 00110 { 00111 switch(m_eStatus) 00112 { 00113 case UNKNOWN: return "UNKNOWN"; break; 00114 case GOOD: return "GOOD"; break; 00115 case LOW: return "LOW"; break; 00116 case BAD: return "BAD"; break; 00117 case DANGEROUS: return "DANGEROUS"; break; 00118 case SENSOR_ERROR: return "SENSOR_ERROR"; break; 00119 default: 00120 return "ILLEGAL CODE STATE"; break; 00121 } 00122 } 00123 00124 double CBatteryDriver::CBatteryStatus::GetPercentCharge() 00125 { 00126 return m_dfPercent; 00127 } 00128 00129 double CBatteryDriver::CBatteryStatus::GetVoltage() 00130 { 00131 return m_dfVoltage; 00132 } 00133 00134 bool CBatteryDriver::CBatteryStatus::Calculate() 00135 { 00136 //how full our we? 00137 m_dfPercent = (m_dfVoltage-m_dfEmpty)/(m_dfFull-m_dfEmpty)*100.0; 00138 00139 if(m_dfVoltage>m_dfLow) 00140 { 00141 m_eStatus = GOOD; 00142 } 00143 else if(m_dfVoltage<m_dfLow) 00144 { 00145 m_eStatus = LOW; 00146 } 00147 else if(m_dfVoltage<m_dfEmpty) 00148 { 00149 m_eStatus = BAD; 00150 } 00151 00152 return true; 00153 } 00154 00155 CBatteryDriver::CBatteryStatus::Condition CBatteryDriver::CBatteryStatus::GetStatus() 00156 { 00157 return m_eStatus; 00158 } 00159 00160 bool CBatteryDriver::IsError() 00161 { 00162 return false; 00163 } 00164 00165 string CBatteryDriver::GetErrorString() 00166 { 00167 return m_sError; 00168 } 00169 00170 bool CBatteryDriver::Switch(bool bOn) 00171 { 00172 return true; 00173 } 00174 00175 string CBatteryDriver::GetCellsString() 00176 { 00177 return ""; 00178 } 00179 00180 00181 string CBatteryDriver::GetCommentString() 00182 { 00183 return ""; 00184 }