darwin_robot_driver.cpp
Go to the documentation of this file.
00001 #include "darwin_robot_driver.h"
00002 #include "darwin_exceptions.h"
00003 
00004 DarwinRobotDriver::DarwinRobotDriver(void)
00005 {
00006   //setDriverId(driver string id);
00007   this->robot=NULL;
00008 
00009   this->CM730_device="/dev/ttyUSB0";
00010   this->action_file="/home/darwin/darwinop/Data/motion_4096.bin";
00011   this->config_file="/home/darwin/iridrivers/darwin_robot/trunk/config.ini";
00012 }
00013 
00014 bool DarwinRobotDriver::openDriver(void)
00015 {
00016   //setDriverId(driver string id);
00017   try{
00018     this->robot=new CDarwin(this->CM730_device,this->action_file);
00019     this->robot->load_config(this->config_file);
00020     return true;
00021   }catch(CException &e){
00022     ROS_INFO("%s",e.what().c_str());
00023     if(this->robot!=NULL)
00024     {
00025       delete this->robot;
00026       this->robot=NULL;
00027     }
00028     return false;
00029   }
00030 }
00031 
00032 bool DarwinRobotDriver::closeDriver(void)
00033 {
00034   if(this->robot!=NULL)
00035   {
00036     this->robot->stop_walking();
00037     this->robot->stop_action();
00038     this->robot->stop_all_joints();
00039     delete this->robot;
00040     this->robot=NULL;
00041   }
00042 
00043   return true;
00044 }
00045 
00046 bool DarwinRobotDriver::startDriver(void)
00047 {
00048   return true;
00049 }
00050 
00051 bool DarwinRobotDriver::stopDriver(void)
00052 {
00053   return true;
00054 }
00055 
00056 void DarwinRobotDriver::config_update(Config& new_cfg, uint32_t level)
00057 {
00058   this->lock();
00059   
00060   // depending on current state
00061   // update driver with new_cfg data
00062   switch(this->getState())
00063   {
00064     case DarwinRobotDriver::CLOSED:
00065       if(this->robot!=NULL)
00066       {
00067         // change the motion and configuration files
00068         try{
00069           this->robot->load_config(new_cfg.config_file);
00070           this->config_file=new_cfg.config_file;
00071         }catch(CDarwinException &e){
00072           ROS_INFO("%s",e.what().c_str());
00073           new_cfg.config_file=this->config_file;
00074         }
00075         try{
00076           this->robot->load_actions(new_cfg.motion_file);
00077           this->action_file=new_cfg.motion_file;
00078         }catch(CDarwinException &e){
00079           ROS_INFO("%s",e.what().c_str());
00080           new_cfg.motion_file=this->action_file;
00081         }
00082       }
00083       break;
00084 
00085     case DarwinRobotDriver::OPENED:
00086       // change the USB device port
00087       this->CM730_device=new_cfg.device_id;
00088       break;
00089 
00090     case DarwinRobotDriver::RUNNING:
00091       break;
00092   }
00093 
00094   // save the current configuration
00095   this->config_=new_cfg;
00096 
00097   this->unlock();
00098 }
00099 
00100 std::vector<double> DarwinRobotDriver::get_current_angles(void)
00101 {
00102   return this->robot->get_current_angles();
00103 }
00104 
00105 // Walking interface
00106 void DarwinRobotDriver::start_walking(double x_dist, double y_dist, double turn_angle)
00107 {
00108   this->robot->start_walking(x_dist,y_dist,turn_angle);
00109 }
00110 
00111 void DarwinRobotDriver::tune_walking(double x_dist,double y_dist, double turn_angle)
00112 {
00113   this->robot->tune_walking(x_dist,y_dist,turn_angle);
00114 }
00115 
00116 void DarwinRobotDriver::set_walking_param(motion_params param, double value)
00117 {
00118   this->robot->set_walking_param(param,value);
00119 }
00120 
00121 double DarwinRobotDriver::get_walking_param(motion_params param)
00122 {
00123   return this->robot->get_walking_param(param);
00124 }
00125 
00126 void DarwinRobotDriver::stop_walking(void)
00127 {
00128   this->robot->stop_walking();
00129 }
00130 
00131 bool DarwinRobotDriver::is_walking(void)
00132 {
00133   return this->robot->is_walking();
00134 }
00135 
00136 // action interface
00137 void DarwinRobotDriver::start_action(unsigned int action_index)
00138 {
00139   this->robot->start_action(action_index);
00140 }
00141 
00142 void DarwinRobotDriver::start_action(std::string &action_name)
00143 {
00144   this->robot->start_action(action_name);
00145 }
00146 
00147 void DarwinRobotDriver::stop_action(void)
00148 {
00149   this->robot->stop_action();
00150 }
00151 
00152 void DarwinRobotDriver::break_action(void)
00153 {
00154   this->robot->break_action();
00155 }
00156 
00157 bool DarwinRobotDriver::action_is_running(void)
00158 {
00159   return this->robot->action_is_running();
00160 }
00161 
00162 // Head public interface
00163 void DarwinRobotDriver::get_head_position(double *pan, double *tilt)
00164 {
00165   this->robot->get_head_position(pan,tilt);
00166 }
00167 
00168 void DarwinRobotDriver::set_head_position(double pan, double tilt)
00169 {
00170   this->robot->set_head_position(pan,tilt);
00171 }
00172 
00173 // sensor interface
00174 void DarwinRobotDriver::get_gyroscope(double *x,double *y, double *z)
00175 {
00176   this->robot->get_gyroscope(x,y,z);
00177 }
00178 
00179 void DarwinRobotDriver::get_accelerometer(double *x, double *y, double *z)
00180 {
00181   this->robot->get_accelerometer(x,y,z);
00182 }
00183 
00184 void DarwinRobotDriver::get_analog_channel(analogs id,double *value)
00185 {
00186   this->robot->get_analog_channel(id,value);
00187 }
00188 
00189 // joint motion public interface
00190 std::string DarwinRobotDriver::move_joints(std::vector<int> &servos,std::vector<double> &angles,std::vector<double> &speeds, std::vector<double> &accels,const std::string &target_id)
00191 {
00192   return this->robot->move_joints(servos,angles,speeds,accels,target_id);
00193 }
00194 
00195 bool DarwinRobotDriver::joints_are_moving(std::string &target_id)
00196 {
00197   return this->robot->joints_are_moving(target_id);
00198 }
00199 
00200 void DarwinRobotDriver::stop_joints(std::string &target_id)
00201 {
00202   this->robot->stop_joints(target_id);
00203 }
00204 
00205 // tracking public interface
00206 void DarwinRobotDriver::start_head_tracking(void)
00207 {
00208   this->robot->start_head_tracking();
00209 }
00210 
00211 void DarwinRobotDriver::stop_head_tracking(void)
00212 {
00213   this->robot->stop_head_tracking();
00214 }
00215 
00216 void DarwinRobotDriver::set_tracking_pid(int t, TPID *pan_pid, TPID *tilt_pid)
00217 {
00218   this->robot->set_tracking_pid(t,pan_pid,tilt_pid);
00219 }
00220 
00221 void DarwinRobotDriver::get_tracking_pid(int *t, TPID *pan_pid, TPID *tilt_pid)
00222 {
00223   this->robot->get_tracking_pid(t,pan_pid,tilt_pid);
00224 }
00225 
00226 void DarwinRobotDriver::set_tracking_target(double pan, double tilt)
00227 {
00228   this->robot->set_tracking_target(pan,tilt);
00229 }
00230 
00231 void DarwinRobotDriver::get_tracking_target(double *pan, double *tilt)
00232 {
00233   this->robot->get_tracking_target(pan,tilt);
00234 }
00235 
00236 DarwinRobotDriver::~DarwinRobotDriver(void)
00237 {
00238   this->lock();
00239   if(this->robot!=NULL)
00240   {
00241     this->robot->stop_walking();
00242     this->robot->stop_action();
00243     this->robot->stop_all_joints();
00244     delete this->robot;
00245     this->robot=NULL;
00246   }
00247   this->unlock();
00248 }


iri_darwin_robot
Author(s): shernand
autogenerated on Fri Dec 6 2013 20:53:54