diff --git a/src/dynamixel_motor.cpp b/src/dynamixel_motor.cpp index 40b679ee8894ece71d5c431ef24e5e4f40ce1b3d..e65e57f0db0bb65d0fa16c03ef2fbcf095c76da3 100644 --- a/src/dynamixel_motor.cpp +++ b/src/dynamixel_motor.cpp @@ -73,6 +73,67 @@ CDynamixelMotor::CDynamixelMotor(std::string& cont_id,unsigned char bus_id,int b } } +CDynamixelMotor::CDynamixelMotor(std::string& cont_id,std::string &bus_id,int baudrate,unsigned char dev_id):CMotorControl(cont_id,1) +{ + std::vector<float> max,min,gear; + std::vector<int> enc_res; + TMotorConfig config; + + this->info.model=""; + this->info.firmware_ver=0x00; + this->control.cw_compliance_margin=0x00; + this->control.ccw_compliance_margin=0x00; + this->control.cw_compliance_slope=0x20; + this->control.ccw_compliance_slope=0x20; + this->dyn_server=CDynamixelServer::instance(); + this->dynamixel_dev=NULL; + this->alarms=0x24; + this->dyn_enc_res=-1; + this->dyn_max_angle=-1; + this->dyn_max_speed=-1; + this->torque_control=false; + try{ + this->dyn_server->config_bus(bus_id,baudrate); + this->dynamixel_dev=this->dyn_server->get_device(dev_id); + this->info.model=this->get_model(); + enc_res.push_back(this->dyn_enc_res); + config.encoder_resolution=enc_res; + this->set_encoder_resolution(enc_res); + gear.push_back(1); + config.gear_factor=gear; + this->set_gear_factor(gear); + this->alarms=this->get_turn_off_alarms(); + this->info.firmware_ver=this->get_firmware_version(); + this->get_position_range(min,max); + config.acceleration.resize(1); + config.acceleration[0].min=0.0; + config.acceleration[0].max=0.0; + config.velocity.resize(1); + config.velocity[0].min=0.0; + config.velocity[0].max=0.0; + config.position.resize(1); + config.position[0].min=min[0]; + config.position[0].max=max[0]; + config.open_loop=false; + this->config(&config); + if(min[0]==0.0 && max[0]==0.0) + this->enable_torque_control(); + else + { + this->config_position_feedback(fb_polling,100.0); + this->enable_position_feedback(); + this->torque_control=false; + } + this->current_position=this->cont_get_position()[0]; + }catch(CException &e){ + /* handle exceptions */ + if(this->dynamixel_dev!=NULL) + delete this->dynamixel_dev; + this->dynamixel_dev=NULL; + throw; + } +} + void CDynamixelMotor::angles_to_controller(std::vector<float>& angles,std::vector<float>& counts) { if(angles.size()!=1) diff --git a/src/dynamixel_motor.h b/src/dynamixel_motor.h index e285931378591fae57494b533d3b08261c1b301c..c2b5a2b4df5a568c7b774c66a80e17b8064bda07 100644 --- a/src/dynamixel_motor.h +++ b/src/dynamixel_motor.h @@ -244,6 +244,11 @@ class CDynamixelMotor : public CMotorControl * */ CDynamixelMotor(std::string& cont_id,unsigned char bus_id,int baudrate,unsigned char dev_id); + /** + * \brief + * + */ + CDynamixelMotor(std::string& cont_id,std::string &bus_id,int baudrate,unsigned char dev_id); /** * \brief *