diff --git a/src/darwin_robot.cpp b/src/darwin_robot.cpp index 7f450649c17405a3ebb7b966d0b5cccc7329bcde..9438169a651d1a5c8748d06bac30d62e70bd9e15 100644 --- a/src/darwin_robot.cpp +++ b/src/darwin_robot.cpp @@ -1837,7 +1837,7 @@ bool CDarwinRobot::is_smart_charger_det_and_en(void) throw CDarwinRobotException(_HERE_,"Invalid robot device"); } - +//Set smart charger period in s void CDarwinRobot::smart_charger_set_period(double period) { unsigned short int period_ms; @@ -1855,7 +1855,7 @@ void CDarwinRobot::smart_charger_set_period(double period) throw CDarwinRobotException(_HERE_,"Invalid robot device"); } - +//Get smart charger period in s double CDarwinRobot::smart_charger_get_period(void) { unsigned short int period_ms; @@ -1884,9 +1884,11 @@ void CDarwinRobot::smart_charger_get_period(double *period) throw CDarwinRobotException(_HERE_,"Invalid robot device"); } */ + +/* Obtain time to full, to empty and battery status + */ TChargerData CDarwinRobot::smart_charger_get_data(void) { - // unsigned short charger_data[3]; TChargerData smart_charger_data; if(this->robot_device!=NULL) @@ -1898,6 +1900,46 @@ TChargerData CDarwinRobot::smart_charger_get_data(void) throw CDarwinRobotException(_HERE_,"Invalid robot device"); } +//Set limit input current +void CDarwinRobot::smart_charger_range_current(double min_current, double max_current) +{ + this->MAX_limit_current=max_current; + this->MIN_limit_current=min_current; +} + +//Get limit current in A +double CDarwinRobot::smart_charger_get_limit_current(void) +{ + unsigned short int limit_current_ma; + + if(this->robot_device!=NULL) + { + this->robot_device->read_word_register(DARWIN_SMART_CHARGER_LIMIT_CURRENT_L,&limit_current_ma); + + return ((double)limit_current_ma)/1000; + } + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} + +//Set limit current in A +void CDarwinRobot::smart_charger_set_limit_current(double limit_current) +{ + unsigned short int limit_current_ma; + + if(this->robot_device!=NULL) + { + //if(limit_current > MIN_limit_current && limit_current < MAX_limit_current){ + if(limit_current > 0.255 && limit_current < 1.025){ + limit_current_ma=(limit_current/2)*1000; + this->robot_device->write_word_register(DARWIN_SMART_CHARGER_LIMIT_CURRENT_L,limit_current_ma); + }else{ + std::cout <<" Invalid current value" << std::endl; + } + } + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} unsigned int CDarwinRobot::smart_charger_read_time_empty(void) { @@ -1938,31 +1980,6 @@ unsigned char CDarwinRobot::smart_charger_read_status(void) throw CDarwinRobotException(_HERE_,"Invalid robot device"); } -//Set limit input current -void CDarwinRobot::smart_charger_range_current(double min_current, double max_current) -{ - this->MAX_limit_current=max_current; - this->MIN_limit_current=min_current; -} -void CDarwinRobot::smart_charger_set_limit_current(double limit_current) -{ - unsigned short int limit_current_ma; - - if(this->robot_device!=NULL) - { - //if(limit_current > MIN_limit_current && limit_current < MAX_limit_current){ - if(limit_current > 0.255 && limit_current < 1.0){ - limit_current_ma=limit_current*1000; - this->robot_device->write_word_register(DARWIN_SMART_CHARGER_LIMIT_CURRENT_L,limit_current_ma); - }else{ - std::cout <<" Invalid current value" << std::endl; - } - } - else - throw CDarwinRobotException(_HERE_,"Invalid robot device"); -} - - CDarwinRobot::~CDarwinRobot() { if(this->robot_device!=NULL) diff --git a/src/darwin_robot.h b/src/darwin_robot.h index ebbbb1e5f26f406346e7d5002943acff4c21977c..80881293b9bc504b3f1655e44088bc7c1b12cd10 100644 --- a/src/darwin_robot.h +++ b/src/darwin_robot.h @@ -218,11 +218,11 @@ class CDarwinRobot void smart_charger_disable(void); /** * \brief Function to set smart charger's read operation period - * \param period_ms Period in ms of smart charger module + * \param period Period in s of smart charger module */ void smart_charger_set_period(double period); /** - * \brief Function to get smart charger's read operation period + * \brief Function to get smart charger's read operation period in segs */ double smart_charger_get_period(void); /** @@ -234,8 +234,12 @@ class CDarwinRobot */ void smart_charger_range_current(double min_current, double max_current); /** - * \brief Function to set smart charger's period - * \param limit_current Value of limit current + * \brief Function to get limit current in A + */ + double smart_charger_get_limit_current(void); + /** + * \brief Function to set smart charger's limit current + * \param limit_current Value of limit current in A */ void smart_charger_set_limit_current(double limit_current); /** diff --git a/src/examples/darwin_smart_charger_test.cpp b/src/examples/darwin_smart_charger_test.cpp index b38c28e7dceddc0541cd9749f9a7748f2c87159a..44e266d754c9e0b859d90acd0af8ed56e20b53ab 100644 --- a/src/examples/darwin_smart_charger_test.cpp +++ b/src/examples/darwin_smart_charger_test.cpp @@ -32,6 +32,7 @@ int main(int argc, char *argv[]) double period; int control, status; TChargerData charger_data; + double current; try{ CDarwinRobot darwin("Darwin",robot_device,1000000,0x02); @@ -76,15 +77,6 @@ int main(int argc, char *argv[]) std::cout << "Motion manager is running" << std::endl; //WRITE EEPROM - /* unsigned short int length = 6; //8 bytes - RAM 0x20 to 0x27 - unsigned short int data_eeprom[3]; //BATTERY_INPUT_CURRENT / BATTERY_CHARGE_CURRENT / BATTERY_CHARGE_VOLTAGE / BATTERY_LIMIT_CURRENT - unsigned char *p_eeprom; - p_eeprom=(uint8_t *)&data_eeprom; - error=dyn_master_read_table(&darwin_dyn_master,id,BATTERY_INPUT_MAX_CURRENT_L,length,p_eeprom); - std::cout << "Limit current eeprom: " << data_eeprom[0] << std::endl; - std::cout << "Output current eeprom: " << data_eeprom[1] << std::endl; - std::cout << "Output voltage eeprom: " << data_eeprom[2] << std::endl; - */ double max_current=1.0; double min_current=0.255; double limit_current = 0.512; //(A) @@ -92,13 +84,11 @@ int main(int argc, char *argv[]) // darwin.smart_charger_range_current(min_current, max_current); darwin.smart_charger_set_limit_current(limit_current); + //current=darwin.smart_charger_get_limit_current(); + std::cout << "LIMIT CURRENT: " << darwin.smart_charger_get_limit_current() << "A" << std::endl; + //READ SMART CHARGER DATA -// charger_data=darwin.smart_charger_get_data(); -// std::cout << "battery status: " << charger_data.bat_status << std::endl; -// std::cout << "Avg time to empty: " << charger_data.avg_time_empty << std::endl; -// std::cout << "Avg time to full: " << charger_data.avg_time_full << std::endl; - while(1){ charger_data=darwin.smart_charger_get_data(); @@ -108,13 +98,15 @@ int main(int argc, char *argv[]) std::cout << "battery status: connected" << std::endl; else if(charger_data.bat_status==128) std::cout << "battery status: connected and charging " << std::endl; + else + std::cout << "Battery status value: " << charger_data.bat_status << std::endl; //y totalmente cargado o descargado??? std::cout << "Avg time to empty: " << charger_data.avg_time_empty << " min" << std::endl; std::cout << "Avg time to full: " << charger_data.avg_time_full << " min" << std::endl; std::cout << "---------------------- " << std::endl; //std::cout << "Avg time to empty: " << darwin.smart_charger_read_time_empty() << " min" << std::endl; - + //charger status --> batteries detected, AC detected, etc //status=darwin.smart_charger_read_status();