00001 #include "uncalibvs_alg_node.h"
00002 
00003 UncalibvsAlgNode::UncalibvsAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<Uncalibvs_Algorithm>(),
00005   activate_(false),
00006   traditional_(false),
00007   random_points_(false),
00008   quadrotor_(true),
00009   output_files_(false),
00010   estop_(false),
00011   serial_(false),
00012   calibrated_ctrl_(true),
00013   lambda_(0.01),
00014   final_z_(1.0),
00015   ENUyaw_(0.0),
00016   ENUyaw_fix_(0.0),
00017   height_fix_(0.0),
00018   tag_thrust_kp_(0.05),
00019   tag_thrust_kd_(0.05),
00020   tag_roll_kp_(0.1),
00021   tag_roll_kd_(0.15),
00022   tag_pitch_kp_(0.1),
00023   tag_pitch_kd_(0.15),
00024   tag_yaw_kp_(0.05),
00025   tag_yaw_kd_(0.05),  
00026   thrust_kp_(0.06),
00027   thrust_kd_(0.005),
00028   roll_kp_(0.2),
00029   roll_kd_(0),
00030   pitch_kp_(0.2),
00031   pitch_kd_(0),
00032   yaw_kp_(0.2),
00033   yaw_kd_(0),  
00034   sat_min_(0.42745),
00035   sat_max_(0.53737),
00036   rollpitch_sat_min_(-0.146),
00037   rollpitch_sat_max_(0.146),
00038   yaw_sat_min_(-1),
00039   yaw_sat_max_(1),
00040   ctrl_ref_(0.447),
00041   trimm_y_(0.0),
00042   trimm_x_(0.0),
00043   buff_speed_(1),
00044   path_("/home/asantamaria/Desktop/poses.txt"),
00045   rollpitch_div_(1000),
00046   Rquad_inertial_(Eigen::MatrixXf::Zero(3,3))
00047 {
00048   this->init_=true; 
00049   
00050   this->loop_rate_ = 100;
00051 
00052   
00053   this->body_twist_publisher_ = this->public_node_handle_.advertise<geometry_msgs::Twist>("body_twist", 1);
00054   this->yaw_control_publisher_ = this->public_node_handle_.advertise<iri_uncalibvs::control>("yaw_control", 1);
00055   this->pitch_control_publisher_ = this->public_node_handle_.advertise<iri_uncalibvs::control>("pitch_control", 1);
00056   this->roll_control_publisher_ = this->public_node_handle_.advertise<iri_uncalibvs::control>("roll_control", 1);
00057   this->thrust_control_publisher_ = this->public_node_handle_.advertise<iri_uncalibvs::control>("thrust_control", 1);
00058   this->state_publisher_ = this->public_node_handle_.advertise<mav_msgs::Status>("state", 10);
00059   this->cmd_yaw_publisher_ = this->public_node_handle_.advertise<std_msgs::Float64>("cmd_yaw", 10);
00060   this->cmd_pitch_publisher_ = this->public_node_handle_.advertise<std_msgs::Float64>("cmd_pitch", 10);
00061   this->cmd_roll_publisher_ = this->public_node_handle_.advertise<std_msgs::Float64>("cmd_roll", 10);
00062   this->cmd_thrust_publisher_ = this->public_node_handle_.advertise<std_msgs::Float64>("cmd_thrust", 10);
00063   this->ESTOP_publisher_ = this->public_node_handle_.advertise<std_msgs::Bool>("ESTOP", 1);
00064 
00065   
00066   this->ll_status_subscriber_ = this->public_node_handle_.subscribe("ll_status", 10, &UncalibvsAlgNode::ll_status_callback, this);
00067   this->height_subscriber_ = this->public_node_handle_.subscribe("height", 10, &UncalibvsAlgNode::height_callback, this);
00068   this->imu_subscriber_ = this->public_node_handle_.subscribe("imu", 10, &UncalibvsAlgNode::imu_callback, this);
00069   this->model_state_subscriber_ = this->public_node_handle_.subscribe("model_state", 10, &UncalibvsAlgNode::model_state_callback, this);
00070   this->input_tag_subscriber_ = this->public_node_handle_.subscribe("input_tag", 10, &UncalibvsAlgNode::input_tag_callback, this);
00071  
00072   
00073   this->time_last_ = ros::Time::now();
00074   
00075   
00076   this->tag_pid_thrust_.initPid(this->tag_thrust_kp_, 0, this->tag_thrust_kd_, 0, 0);
00077   this->pid_thrust_.initPid(this->thrust_kp_, 0, this->thrust_kd_, 0, 0);
00078   
00079   
00080   this->tag_pid_roll_.initPid(this->tag_roll_kp_, 0, this->tag_roll_kd_, 0, 0);  
00081   this->pid_roll_.initPid(this->roll_kp_, 0, this->roll_kd_, 0, 0);
00082   
00083   
00084   this->tag_pid_pitch_.initPid(this->tag_pitch_kp_, 0, this->tag_pitch_kd_, 0, 0);  
00085   this->pid_pitch_.initPid(this->pitch_kp_, 0, this->pitch_kd_, 0, 0);
00086   
00087   
00088   this->tag_pid_yaw_.initPid(this->tag_yaw_kp_, 0, this->tag_yaw_kd_, 0, 0);  
00089   this->pid_yaw_.initPid(this->yaw_kp_, 0, this->yaw_kd_, 0, 0);
00090 
00091   
00092   
00093   
00094   
00095   
00096   
00097   
00098 }
00099 
00100 UncalibvsAlgNode::~UncalibvsAlgNode(void)
00101 {
00102   
00103 }
00104 
00105 void UncalibvsAlgNode::mainNodeThread(void)
00106 {
00107   
00108   
00109   
00110   
00111   
00112   
00113   
00114   
00115   
00116   
00117   
00118   
00119   
00120   
00121   
00122   
00123   
00124   
00125   
00126   
00127   this->Bool_msg_.data=this->estop_;
00128   if (this->estop_) {
00129     ROS_ERROR_STREAM("EMERGENCY_STOP ENABLED");
00130     this->ESTOP_publisher_.publish(this->Bool_msg_);
00131   }
00132  
00133   
00134   this->body_twist_publisher_.publish(this->body_twist_msg_);
00135   this->yaw_control_publisher_.publish(this->yaw_control_msg_);
00136   this->pitch_control_publisher_.publish(this->pitch_control_msg_);
00137   this->roll_control_publisher_.publish(this->roll_control_msg_);
00138   this->thrust_control_publisher_.publish(this->thrust_control_msg_);
00139   this->state_publisher_.publish(this->Status_msg_);
00140   this->cmd_yaw_publisher_.publish(this->cmd_yaw_msg_);
00141   this->cmd_pitch_publisher_.publish(this->cmd_pitch_msg_);
00142   this->cmd_roll_publisher_.publish(this->cmd_roll_msg_);
00143   this->cmd_thrust_publisher_.publish(this->cmd_thrust_msg_);
00144 }
00145 
00146 
00147 void UncalibvsAlgNode::ll_status_callback(const asctec_msgs::LLStatus::ConstPtr& msg) 
00148 { 
00149   
00150 
00151   
00152   
00153   this->ll_status_mutex_.enter(); 
00154 
00155   
00156   int ll_status;
00157   ll_status=(int)msg->flightMode;
00158   
00159   std::bitset<32> flight_mode;
00160   flight_mode.reset();
00161   
00162   
00163   int *y,x;
00164   y = reinterpret_cast<int*>(&ll_status);
00165   x=*y;
00166   for(short i=0;i<32;++i) {
00167     flight_mode[i] = x%2;
00168     x /= 2;
00169   }
00170 
00171   
00172   if ((ll_status|0b1111111101111111)!=0b1111111111111111)   ROS_DEBUG("NO Emergency");
00173   if ((ll_status|0b1111111111111101)!=0b1111111111111111)   ROS_DEBUG("NO Height Control");
00174   if ((ll_status|0b1111111111111011)!=0b1111111111111111)   ROS_DEBUG("NO GPS Mode");
00175   if ((ll_status|0b1111111111011111)!=0b1111111111111111) {
00176     ROS_DEBUG("NO Serial Enable");
00177     this->serial_=false;
00178     this->height_fix_=0;
00179   }
00180   else {
00181     this->serial_=true;
00182   }
00183   
00184   if ((ll_status|0b1111111110111111)!=0b1111111111111111)   ROS_DEBUG("NO Serial Active");
00185 
00186   
00187   
00188   this->ll_status_mutex_.exit(); 
00189 }
00190 void UncalibvsAlgNode::height_callback(const mav_msgs::Height::ConstPtr& msg) 
00191 { 
00192   
00193 
00194   
00195   
00196   this->height_mutex_.enter(); 
00197 
00198   
00199 
00200   this->height_=msg->height;
00201   
00202   
00203   if(this->height_fix_==0 && this->serial_) this->height_fix_=this->height_;
00204   
00205   
00206   
00207   this->height_mutex_.exit(); 
00208 }
00209 void UncalibvsAlgNode::imu_callback(const sensor_msgs::Imu::ConstPtr& msg) 
00210 { 
00211   
00212 
00213   
00214   
00215   this->imu_mutex_.enter(); 
00216 
00217    
00218   this->twist_quad_.linear.x=0.0;
00219   this->twist_quad_.linear.y=0.0;
00220   this->twist_quad_.linear.z=0.0;
00221   this->twist_quad_.angular.x=-msg->angular_velocity.x;
00222   this->twist_quad_.angular.y=msg->angular_velocity.y;
00223   this->twist_quad_.angular.z=msg->angular_velocity.z;
00224 
00225   
00226   geometry_msgs::Pose qpose;
00227   qpose.position.x=0.0;
00228   qpose.position.y=0.0;
00229   qpose.position.z=0.0;
00230   qpose.orientation=msg->orientation;
00231   
00232   tf::Transform tf_pose;
00233   double ya,pi,ro;
00234   tf::poseMsgToTF(qpose, tf_pose);
00235   tf_pose.getBasis().getRPY(ro,pi,ya);
00236 
00237 
00238   
00239   
00240   
00241   
00242   
00243   
00244   
00245   
00246   Eigen::Matrix3f Rwb,Rfix,Rwfb,Rfbi;
00247   
00248   
00249   Rwb = Eigen::AngleAxisf(ro, Eigen::Vector3f::UnitX()) \
00250       * Eigen::AngleAxisf(pi, Eigen::Vector3f::UnitY()) \
00251       * Eigen::AngleAxisf(ya, Eigen::Vector3f::UnitZ());
00252   
00253   
00254   
00255   
00256   Rfix=Eigen::MatrixXf::Zero(3,3);
00257   double zang=0.75*3.1416;
00258   
00259   
00260   
00261   
00262   
00263   Rfix = Eigen::AngleAxisf(0, Eigen::Vector3f::UnitX()) \
00264        * Eigen::AngleAxisf(0, Eigen::Vector3f::UnitY()) \
00265        * Eigen::AngleAxisf(zang, Eigen::Vector3f::UnitZ());
00266   
00267   
00268   
00269   Rwfb=Rwb*Rfix;
00270   
00271   
00272   
00273   Eigen::MatrixXf wfbangl(3,1);
00274   wfbangl=Rwfb.eulerAngles(0,1,2);
00275   
00276   
00277   Rfbi = Eigen::AngleAxisf(0, Eigen::Vector3f::UnitX()) \
00278          * Eigen::AngleAxisf(0, Eigen::Vector3f::UnitY()) \
00279          * Eigen::AngleAxisf(wfbangl(2), Eigen::Vector3f::UnitZ());
00280   
00281   
00282   
00283   Rquad_inertial_=Rfbi.transpose()*Rwfb;
00284   
00285   
00286   
00287   
00288   this->ENUyaw_=wfbangl(2);
00289     
00290   if(this->ENUyaw_fix_==0 && this->serial_) this->ENUyaw_fix_=this->ENUyaw_;
00291   
00292   
00293   
00294   
00295   
00296     
00297   
00298   
00299   
00300     
00301     
00302   
00303   
00304   
00305   
00306   
00307   
00308   
00309   
00310   
00311   
00312   
00313   
00314   
00315   
00316   
00317   
00318   
00319   
00320   
00321   
00322   
00323   
00324 
00325 
00326   
00327   
00328   
00329   
00330 
00331   
00332   
00333   this->imu_mutex_.exit(); 
00334 }
00335 
00336 void UncalibvsAlgNode::model_state_callback(const asctec_msgs::IMUCalcData::ConstPtr& msg) 
00337 { 
00338   
00339 
00340   
00341   
00342   this->model_state_mutex_.enter(); 
00343   
00345   int size=this->buff_speed_;
00346   std::vector<double> buff_x(size),buff_y(size);
00347   buff_x.reserve(size);
00348   buff_y.reserve(size);
00349   double m_x,m_y;
00350   int index;
00351   m_x=0.0;
00352   m_y=0.0;
00353   if (index==size) index=0;
00354   buff_x[index]=msg->speed_x;
00355   buff_y[index]=msg->speed_y;
00356   index=index+1; 
00357   for(int i=0; i<(size-1); ++i){
00358     m_x += buff_x[i];
00359     m_y += buff_y[i];
00360   }
00361   
00362   Eigen::MatrixXf body_speed(3,1),inertial_speed(3,1);
00363   
00364   
00365   
00366   body_speed(0,0)=msg->speed_x;
00367   body_speed(1,0)=msg->speed_y;
00368   body_speed(2,0)=msg->speed_z;
00369   
00370   Eigen::Matrix3f Rfix;
00371   
00372   Rfix=Eigen::MatrixXf::Zero(3,3);
00373   double zang=0.75*3.1416;
00374   Rfix = Eigen::AngleAxisf(0, Eigen::Vector3f::UnitX()) \
00375        * Eigen::AngleAxisf(0, Eigen::Vector3f::UnitY()) \
00376        * Eigen::AngleAxisf(zang, Eigen::Vector3f::UnitZ());
00377        
00378   
00379   
00380   inertial_speed=Rfix*body_speed;          
00381   
00382  
00383   
00384   this->twist_quad_asctec_.linear.x=inertial_speed(0,0);
00385   this->twist_quad_asctec_.linear.y=inertial_speed(1,0);
00386   this->twist_quad_asctec_.linear.z=inertial_speed(2,0);
00387   this->twist_quad_asctec_.angular.x=msg->angvel_roll;
00388   this->twist_quad_asctec_.angular.y=msg->angvel_nick;
00389   this->twist_quad_asctec_.angular.z=msg->angvel_yaw;
00390   
00391   this->body_twist_msg_=this->twist_quad_asctec_;
00392   
00393   
00394   
00395   
00396   
00397   
00398   
00399 
00400   
00401   
00402   
00403   
00404 
00405   
00406   this->model_state_mutex_.exit(); 
00407 }
00408 
00409 void UncalibvsAlgNode::input_tag_callback(const ar_pose::ARMarkers::ConstPtr& msg) 
00410 { 
00411 
00412   
00413   this->alg_.lock();   
00414 
00415   this->time_ = ros::Time::now();
00416 
00417   double x,y,z,yaw,pitch,roll,tag_cmd_pid_roll,tag_cmd_pid_pitch,tag_cmd_pid_yaw,tag_cmd_pid_thrust,cmd_pid_roll,cmd_pid_pitch,cmd_pid_yaw,cmd_pid_thrust;
00418   x=0;
00419   y=0;
00420   z=0;
00421   roll=0;
00422   pitch=0;
00423   yaw=0;
00424   tag_cmd_pid_roll=0;
00425   tag_cmd_pid_pitch=0;
00426   tag_cmd_pid_yaw=0;
00427   tag_cmd_pid_thrust=0;
00428   cmd_pid_roll=0;
00429   cmd_pid_pitch=0;
00430   cmd_pid_yaw=0;
00431   cmd_pid_thrust=0;
00432   
00433   Eigen::Matrix3f R;
00434   Eigen::MatrixXf Vel_quad(6,1);
00435   Vel_quad=Eigen::MatrixXf::Zero(6,1);
00436   this->error_=Eigen::MatrixXf::Zero(6,1);
00437   this->tag_error_=Eigen::MatrixXf::Zero(6,1);
00438  
00439   if (msg->markers.empty()){
00440      this->init_=true;  
00441     
00442      
00443      this->error_(2)=this->height_ - this->height_fix_;
00444      
00445      
00446      this->error_(1)= -(this->twist_quad_asctec_.linear.y/this->rollpitch_div_) - 0.0;
00447 
00448      
00449      this->error_(0)=this->twist_quad_asctec_.linear.x/this->rollpitch_div_- 0.0;
00450      
00451      
00452      this->error_(5)=this->ENUyaw_ - this->ENUyaw_fix_;
00453      
00455      this->error_(1)=0.0;
00456      this->error_(0)=0.0;
00457      this->error_(5)=0.0;
00458      this->tag_error_=this->error_;
00461      this->thrust_control_msg_.marker=false;
00462      this->roll_control_msg_.marker=false;
00463      this->pitch_control_msg_.marker=false;
00464      this->yaw_control_msg_.marker=false;
00465      
00466   }
00467   
00468   else if (!msg->markers.empty()){
00469     
00470     geometry_msgs::Pose pose;
00471     pose = msg->markers.back().pose.pose;
00472     
00473     ros::Time mt,mt_old;
00474     mt_old=mt;
00475     
00476     mt = msg->markers.back().header.stamp;
00477 
00478     
00479     if (this->init_){
00480       mt_old=mt;
00481       this->init_=false;
00482     }
00483      
00484     ros::Duration Ts;  
00485     Ts=mt-mt_old;
00486     
00487     double secs;
00488     secs=Ts.toSec();  
00489     
00490     if (this->activate_){
00491       
00492     
00493       
00494       
00495       tf::Transform tf_pose;
00496     
00497       tf::poseMsgToTF(pose, tf_pose);
00498       tf_pose.getBasis().getRPY(roll,pitch,yaw);
00499   
00500       
00501       R = Eigen::AngleAxisf(roll, Eigen::Vector3f::UnitZ()) \
00502           * Eigen::AngleAxisf(pitch, Eigen::Vector3f::UnitY()) \
00503           * Eigen::AngleAxisf(yaw, Eigen::Vector3f::UnitX());
00504 
00505       x = pose.position.x;
00506       y = pose.position.y;
00507       z = pose.position.z;
00508 
00509       Eigen::Matrix4f cTo(4,4);
00510     
00511       cTo.block(0,0,3,3)=R;  
00512       cTo.block(0,3,3,1) << x, y, z;
00513       cTo.row(3) << 0.0, 0.0, 0.0, 1.0;
00514     
00515       
00516       Eigen::MatrixXf V2(2,1);
00517       V2=Eigen::MatrixXf::Zero(2,1);
00518       if (this->quadrotor_){
00519         V2(0,0)=this->twist_quad_.angular.x;
00520         V2(1,0)=this->twist_quad_.angular.y; 
00521         
00522         
00523       }
00524     
00525       
00526       bool arm = false;
00527       KDL::Chain kdl_chain;
00528       Eigen::MatrixXf q;
00529       q=Eigen::MatrixXf::Zero(11,1);
00530       
00531   
00533         this->tag_error_(0)=0.0-y;
00534         this->tag_error_(1)=0.0-x;
00535         this->tag_error_(2)=z-this->final_z_;
00536         this->tag_error_(5)=0.0-yaw;
00537   
00538   
00540         uncalib_vs_alg_.uncalib_vs(this->traditional_,this->random_points_,this->quadrotor_,arm,this->output_files_,this->path_,this->lambda_,this->final_z_,cTo,secs,V2,kdl_chain,q,this->Rquad_inertial_,Vel_quad);
00541         
00542         this->error_=-Vel_quad/lambda_;         
00543   
00544     }
00545     
00546     if (this->serial_) {
00547       this->height_fix_=this->height_;
00548       this->ENUyaw_fix_=this->ENUyaw_;
00549     }
00550     
00551      this->thrust_control_msg_.marker=true;
00552      this->roll_control_msg_.marker=true;
00553      this->pitch_control_msg_.marker=true;
00554      this->yaw_control_msg_.marker=true;
00555 
00556   }
00557   
00559   tag_cmd_pid_thrust = this->tag_pid_thrust_.updatePid(this->tag_error_(2), this->time_ - this->time_last_);
00560   tag_cmd_pid_thrust=tag_cmd_pid_thrust+this->ctrl_ref_;
00561   if (tag_cmd_pid_thrust>this->sat_max_) tag_cmd_pid_thrust=this->sat_max_;
00562   if (tag_cmd_pid_thrust<this->sat_min_) tag_cmd_pid_thrust=this->sat_min_; 
00563   
00564   cmd_pid_thrust = this->pid_thrust_.updatePid(this->error_(2), this->time_ - this->time_last_);
00565   cmd_pid_thrust=cmd_pid_thrust+this->ctrl_ref_;
00566   if (cmd_pid_thrust>this->sat_max_) cmd_pid_thrust=this->sat_max_;
00567   if (cmd_pid_thrust<this->sat_min_) cmd_pid_thrust=this->sat_min_;
00568 
00569   this->thrust_control_msg_.name="Thrust";
00570   this->thrust_control_msg_.tag_error=this->tag_error_(2);
00571   this->thrust_control_msg_.tag_satured=tag_cmd_pid_thrust;
00572   this->thrust_control_msg_.uncal_error=this->error_(2);
00573   this->thrust_control_msg_.uncal_satured=cmd_pid_thrust;  
00574   
00575   if (calibrated_ctrl_) this->cmd_thrust_msg_.data=tag_cmd_pid_thrust;
00576   else this->cmd_thrust_msg_.data=cmd_pid_thrust;
00577   
00579   tag_cmd_pid_roll = this->tag_pid_roll_.updatePid(this->tag_error_(1), this->time_ - this->time_last_);
00580   tag_cmd_pid_roll=tag_cmd_pid_roll-this->trimm_y_;
00581   if (tag_cmd_pid_roll>this->rollpitch_sat_max_) tag_cmd_pid_roll=this->rollpitch_sat_max_;
00582   if (tag_cmd_pid_roll<this->rollpitch_sat_min_) tag_cmd_pid_roll=this->rollpitch_sat_min_;  
00583     
00584   cmd_pid_roll = this->pid_roll_.updatePid(this->error_(1), this->time_ - this->time_last_);
00585   cmd_pid_roll=cmd_pid_roll-this->trimm_y_;
00586   if (cmd_pid_roll>this->rollpitch_sat_max_) cmd_pid_roll=this->rollpitch_sat_max_;
00587   if (cmd_pid_roll<this->rollpitch_sat_min_) cmd_pid_roll=this->rollpitch_sat_min_;
00588 
00589   this->roll_control_msg_.name="Roll";
00590   this->roll_control_msg_.tag_error=this->tag_error_(1);
00591   this->roll_control_msg_.tag_satured=tag_cmd_pid_roll;
00592   this->roll_control_msg_.uncal_error=this->error_(1);
00593   this->roll_control_msg_.uncal_satured=cmd_pid_roll; 
00594   
00595   if (calibrated_ctrl_) this->cmd_roll_msg_.data=tag_cmd_pid_roll;
00596   else this->cmd_roll_msg_.data=cmd_pid_roll;
00597   
00599   tag_cmd_pid_pitch = this->tag_pid_pitch_.updatePid(this->tag_error_(0), this->time_ - this->time_last_);
00600   tag_cmd_pid_pitch=tag_cmd_pid_pitch-this->trimm_x_;
00601   if (tag_cmd_pid_pitch>this->rollpitch_sat_max_) tag_cmd_pid_pitch=this->rollpitch_sat_max_;
00602   if (tag_cmd_pid_pitch<this->rollpitch_sat_min_) tag_cmd_pid_pitch=this->rollpitch_sat_min_; 
00603   
00604   cmd_pid_pitch = this->pid_pitch_.updatePid(this->error_(0), this->time_ - this->time_last_);
00605   cmd_pid_pitch=cmd_pid_pitch-this->trimm_x_;
00606   if (cmd_pid_pitch>this->rollpitch_sat_max_) cmd_pid_pitch=this->rollpitch_sat_max_;
00607   if (cmd_pid_pitch<this->rollpitch_sat_min_) cmd_pid_pitch=this->rollpitch_sat_min_;
00608 
00609   this->pitch_control_msg_.name="Pitch";
00610   this->pitch_control_msg_.tag_error=this->tag_error_(0);
00611   this->pitch_control_msg_.tag_satured=tag_cmd_pid_pitch;
00612   this->pitch_control_msg_.uncal_error=this->error_(0);
00613   this->pitch_control_msg_.uncal_satured=cmd_pid_pitch;
00614   
00615   if (calibrated_ctrl_) this->cmd_pitch_msg_.data=tag_cmd_pid_pitch;
00616   else this->cmd_pitch_msg_.data=cmd_pid_pitch;
00617 
00619   tag_cmd_pid_yaw  = this->tag_pid_yaw_.updatePid(this->tag_error_(5), this->time_ - this->time_last_);
00620   if (tag_cmd_pid_yaw>yaw_sat_max_) tag_cmd_pid_yaw=yaw_sat_max_;
00621   if (tag_cmd_pid_yaw<yaw_sat_min_) tag_cmd_pid_yaw=yaw_sat_min_;
00622   
00623   cmd_pid_yaw = this->pid_yaw_.updatePid(-(this->error_(5)), this->time_ - this->time_last_);
00624   if (cmd_pid_yaw>yaw_sat_max_) cmd_pid_yaw=yaw_sat_max_;
00625   if (cmd_pid_yaw<yaw_sat_min_) cmd_pid_yaw=yaw_sat_min_;
00626 
00627   this->yaw_control_msg_.name="Yaw";
00628   this->yaw_control_msg_.tag_error=this->tag_error_(5);
00629   this->yaw_control_msg_.tag_satured=tag_cmd_pid_yaw;
00630   this->yaw_control_msg_.uncal_error=this->error_(5);
00631   this->yaw_control_msg_.uncal_satured=cmd_pid_yaw;
00632   
00633   if (calibrated_ctrl_) this->cmd_yaw_msg_.data=tag_cmd_pid_yaw; 
00634   else this->cmd_yaw_msg_.data=cmd_pid_yaw;  
00635   
00637   
00638   ros::Time stamp = ros::Time::now();
00639   this->Status_msg_.header.stamp=stamp;
00640 
00641   this->time_last_ = this->time_;
00642   
00643   
00644   this->alg_.unlock(); 
00645 
00646 }
00647 
00648 
00649 
00650 
00651 
00652 
00653 void UncalibvsAlgNode::node_config_update(Config &config, uint32_t level)
00654 {
00655   this->alg_.lock();
00656   
00657   this->activate_=config.activate;
00658   this->traditional_=config.traditional;
00659   this->lambda_=config.lambda;
00660   this->final_z_=config.final_z;
00661   this->random_points_=config.random_points;
00662   this->quadrotor_=config.quadrotor;
00663   this->output_files_=config.output_files;
00664   this->path_=config.path;
00665   this->tag_thrust_kp_=config.tag_thrust_kp;
00666   this->tag_thrust_kd_=config.tag_thrust_kd;
00667   this->tag_roll_kp_=config.tag_roll_kp;
00668   this->tag_roll_kd_=config.tag_roll_kd;
00669   this->tag_pitch_kp_=config.tag_pitch_kp;
00670   this->tag_pitch_kd_=config.tag_pitch_kd;
00671   this->tag_yaw_kp_=config.tag_yaw_kp;
00672   this->tag_yaw_kd_=config.tag_yaw_kd;   
00673   this->thrust_kp_=config.thrust_kp;
00674   this->thrust_kd_=config.thrust_kd;
00675   this->roll_kp_=config.roll_kp;
00676   this->roll_kd_=config.roll_kd;
00677   this->pitch_kp_=config.pitch_kp;
00678   this->pitch_kd_=config.pitch_kd;
00679   this->yaw_kp_=config.yaw_kp;
00680   this->yaw_kd_=config.yaw_kd;     
00681   this->sat_min_=config.thrust_sat_min;
00682   this->sat_max_=config.thrust_sat_max;
00683   this->ctrl_ref_=config.thrust_ctrl_ref;
00684   this->trimm_y_=config.trimm_y;
00685   this->trimm_x_=config.trimm_x;
00686   this->rollpitch_sat_min_=config.rollpitch_sat_min;
00687   this->rollpitch_sat_max_=config.rollpitch_sat_max;
00688   this->yaw_sat_min_=config.yaw_sat_min;
00689   this->yaw_sat_max_=config.yaw_sat_max;
00690   this->rollpitch_div_=config.rollpitch_div;
00691   this->buff_speed_=config.buff_speed;
00692   this->estop_=config.EMERGENCY_STOP;
00693   this->calibrated_ctrl_=config.calibrated_ctrl;
00694   
00695   
00696   
00697   this->tag_pid_thrust_.setGains(this->tag_thrust_kp_, 0, this->tag_thrust_kd_, 0, 0);
00698   this->pid_thrust_.setGains(this->thrust_kp_, 0, this->thrust_kd_, 0, 0);
00699     
00700   
00701   this->tag_pid_roll_.setGains(this->tag_roll_kp_, 0, this->tag_roll_kd_, 0, 0);
00702   this->pid_roll_.setGains(this->roll_kp_, 0, this->roll_kd_, 0, 0);
00703   
00704   
00705   this->tag_pid_pitch_.setGains(this->tag_pitch_kp_, 0, this->tag_pitch_kd_, 0, 0);  
00706   this->pid_pitch_.setGains(this->pitch_kp_, 0, this->pitch_kd_, 0, 0);
00707   
00708   
00709   this->tag_pid_yaw_.setGains(this->tag_yaw_kp_, 0, this->tag_yaw_kd_, 0, 0);  
00710   this->pid_yaw_.setGains(this->yaw_kp_, 0, this->yaw_kd_, 0, 0);
00711   
00712   this->alg_.unlock();
00713 }
00714 
00715 void UncalibvsAlgNode::addNodeDiagnostics(void)
00716 {
00717 }
00718 
00719 
00720 int main(int argc,char *argv[])
00721 {
00722 
00723   return algorithm_base::main<UncalibvsAlgNode>(argc, argv, "uncalibvs_alg_node");
00724 }