diff --git a/src/darwin_robot.cpp b/src/darwin_robot.cpp index ca6c6931b900f4e185e14d4fc176fa9ecf327f07..600d0834d28c8ef8eb7e9fb3485414901299d3dc 100644 --- a/src/darwin_robot.cpp +++ b/src/darwin_robot.cpp @@ -1,5 +1,6 @@ #include "darwin_robot.h" #include "darwin_robot_exceptions.h" +#include "dynamixelexceptions.h" #include <iostream> #include <sys/types.h> #include <sys/stat.h> @@ -82,23 +83,28 @@ CDarwinRobot::CDarwinRobot(const std::string &name,std::string &bus_id,int bus_s if(num_buses>0) { sleep(1); - this->robot_device=dyn_server->get_device(id,dyn_version2); - this->robot_id=id; - /* wait for the firmware to finish the scan */ - do{ - /* get the current manager status */ - this->robot_device->read_byte_register(DARWIN_MM_CNTRL,&this->manager_status); - usleep(10000); - }while(this->manager_status&MANAGER_SCANNING); - /* get the number of servos detected */ - this->robot_device->read_byte_register(DARWIN_MM_NUM_SERVOS,&this->manager_num_servos); - /* get the current action status */ - this->robot_device->read_byte_register(DARWIN_ACTION_CNTRL,&this->action_status); - /* get the current smart charger status (detected or not)*/ - this->robot_device->read_byte_register(DARWIN_SMART_CHARGER_CNTRL,&this->smart_charger_status); - this->min_limit_current=MIN_LIMIT_CURRENT; - this->max_limit_current=MAX_LIMIT_CURRENT; - + try{ + this->robot_device=dyn_server->get_device(id,dyn_version2); + this->robot_id=id; + /* wait for the firmware to finish the scan */ + do{ + /* get the current manager status */ + this->robot_device->read_byte_register(DARWIN_MM_CNTRL,&this->manager_status); + usleep(10000); + }while(this->manager_status&MANAGER_SCANNING); + /* get the number of servos detected */ + this->robot_device->read_byte_register(DARWIN_MM_NUM_SERVOS,&this->manager_num_servos); + /* get the current action status */ + this->robot_device->read_byte_register(DARWIN_ACTION_CNTRL,&this->action_status); + /* get the current smart charger status (detected or not)*/ + this->robot_device->read_byte_register(DARWIN_SMART_CHARGER_CNTRL,&this->smart_charger_status); + this->min_limit_current=MIN_LIMIT_CURRENT; + this->max_limit_current=MAX_LIMIT_CURRENT; + }catch(CDynamixelServerException &e){ + this->dyn_server->free_device(id); + std::cout << "exception" << std::endl; + throw e; + } } else {