Aria  2.8.0
ArBatteryMTX Class Reference

#include <ArBatteryMTX.h>

Inherits ArASyncTask.

Public Types

enum  ErrorFlags {
  ERROR_BATTERY_OVERVOLTAGE =0x0001, ERROR_BATTERY_UNDERVOLTAGE =0x0002, ERROR_OVERCURRENT =0x0004, ERROR_BLOWNFUSE =0x0008,
  ERROR_RTC_ERROR =0x0010, ERROR_OVER_TEMPERATURE =0x0020, ERROR_MASTER_SWITCH_FAULT =0x0040, ERROR_SRAM_ERROR =0x0080,
  ERROR_CHARGER_OUT_OF_VOLTAGE_RANGE =0x0100, ERROR_CHARGER_CIRCUIT_FAULT =0x0200
}
 
enum  Headers { HEADER1 =0xfa, HEADER2 =0xba }
 
enum  StatusFlags {
  STATUS_ON_CHARGER =0x0001, STATUS_CHARGING =0x0002, STATUS_BALANCING_ENGAGED =0x0004, STATUS_CHARGER_ON =0x0008,
  STATUS_BATTERY_POWERING_OFF =0x0010, STATUS_MASTER_SWITCH_ON =0x0020, STATUS_CHARGE_SWITCH_ON =0x0040, STATUS_COMMANDED_SHUTDOWN =0x0080,
  STATUS_OFF_BUTTON_PRESSED =0x0100, STATUS_ON_BUTTON_PRESSED =0x0200, STATUS_USER_BUTTON_PRESSED =0x0400
}
 
- Public Types inherited from ArThread
typedef std::map< ThreadType, ArThread * > MapType
 
enum  Status {
  STATUS_FAILED =1, STATUS_NORESOURCE, STATUS_NO_SUCH_THREAD, STATUS_INVALID,
  STATUS_JOIN_SELF, STATUS_ALREADY_DETATCHED
}
 
typedef pthread_t ThreadType
 

Public Member Functions

void addBatteryPoweringOffCancelledCB (ArFunctor *functor, int position=51)
 Adds a callback for when the battery is powering off.
 
void addBatteryPoweringOffCB (ArFunctor *functor, int position=51)
 Adds a callback for when the battery is powering off.
 
void addDisconnectOnErrorCB (ArFunctor *functor, int position=51)
 Adds a callback for when disconnection happens because of an error.
 
 ArBatteryMTX (int batteryBoardNum=0, const char *name="MTXBattery", ArDeviceConnection *conn=NULL, ArRobot *robot=NULL)
 Constructor.
 
virtual bool blockingConnect (bool sendTracking, bool recvTracking)
 
bool checkLostConnection (void)
 check for lost connections More...
 
virtual bool disconnect (void)
 
void disconnectOnError (void)
 disconnect
 
int getAsyncConnectState (void)
 
int getBoardNum (void)
 
int getCapacityEstimate (void) const
 
int getCellCapacity (int cellNum) const
 
int getCellCharge (int cellNum) const
 
int getCellFlag (int cellNum) const
 
double getCellImbalance (void) const
 
ArRobotPacket getCellPacket ()
 
double getCellVoltage (int cellNum) const
 
double getChargeCurrent (void) const
 
double getChargeEstimate (void) const
 Charge estimate (in percentage, 0-100)
 
int getChargeRemainingEstimate (void) const
 
ArRobot::ChargeState getChargeState (void) const
 
int getChargeStateAsInt (void) const
 
virtual double getConnectionTimeoutSeconds (void)
 Gets the number of seconds without a response until connection assumed lost.
 
double getCurrentDraw (void) const
 Current draw (amps, negative is charging)
 
long long getCurrentTime (void) const
 
int getCycleCount (void) const
 
const char * getDefaultPortType (void)
 Gets the default port type for the battery.
 
const char * getDefaultTcpPort (void)
 Gets the default port type for the battery.
 
double getDelay (void) const
 
ArDeviceConnectiongetDeviceConnection (void)
 Gets the device this instance receives packets from.
 
double getDisChargeCurrent (void) const
 
int getErrorFlags (void) const
 
int getFirmwareVersion (void) const
 
double getFuseVoltage (void) const
 
int getId (void) const
 
double getImbalanceQuality (void) const
 
long long getLastChargeTime (void) const
 
ArTime getLastReadingTime (void)
 Gets the time data was last receieved.
 
virtual const char * getName (void) const
 
int getNumCells (void) const
 
ArRobotPacketReceivergetPacketReceiver (void)
 Very Internal call that gets the packet sender, shouldn't be used.
 
ArRobotPacketSendergetPacketSender (void)
 Very Internal call that gets the packet sender, shouldn't be used.
 
double getPackVoltage (void) const
 volts
 
double getPaddleVolts (void) const
 
int getReadingCount (void)
 Gets the number of battery readings received in the last second.
 
double getReserveChargeValue (void) const
 
int getSerialNumber (void) const
 
int getStatusFlags (void) const
 
double getTemperature (void) const
 
double getVoltage (void) const
 
bool haveRequestedCellInfoPackets (void)
 See if we've requested packets.
 
bool haveRequestedSysInfoPackets (void)
 See if we've requested packets.
 
virtual void internalGotReading (void)
 
virtual bool isConnected (void)
 
virtual bool isTryingToConnect (void)
 
virtual int lockDevice ()
 Lock this device.
 
void log (ArLog::LogLevel level=ArLog::Normal)
 
void logBatteryInfo (ArLog::LogLevel level=ArLog::Normal)
 
void logCellInfo (ArLog::LogLevel level=ArLog::Normal)
 
bool onCharger (void) const
 
void remBatteryPoweringOffCancelledCB (ArFunctor *functor)
 Removes a callback for when the battery is powering off.
 
void remBatteryPoweringOffCB (ArFunctor *functor)
 Removes a callback for when the battery is powering off.
 
void remDisconnectOnErrorCB (ArFunctor *functor)
 Removes a callback for when disconnection happens because of an error.
 
void requestContinuousCellInfoPackets (void)
 Request a continous stream of packets.
 
void requestContinuousSysInfoPackets (void)
 Request a continous stream of packets.
 
bool sendBasicInfo (unsigned char dataValue)
 
bool sendCellInfo (unsigned char dataValue)
 
bool sendEmergencyPowerOff ()
 
bool sendPowerOff ()
 
bool sendPowerOffCancel ()
 
bool sendResetCellData ()
 
bool sendSetBalanceValue (unsigned short hundredthOfPercent)
 
bool sendSetPowerOffDelay (unsigned int msDelay)
 
bool sendSetRealTimeClock (unsigned int secSinceEpoch)
 
bool sendSetReserveValue (unsigned short hundredthOfPercent)
 
bool sendStartCharging ()
 
bool sendStopCharging ()
 
bool sendSystemInfo (unsigned char dataValue)
 
virtual void setConnectionTimeoutSeconds (double seconds)
 Sets the numter of seconds without a response until connection assumed lost.
 
void setDeviceConnection (ArDeviceConnection *conn)
 Sets the device this instance receives packets from.
 
void setInfoLogLevel (ArLog::LogLevel infoLogLevel)
 
virtual void setRobot (ArRobot *robot)
 Sets the robot pointer, also attaches its process function to the robot as a Sensor Interpretation task. More...
 
void stopCellInfoPackets (void)
 Stop the stream of packets.
 
void stopSysInfoPackets (void)
 Stop the stream of packets.
 
virtual int tryLockDevice ()
 Try to lock this device.
 
virtual int unlockDevice ()
 Unlock this device.
 
void updateBasicInfo (unsigned char *buf)
 
void updateCellInfo (unsigned char *buf)
 
void updateSystemInfo (unsigned char *buf)
 
virtual ~ArBatteryMTX ()
 Destructor.
 
- Public Member Functions inherited from ArASyncTask
 ArASyncTask ()
 Constructor.
 
virtual int create (bool joinable=true, bool lowerPriority=true)
 Create the task and start it going.
 
virtual const char * getThreadActivity (void)
 Gets a string that describes what the thread is doing, or NULL if it doesn't know. More...
 
virtual void run (void)
 Run without creating a new thread. More...
 
virtual void runAsync (void)
 Run in its own thread.
 
virtual void * runInThisThread (void *arg=0)
 Internal function used with system threading system to run the new thread. More...
 
virtual void stopRunning (void)
 Stop the thread.
 
virtual ~ArASyncTask ()
 Destructor.
 
- Public Member Functions inherited from ArThread
 ArThread (bool blockAllSignals=true)
 Constructor.
 
 ArThread (ThreadType thread, bool joinable, bool blockAllSignals=true)
 Constructor - starts the thread.
 
 ArThread (ArFunctor *func, bool joinable=true, bool blockAllSignals=true)
 Constructor - starts the thread.
 
virtual void cancel (void)
 Cancel the thread.
 
virtual int detach (void)
 Detatch the thread so it cant be joined.
 
bool getBlockAllSignals (void)
 Do we block all process signals at startup?
 
virtual ArFunctorgetFunc (void) const
 Get the functor that the thread runs.
 
virtual bool getJoinable (void) const
 Get the joinable status of the thread.
 
virtual ThreadType getOSThread (void) const
 Get the underlying os thread type.
 
pid_t getPID (void)
 
virtual bool getRunning (void) const
 Get the running status of the thread.
 
virtual bool getRunningWithLock (void)
 Get the running status of the thread, locking around the variable.
 
virtual const ThreadType * getThread (void) const
 Get the underlying thread type.
 
virtual const char * getThreadName (void)
 Gets the name of the thread.
 
pid_t getTID (void)
 
virtual bool isThreadFinished () const
 Returns whether the thread has been completed and can be deleted. More...
 
virtual bool isThreadStarted () const
 Returns whether the thread has been started. More...
 
virtual int join (void **ret=NULL)
 Join on the thread.
 
int lock (void)
 Lock the thread instance. More...
 
virtual void logThreadInfo (void)
 Logs the information about this thread.
 
virtual void setRunning (bool running)
 Set the running value on the thread.
 
virtual void setThreadName (const char *name)
 Sets the name of the thread.
 
virtual void threadFinished (void)
 Marks the thread as finished and logs useful debugging information. More...
 
virtual void threadStarted (void)
 Marks the thread as started and logs useful debugging information. More...
 
int tryLock (void)
 Try to lock the thread instance without blocking. More...
 
int unlock (void)
 Unlock the thread instance. More...
 
virtual ~ArThread ()
 Destructor.
 

Protected Types

enum  CellFlags { BALANCER_IS_ON =0x01, OVER_VOLTAGE =0x02, UNDER_VOLTAGE =0x04 }
 
enum  Commands {
  BASIC_INFO =0x00, SYSTEM_INFO =0x01, CELL_INFO =0x02, POWER_OFF_REQUEST =0x10,
  POWER_OFF_CANCEL =0x11, STOP_CHARGING =0x12, START_CHARGING =0x13, SET_POWER_OFF_DELAY =0x20,
  SET_REAL_TIME_CLOCK =0x21, RESET_CELL_DATA =0x22, SET_RESERVE_VALUE =0x23, SET_BALANCE_VALUE =0x24,
  EMERGENCY_OFF =0xff
}
 
enum  Data { STOP_SENDING =0x00, SEND_ONCE =0x01, SEND_CONTINUOUS =0x02 }
 
enum  Sizes { BASIC_INFO_SIZE =16, SYSTEM_INFO_SIZE =60, CELL_INFO_SIZE =95 }
 

Protected Member Functions

virtual void batterySetName (const char *name)
 
void checkAndSetCurrentErrors (ErrorFlags errorFlag, const char *errorString)
 
void clear (void)
 
void failedToConnect (void)
 
bool getBasicInfo ()
 
bool getCellInfo ()
 
bool getSystemInfo ()
 
void interpBasicInfo (void)
 
void interpErrors (void)
 
virtual void * runThread (void *arg)
 
void sensorInterp (void)
 
- Protected Member Functions inherited from ArThread
virtual int doJoin (void **ret=NULL)
 

Protected Attributes

ArRetFunctorC< bool, ArBatteryMTXmyAriaExitCB
 
int myAsyncConnectState
 
ArCallbackList myBatteryPoweringOffCancelledCBList
 
ArCallbackList myBatteryPoweringOffCBList
 
int myBoardNum
 
unsigned int myCapacityEstimate
 
double myCellImbalance
 
std::map< int, CellInfo * > myCellNumToInfoMap
 
ArRobotPacket myCellPacket
 
double myChargeCurrent
 
double myChargeEstimate
 
unsigned int myChargeRemainingEstimate
 
ArRobot::ChargeState myChargeState
 
ArDeviceConnectionmyConn
 
double myCurrentDraw
 
long long myCurrentTime
 
unsigned int myCycleCount
 
ArMutex myDataMutex
 
std::string myDefaultPortType
 
std::string myDefaultTcpPort
 
double myDelay
 
ArMutex myDeviceMutex
 
double myDisChargeCurrent
 
ArCallbackList myDisconnectOnErrorCBList
 
int myErrorCount
 
unsigned short myErrorFlags
 
std::string myErrorString
 
unsigned char myFirmwareVersion
 
bool myFirstErrorFlagsCheck
 
double myFuseVoltage
 
bool myHaveSetRTC
 
unsigned char myId
 
double myImbalanceQuality
 
ArLog::LogLevel myInfoLogLevel
 
bool myIsConnected
 
long long myLastChargeTime
 
int myLastErrorCount
 
unsigned short myLastErrorFlags
 
std::string myLastErrorString
 
ArTime myLastReading
 
int myLastStatusFlags
 
ArLog::LogLevel myLogLevel
 
std::string myName
 
unsigned char myNumCells
 
bool myOnCharger
 
std::list< ArRobotPacket * > myPackets
 
ArMutex myPacketsMutex
 
double myPackVoltage
 
double myPaddleVolts
 
ArTime myPrevBatteryIntTime
 
ArFunctorC< ArBatteryMTXmyProcessCB
 
unsigned short myRawCellImbalance
 
unsigned short myRawChargeCurrent
 
unsigned short myRawChargeEstimate
 
unsigned short myRawCurrentDraw
 
unsigned int myRawDelay
 
unsigned short myRawDisChargeCurrent
 
unsigned short myRawFuseVoltage
 
unsigned short myRawImbalanceQuality
 
unsigned short myRawPackVoltage
 
unsigned short myRawPaddleVolts
 
unsigned short myRawReserveChargeValue
 
unsigned short myRawTemperature
 
unsigned short myRawVoltage
 
int myReadingCount
 
int myReadingCurrentCount
 
ArRobotPacketReceivermyReceiver
 
bool myRecvTracking
 
bool myRequestedCellInfoBatteryPackets
 
bool myRequestedSysInfoBatteryPackets
 
double myReserveChargeValue
 
ArRobotmyRobot
 
bool myRobotRunningAndConnected
 
ArRobotPacketSendermySender
 
bool mySendTracking
 
ArFunctorC< ArBatteryMTXmySensorInterpTask
 
unsigned int mySerialNumber
 
bool myStartConnect
 
unsigned short myStatusFlags
 
double myTemperature
 
time_t myTimeLastReading
 
double myTimeoutSeconds
 
bool myTryingToConnect
 
unsigned char myVersion
 
double myVoltage
 
- Protected Attributes inherited from ArThread
bool myBlockAllSignals
 
bool myFinished
 
ArFunctormyFunc
 
bool myJoinable
 
ArMutex myMutex
 
std::string myName
 
pid_t myPID
 
bool myRunning
 State variable to denote when the thread should continue or exit.
 
bool myStarted
 
ArStrMap myStrMap
 
ThreadType myThread
 
pid_t myTID
 

Additional Inherited Members

- Static Public Member Functions inherited from ArThread
static void cancelAll (void)
 Cancel all threads.
 
static ArLog::LogLevel getLogLevel (void)
 Gets the logging level for thread information.
 
static ThreadType getThisOSThread (void)
 Get the underlying os thread type of this thread.
 
static const ThreadType * getThisThread (void)
 Get the underlying thread type of this thread.
 
static const char * getThisThreadName (void)
 Gets the name of the this thread.
 
static void init (void)
 Initialize the internal book keeping structures. More...
 
static void joinAll (void)
 Join on all threads.
 
static ThreadType osSelf (void)
 Returns the os self of the current thread. More...
 
static ArThreadself (void)
 Returns the instance of your own thread (the current one) More...
 
static void setLogLevel (ArLog::LogLevel level)
 Sets the logging level for thread information.
 
static void shutdown ()
 Shuts down and deletes the last remaining thread; call after joinAll.
 
static void stopAll ()
 Stop all threads.
 
static void yieldProcessor (void)
 Yield the processor to another thread.
 
- Static Protected Member Functions inherited from ArThread
static void addThreadToMap (ThreadType pt, ArThread *at)
 
static ArThreadfindThreadInMap (ThreadType t)
 
static void removeThreadFromMap (ThreadType t)
 
- Static Protected Attributes inherited from ArThread
static ArLog::LogLevel ourLogLevel = ArLog::Verbose
 
static MapType ourThreads
 
static ArMutex ourThreadsMutex
 
static std::string ourUnknownThreadName = "unknown"
 

Detailed Description

Since
2.8.0

Member Function Documentation

◆ checkLostConnection()

bool ArBatteryMTX::checkLostConnection ( void  )

check for lost connections

This will check if the battery has lost connection.

If there is no robot it is a straightforward check of last reading time against getConnectionTimeoutSeconds. If there is a robot then it will not start the check until the battery is running and connected.

◆ setRobot()

void ArBatteryMTX::setRobot ( ArRobot robot)
virtual

Sets the robot pointer, also attaches its process function to the robot as a Sensor Interpretation task.


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