00001 #include "artag_pose_based_vs_alg_node.h"
00002
00003 ArtagPoseBasedVsAlgNode::ArtagPoseBasedVsAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<ArtagPoseBasedVsAlgorithm>()
00005 {
00006
00007 this->loop_rate_ = 100;
00008
00009
00010 this->current_pose_ = Eigen::MatrixXd::Zero(6,1);
00011 this->desired_pose_ = Eigen::MatrixXd::Zero(6,1);
00012 this->kp_ = Eigen::MatrixXd::Zero(6,1);
00013 this->kd_ = Eigen::MatrixXd::Zero(6,1);
00014 this->ki_ = Eigen::MatrixXd::Zero(6,1);
00015 this->cam_vel_ = Eigen::MatrixXd::Zero(6,1);
00016
00017
00018
00019 this->cmd_vel_cov_publisher_ = this->public_node_handle_.advertise<geometry_msgs::TwistWithCovariance>("cmd_vel_cov", 1);
00020 this->target_artag_publisher_ = this->public_node_handle_.advertise<ar_pose::ARMarkers>("target_artag", 1);
00021
00022
00023 this->input_ARtag_subscriber_ = this->public_node_handle_.subscribe("input_ARtag", 1, &ArtagPoseBasedVsAlgNode::input_ARtag_callback, this);
00024
00025
00026
00027
00028
00029
00030
00031
00032 }
00033
00034 ArtagPoseBasedVsAlgNode::~ArtagPoseBasedVsAlgNode(void)
00035 {
00036
00037 }
00038
00039 void ArtagPoseBasedVsAlgNode::mainNodeThread(void)
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049 }
00050
00051
00052 void ArtagPoseBasedVsAlgNode::input_ARtag_callback(const ar_pose::ARMarkers::ConstPtr& msg)
00053 {
00054
00055
00056
00057
00058 this->input_ARtag_mutex_.enter();
00059
00060 this->cam_vel_ = Eigen::MatrixXd::Zero(6,1);
00061
00062 if (msg->markers.empty()){
00063
00064 this->target_artag_msg_.markers.resize(0);
00065
00066
00067 this->TwistWC_msg_.covariance[0] =
00068 this->TwistWC_msg_.covariance[7] =
00069 this->TwistWC_msg_.covariance[14] =
00070 this->TwistWC_msg_.covariance[21] =
00071 this->TwistWC_msg_.covariance[28] =
00072 this->TwistWC_msg_.covariance[35] = 99999;
00073 }
00074 else if (!msg->markers.empty()){
00075
00076 this->time_last_ = this->time_;
00077
00078
00079 if ((!std::isnan(msg->markers[0].pose.pose.orientation.x) && std::isfinite(msg->markers[0].pose.pose.orientation.x)) || (!std::isnan(msg->markers[1].pose.pose.orientation.x) && std::isfinite(msg->markers[1].pose.pose.orientation.x)))
00080 {
00081
00082
00083 get_marker_info(msg);
00084
00085 if (this->current_pose_(2,0) > 0)
00086 {
00087 this->alg_.lock();
00088
00089 this->pose_based_vs_alg_.pose_based_vs(this->desired_pose_, this->current_pose_,this->dt_,
00090 this->kp_,this->kd_,this->ki_,
00091 this->i_lim_,this->cam_vel_);
00092 this->alg_.unlock();
00093 }
00094
00095
00096
00097 double cov = double(100-msg->markers.back().confidence)/100;
00098 this->TwistWC_msg_.covariance[0] =
00099 this->TwistWC_msg_.covariance[7] =
00100 this->TwistWC_msg_.covariance[14] =
00101 this->TwistWC_msg_.covariance[21] =
00102 this->TwistWC_msg_.covariance[28] =
00103 this->TwistWC_msg_.covariance[35] = cov;
00104 }
00105 else ROS_ERROR("Marker Reading error");
00106 }
00107
00108 this->TwistWC_msg_.twist.linear.x=this->cam_vel_(0,0);
00109 this->TwistWC_msg_.twist.linear.y=this->cam_vel_(1,0);
00110 this->TwistWC_msg_.twist.linear.z=this->cam_vel_(2,0);
00111 this->TwistWC_msg_.twist.angular.x=this->cam_vel_(3,0);
00112 this->TwistWC_msg_.twist.angular.y=this->cam_vel_(4,0);
00113 this->TwistWC_msg_.twist.angular.z=this->cam_vel_(5,0);
00114
00115
00116
00117
00118
00119
00120 this->cmd_vel_cov_publisher_.publish(this->TwistWC_msg_);
00121 this->target_artag_publisher_.publish(this->target_artag_msg_);
00122
00123 this->input_ARtag_mutex_.exit();
00124 }
00125
00126
00127
00128
00129
00130
00131
00132 void ArtagPoseBasedVsAlgNode::get_marker_info(const ar_pose::ARMarkers::ConstPtr& msg)
00133 {
00134
00135 if (1 < msg->markers.size()) {
00136 if (msg->markers[0].pose.pose.position.z<(this->desired_pose_(2,3)-0.24) || (this->fixed_to_id_==1))
00137 {
00138 this->pose_ = msg->markers[1].pose.pose;
00139 this->time_ = msg->markers[1].header.stamp;
00140 this->fixed_to_id_=1;
00141 }
00142 else if (msg->markers[0].pose.pose.position.z>(this->desired_pose_(2,3)-0.24))
00143 {
00144 this->pose_ = msg->markers[0].pose.pose;
00145 this->time_ = msg->markers[0].header.stamp;
00146 this->fixed_to_id_=0;
00147 }
00148 }
00149 else
00150 {
00151 this->pose_ = msg->markers.back().pose.pose;
00152 this->time_ = msg->markers.back().header.stamp;
00153 this->fixed_to_id_=msg->markers.back().id;
00154 }
00155
00156
00157
00158 if (this->init_)
00159 {
00160 this->time_last_=this->time_;
00161 this->init_=false;
00162 }
00163 this->dt_=(this->time_-this->time_last_).toSec();
00164
00165
00166 tf::Transform tf_pose;
00167 double roll,pitch,yaw;
00168 tf::poseMsgToTF(this->pose_, tf_pose);
00169 tf_pose.getBasis().getRPY(roll,pitch,yaw);
00170
00171 this->current_pose_(0,0) = this->pose_.position.x;
00172 this->current_pose_(1,0) = this->pose_.position.y;
00173 this->current_pose_(2,0) = this->pose_.position.z;
00174 this->current_pose_(3,0) = roll;
00175 this->current_pose_(4,0) = pitch;
00176 this->current_pose_(5,0) = yaw;
00177
00178
00179 this->target_artag_msg_.header = msg->header;
00180 this->target_artag_msg_.markers.resize(1);
00181 this->target_artag_msg_.markers[0] = msg->markers[this->fixed_to_id_];
00182 }
00183
00184
00185 void ArtagPoseBasedVsAlgNode::node_config_update(Config &config, uint32_t level)
00186 {
00187 this->alg_.lock();
00188
00189
00190
00191 this->desired_pose_(0,0) = config.desired_x;
00192 this->desired_pose_(1,0) = config.desired_y;
00193 this->desired_pose_(2,0) = config.desired_z;
00194 this->desired_pose_(3,0) = config.desired_roll-3.14159265359;
00195 this->desired_pose_(4,0) = config.desired_pitch;
00196 this->desired_pose_(5,0) = config.desired_yaw;
00197
00198 this->kp_(0,0) = config.kp_x;
00199 this->kd_(0,0) = config.kd_x;
00200 this->ki_(0,0) = config.ki_x;
00201 this->kp_(1,0) = config.kp_y;
00202 this->kd_(1,0) = config.kd_y;
00203 this->ki_(1,0) = config.ki_y;
00204 this->kp_(2,0) = config.kp_z;
00205 this->kd_(2,0) = config.kd_z;
00206 this->ki_(2,0) = config.ki_z;
00207 this->kp_(3,0) = config.kp_roll;
00208 this->kd_(3,0) = config.kd_roll;
00209 this->ki_(3,0) = config.ki_roll;
00210 this->kp_(4,0) = config.kp_pitch;
00211 this->kd_(4,0) = config.kd_pitch;
00212 this->ki_(4,0) = config.ki_pitch;
00213 this->kp_(5,0) = config.kp_yaw;
00214 this->kd_(5,0) = config.kd_yaw;
00215 this->ki_(5,0) = config.ki_yaw;
00216 this->i_lim_ = config.i_lim;
00217
00218 this->alg_.unlock();
00219 }
00220
00221 void ArtagPoseBasedVsAlgNode::addNodeDiagnostics(void)
00222 {
00223 }
00224
00225
00226 int main(int argc,char *argv[])
00227 {
00228 return algorithm_base::main<ArtagPoseBasedVsAlgNode>(argc, argv, "artag_pose_based_vs_alg_node");
00229 }