Go to the documentation of this file.00001 #include "pose_based_vs_alg.h"
00002
00003 PoseBasedVsAlgorithm::PoseBasedVsAlgorithm(void)
00004 {
00005 }
00006
00007 PoseBasedVsAlgorithm::~PoseBasedVsAlgorithm(void)
00008 {
00009 }
00010
00011 void PoseBasedVsAlgorithm::config_update(Config& new_cfg, uint32_t level)
00012 {
00013 this->lock();
00014
00015
00016 this->config_=new_cfg;
00017
00018 this->unlock();
00019 }
00020
00021
00022 void PoseBasedVsAlgorithm::pose_vs(const std::vector<double>& current_pose,const std::vector<double>& desired_pose,const std::vector<double>& kp,const std::vector<double>& kd,const std::vector<double>& ki, const double& i_lim, const double& dt,std::vector<double>& cam_vel)
00023 {
00024 this->current_pose_=current_pose;
00025 this->desired_pose_=desired_pose;
00026 this->kp_=kp;
00027 this->kd_=kd;
00028 this->ki_=ki;
00029 this->i_lim_=i_lim;
00030 this->dt_=dt;
00031
00032
00033 double error;
00034
00035
00036 this->p_error_last_.resize(6,0.0);
00037 this->p_error_.resize(6,0.0);
00038 this->d_error_.resize(6,0.0);
00039 this->i_error_.resize(6,0.0);
00040 this->kp_.resize(6,0.0);
00041 this->kd_.resize(6,0.0);
00042 this->ki_.resize(6,0.0);
00043
00044 for (unsigned int i = 0; i < this->current_pose_.size(); ++i)
00045 {
00046
00047 error = this->desired_pose_[i] - this->current_pose_[i];
00048
00049 cam_vel.at(i)=updatePid(error, this->dt_, i);
00050 }
00051 }
00052
00053
00054 double PoseBasedVsAlgorithm::updatePid(double error, double dt, double i)
00055 {
00056
00057 double p_term, d_term, i_term;
00058 double i_max = this->i_lim_;
00059 double i_min = -(this->i_lim_);
00060 this->p_error_.at(i) = error;
00061
00062 if (dt == 0.0 || std::isnan(error) || std::isinf(error))
00063 return 0.0;
00064
00065 p_term = this->kp_[i] * p_error_[i];
00066
00067
00068 this->i_error_.at(i) = this->i_error_[i] + dt * this->p_error_[i];
00069
00070
00071 i_term = this->ki_[i] * this->i_error_[i];
00072
00073
00074 if (i_term > i_max)
00075 {
00076 i_term = i_max;
00077 this->i_error_.at(i)=i_term/this->ki_[i];
00078 }
00079 else if (i_term < i_min)
00080 {
00081 i_term = i_min;
00082 this->i_error_.at(i)=i_term/this->ki_[i];
00083 }
00084
00085 if (dt != 0.0)
00086 {
00087 this->d_error_.at(i) = (this->p_error_[i] - this->p_error_last_[i]) / dt;
00088 this->p_error_last_.at(i) = this->p_error_[i];
00089 }
00090
00091 d_term = this->kd_[i] * this->d_error_[i];
00092 this->cmd_ = -p_term - i_term - d_term;
00093 return cmd_;
00094 }