00001 #include "tibi_dabo_head_tracking_alg.h" 00002 00003 TibiDaboHeadTrackingAlgorithm::TibiDaboHeadTrackingAlgorithm(void) 00004 { 00005 this->current_pan=0.0; 00006 this->current_tilt=0.0; 00007 00008 this->pan_control.P=0.01; 00009 this->pan_control.I=0.0; 00010 this->pan_control.D=0.0; 00011 this->tilt_control.P=0.01; 00012 this->tilt_control.I=0.0; 00013 this->tilt_control.D=0.0; 00014 00015 this->max_pan_angle=150.0*3.14159/180.0; 00016 this->min_pan_angle=-150.0*3.14159/180.0; 00017 this->max_tilt_angle=125.0*3.14159/180.0; 00018 this->min_tilt_angle=-125.0*3.14159/180.0; 00019 00020 this->pan_error=0.0; 00021 this->tilt_error=0.0; 00022 } 00023 00024 TibiDaboHeadTrackingAlgorithm::~TibiDaboHeadTrackingAlgorithm(void) 00025 { 00026 } 00027 00028 void TibiDaboHeadTrackingAlgorithm::config_update(Config& new_cfg, uint32_t level) 00029 { 00030 this->lock(); 00031 00032 // save the current configuration 00033 this->pan_control.P=new_cfg.pan_P; 00034 this->pan_control.I=new_cfg.pan_I; 00035 this->pan_control.D=new_cfg.pan_D; 00036 this->tilt_control.P=new_cfg.tilt_P; 00037 this->tilt_control.I=new_cfg.tilt_I; 00038 this->tilt_control.D=new_cfg.tilt_D; 00039 00040 this->max_pan_angle=new_cfg.max_pan; 00041 this->min_pan_angle=new_cfg.min_pan; 00042 this->max_tilt_angle=new_cfg.max_tilt; 00043 this->min_tilt_angle=new_cfg.min_tilt; 00044 this->config_=new_cfg; 00045 00046 this->unlock(); 00047 } 00048 00049 // TibiDaboHeadTrackingAlgorithm Public API 00050 void TibiDaboHeadTrackingAlgorithm::compute_head_position(float target_pan,float target_tilt,float *pan, float *tilt) 00051 { 00052 static float last_pan_error=0.0,int_pan_error=0.0; 00053 static float last_tilt_error=0.0,int_tilt_error=0.0; 00054 00055 this->lock(); 00056 this->pan_error=target_pan-this->current_pan; 00057 this->tilt_error=target_tilt-this->current_tilt; 00058 (*pan)=(pan_error*this->pan_control.P)+(pan_error-last_pan_error)*this->pan_control.D-int_pan_error*this->pan_control.I+this->current_pan; 00059 if((*pan)>this->max_pan_angle) 00060 (*pan)=this->max_pan_angle; 00061 else if((*pan)<this->min_pan_angle) 00062 (*pan)=this->min_pan_angle; 00063 (*tilt)=(tilt_error*this->tilt_control.P)+(tilt_error-last_tilt_error)*this->tilt_control.D-int_tilt_error*this->tilt_control.I+this->current_tilt; 00064 if((*tilt)>this->max_tilt_angle) 00065 (*tilt)=this->max_tilt_angle; 00066 else if((*tilt)<this->min_tilt_angle) 00067 (*tilt)=this->min_tilt_angle; 00068 last_pan_error=pan_error; 00069 last_tilt_error=tilt_error; 00070 int_pan_error+=pan_error; 00071 int_tilt_error+=tilt_error; 00072 this->unlock(); 00073 } 00074 00075 void TibiDaboHeadTrackingAlgorithm::set_current_head_position(float pan, float tilt) 00076 { 00077 this->lock(); 00078 this->current_pan=pan; 00079 this->current_tilt=tilt; 00080 this->unlock(); 00081 } 00082 00083 void TibiDaboHeadTrackingAlgorithm::get_current_error(float *pan_error,float *tilt_error) 00084 { 00085 (*pan_error)=this->pan_error; 00086 (*tilt_error)=this->tilt_error; 00087 }