Skip to content
Snippets Groups Projects
Commit 9a1c2074 authored by Irene Garcia Camacho's avatar Irene Garcia Camacho
Browse files

Added a function to read limit current of the smart charger

parent 17f33fdf
No related branches found
No related tags found
1 merge request!2Added a function to read limit current of the smart charger
...@@ -1837,7 +1837,7 @@ bool CDarwinRobot::is_smart_charger_det_and_en(void) ...@@ -1837,7 +1837,7 @@ bool CDarwinRobot::is_smart_charger_det_and_en(void)
throw CDarwinRobotException(_HERE_,"Invalid robot device"); throw CDarwinRobotException(_HERE_,"Invalid robot device");
} }
//Set smart charger period in s
void CDarwinRobot::smart_charger_set_period(double period) void CDarwinRobot::smart_charger_set_period(double period)
{ {
unsigned short int period_ms; unsigned short int period_ms;
...@@ -1855,7 +1855,7 @@ void CDarwinRobot::smart_charger_set_period(double period) ...@@ -1855,7 +1855,7 @@ void CDarwinRobot::smart_charger_set_period(double period)
throw CDarwinRobotException(_HERE_,"Invalid robot device"); throw CDarwinRobotException(_HERE_,"Invalid robot device");
} }
//Get smart charger period in s
double CDarwinRobot::smart_charger_get_period(void) double CDarwinRobot::smart_charger_get_period(void)
{ {
unsigned short int period_ms; unsigned short int period_ms;
...@@ -1884,9 +1884,11 @@ void CDarwinRobot::smart_charger_get_period(double *period) ...@@ -1884,9 +1884,11 @@ void CDarwinRobot::smart_charger_get_period(double *period)
throw CDarwinRobotException(_HERE_,"Invalid robot device"); throw CDarwinRobotException(_HERE_,"Invalid robot device");
} }
*/ */
/* Obtain time to full, to empty and battery status
*/
TChargerData CDarwinRobot::smart_charger_get_data(void) TChargerData CDarwinRobot::smart_charger_get_data(void)
{ {
// unsigned short charger_data[3];
TChargerData smart_charger_data; TChargerData smart_charger_data;
if(this->robot_device!=NULL) if(this->robot_device!=NULL)
...@@ -1898,6 +1900,46 @@ TChargerData CDarwinRobot::smart_charger_get_data(void) ...@@ -1898,6 +1900,46 @@ TChargerData CDarwinRobot::smart_charger_get_data(void)
throw CDarwinRobotException(_HERE_,"Invalid robot device"); 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) unsigned int CDarwinRobot::smart_charger_read_time_empty(void)
{ {
...@@ -1938,31 +1980,6 @@ unsigned char CDarwinRobot::smart_charger_read_status(void) ...@@ -1938,31 +1980,6 @@ unsigned char CDarwinRobot::smart_charger_read_status(void)
throw CDarwinRobotException(_HERE_,"Invalid robot device"); 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() CDarwinRobot::~CDarwinRobot()
{ {
if(this->robot_device!=NULL) if(this->robot_device!=NULL)
......
...@@ -218,11 +218,11 @@ class CDarwinRobot ...@@ -218,11 +218,11 @@ class CDarwinRobot
void smart_charger_disable(void); void smart_charger_disable(void);
/** /**
* \brief Function to set smart charger's read operation period * \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); 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); double smart_charger_get_period(void);
/** /**
...@@ -234,8 +234,12 @@ class CDarwinRobot ...@@ -234,8 +234,12 @@ class CDarwinRobot
*/ */
void smart_charger_range_current(double min_current, double max_current); void smart_charger_range_current(double min_current, double max_current);
/** /**
* \brief Function to set smart charger's period * \brief Function to get limit current in A
* \param limit_current Value of limit current */
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); void smart_charger_set_limit_current(double limit_current);
/** /**
......
...@@ -32,6 +32,7 @@ int main(int argc, char *argv[]) ...@@ -32,6 +32,7 @@ int main(int argc, char *argv[])
double period; double period;
int control, status; int control, status;
TChargerData charger_data; TChargerData charger_data;
double current;
try{ try{
CDarwinRobot darwin("Darwin",robot_device,1000000,0x02); CDarwinRobot darwin("Darwin",robot_device,1000000,0x02);
...@@ -76,15 +77,6 @@ int main(int argc, char *argv[]) ...@@ -76,15 +77,6 @@ int main(int argc, char *argv[])
std::cout << "Motion manager is running" << std::endl; std::cout << "Motion manager is running" << std::endl;
//WRITE EEPROM //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 max_current=1.0;
double min_current=0.255; double min_current=0.255;
double limit_current = 0.512; //(A) double limit_current = 0.512; //(A)
...@@ -92,13 +84,11 @@ int main(int argc, char *argv[]) ...@@ -92,13 +84,11 @@ int main(int argc, char *argv[])
// darwin.smart_charger_range_current(min_current, max_current); // darwin.smart_charger_range_current(min_current, max_current);
darwin.smart_charger_set_limit_current(limit_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 //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){ while(1){
charger_data=darwin.smart_charger_get_data(); charger_data=darwin.smart_charger_get_data();
...@@ -108,13 +98,15 @@ int main(int argc, char *argv[]) ...@@ -108,13 +98,15 @@ int main(int argc, char *argv[])
std::cout << "battery status: connected" << std::endl; std::cout << "battery status: connected" << std::endl;
else if(charger_data.bat_status==128) else if(charger_data.bat_status==128)
std::cout << "battery status: connected and charging " << std::endl; 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??? //y totalmente cargado o descargado???
std::cout << "Avg time to empty: " << charger_data.avg_time_empty << " min" << std::endl; 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 << "Avg time to full: " << charger_data.avg_time_full << " min" << std::endl;
std::cout << "---------------------- " << std::endl; std::cout << "---------------------- " << std::endl;
//std::cout << "Avg time to empty: " << darwin.smart_charger_read_time_empty() << " min" << std::endl; //std::cout << "Avg time to empty: " << darwin.smart_charger_read_time_empty() << " min" << std::endl;
//charger status --> batteries detected, AC detected, etc //charger status --> batteries detected, AC detected, etc
//status=darwin.smart_charger_read_status(); //status=darwin.smart_charger_read_status();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment