Go to the documentation of this file.00001 #include "covariance_markers_alg.h"
00002
00003 CovarianceMarkersAlgorithm::CovarianceMarkersAlgorithm():
00004 frame_id_("/teo/odom"),
00005 namespace_("/teo"),
00006 counter_(0),
00007 scale_multiplier_(2.0),
00008 scale_multiplier_z_(0.01),
00009 color_alpha_(0.5),
00010 color_red_(0.45),
00011 color_green_(0.95),
00012 color_blue_ (0.65)
00013 {
00014 }
00015
00016 CovarianceMarkersAlgorithm::~CovarianceMarkersAlgorithm()
00017 {
00018 }
00019
00020 void CovarianceMarkersAlgorithm::config_update(const Config& new_cfg, uint32_t level)
00021 {
00022 this->lock();
00023
00024
00025 config_ = new_cfg;
00026
00027 frame_id_ = config_.frame_id;
00028 namespace_ = config_.ns;
00029 scale_multiplier_ = config_.scale_multiplier;
00030 scale_multiplier_z_ = config_.scale_multiplier_z;
00031 color_alpha_ = config_.color_alpha;
00032 color_red_ = config_.color_red;
00033 color_green_ = config_.color_green;
00034 color_blue_ = config_.color_blue;
00035
00036 this->unlock();
00037 }
00038
00039
00040 void CovarianceMarkersAlgorithm::drawCovariance()
00041 {
00042 current_marker_.header.stamp = ros::Time::now();
00043 current_marker_.header.frame_id = frame_id_;
00044 current_marker_.header.seq = counter_++;
00045 current_marker_.ns = namespace_;
00046 current_marker_.id = counter_;
00047 current_marker_.type = visualization_msgs::Marker::SPHERE;
00048 current_marker_.action = visualization_msgs::Marker::ADD;
00049
00050 current_marker_.pose.position.x = odom_.pose.pose.position.x;
00051 current_marker_.pose.position.y = odom_.pose.pose.position.y;
00052 current_marker_.pose.position.z = odom_.pose.pose.position.z;
00053
00054 ROS_DEBUG("CovarianceMarkersAlgorithm::drawCovariance x: %f y: %f z: %f",
00055 odom_.pose.pose.position.x,
00056 odom_.pose.pose.position.y,
00057 odom_.pose.pose.position.z);
00058
00059 Eigen::Matrix3f covs;
00060 covs(0) = odom_.pose.covariance[0];
00061 covs(1) = odom_.pose.covariance[1];
00062 covs(2) = odom_.pose.covariance[2];
00063 covs(3) = odom_.pose.covariance[6];
00064 covs(4) = odom_.pose.covariance[7];
00065 covs(5) = odom_.pose.covariance[8];
00066 covs(6) = odom_.pose.covariance[12];
00067 covs(7) = odom_.pose.covariance[13];
00068 covs(8) = odom_.pose.covariance[14];
00069
00070 ROS_DEBUG("CovarianceMarkersAlgorithm::drawCovariance cov: %f %f %f %f",
00071 covs(0),covs(1),covs(2),covs(3));
00072
00073 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eig(covs);
00074
00075 const Eigen::Vector3f& eigValues (eig.eigenvalues());
00076 const Eigen::Matrix3f& eigVectors (eig.eigenvectors());
00077
00078
00079 float angle = (atan2(eigVectors(1, 0), eigVectors(0, 0)));
00080
00081 double length_x = sqrt(eigValues[0]);
00082 double length_y = sqrt(eigValues[1]);
00083 double length_z = sqrt(eigValues[2]);
00084
00085 ROS_DEBUG("CovarianceMarkersAlgorithm::drawCovariance lengths: %f %f %f",
00086 length_x,length_y,length_z);
00087
00088 current_marker_.scale.x = length_x*scale_multiplier_;
00089 current_marker_.scale.y = length_y*scale_multiplier_;
00090 current_marker_.scale.z = length_z*scale_multiplier_z_;
00091
00092 current_marker_.color.a = color_alpha_;
00093 current_marker_.color.r = color_red_;
00094 current_marker_.color.g = color_green_;
00095 current_marker_.color.b = color_blue_;
00096
00097 current_marker_.pose.orientation.w = cos(angle*0.5);
00098 current_marker_.pose.orientation.z = sin(angle*0.5);
00099
00100 marker_array_.markers.push_back(current_marker_);
00101 }
00102
00103 visualization_msgs::MarkerArray CovarianceMarkersAlgorithm::marker_array()
00104 {
00105 return marker_array_;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162