Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <hector_pose_estimation/state.h>
00030 #include <hector_pose_estimation/substate.h>
00031
00032 namespace hector_pose_estimation {
00033
00034 State::State()
00035 : vector_(Dimension)
00036 , covariance_(Dimension)
00037 , base_(new SubState_<0>(*this))
00038 {
00039 reset();
00040 }
00041
00042 State::State(const Vector &vector, const Covariance& covariance)
00043 : vector_(vector)
00044 , covariance_(covariance)
00045 , base_(new SubState_<0>(*this))
00046 {
00047 reset();
00048 }
00049
00050 State::~State()
00051 {
00052 }
00053
00054 void State::reset()
00055 {
00056
00057 vector_.setZero();
00058 covariance_.setZero();
00059 orientation().w() = 1.0;
00060
00061
00062 system_status_ = 0;
00063 measurement_status_ = 0;
00064
00065
00066 fake_rate_.resize(3,1);
00067 fake_rate_ << 0.0, 0.0, 0.0;
00068 fake_orientation_.resize(4,1);
00069 fake_orientation_ << 0.0, 0.0, 0.0, 1.0;
00070 fake_position_.resize(3,1);
00071 fake_position_ << 0.0, 0.0, 0.0;
00072 fake_velocity_.resize(3,1);
00073 fake_velocity_ << 0.0, 0.0, 0.0;
00074 fake_acceleration_.resize(3,1);
00075 fake_acceleration_ << 0.0, 0.0, 0.0;
00076 }
00077
00078 bool State::valid() const {
00079 return (vector_ == vector_);
00080 }
00081
00082 void State::updated()
00083 {
00084 normalize();
00085 P().symmetric();
00086 }
00087
00088 State::RotationMatrix State::getRotationMatrix() const {
00089 RotationMatrix R;
00090 getRotationMatrix(R);
00091 return R;
00092 }
00093
00094 void State::getRotationMatrix(RotationMatrix &R) const
00095 {
00096 ConstOrientationType q(getOrientation());
00097 R << (q.w()*q.w()+q.x()*q.x()-q.y()*q.y()-q.z()*q.z()), (2.0*q.x()*q.y()-2.0*q.w()*q.z()), (2.0*q.x()*q.z()+2.0*q.w()*q.y()),
00098 (2.0*q.x()*q.y()+2.0*q.w()*q.z()), (q.w()*q.w()-q.x()*q.x()+q.y()*q.y()-q.z()*q.z()), (2.0*q.y()*q.z()-2.0*q.w()*q.x()),
00099 (2.0*q.x()*q.z()-2.0*q.w()*q.y()), (2.0*q.y()*q.z()+2.0*q.w()*q.x()), (q.w()*q.w()-q.x()*q.x()-q.y()*q.y()+q.z()*q.z());
00100 }
00101
00102 double State::getYaw() const
00103 {
00104 ConstOrientationType q(getOrientation());
00105 return atan2(2*q.x()*q.y() + 2*q.w()*q.z(), q.x()*q.x() + q.w()*q.w() - q.z()*q.z() - q.y()*q.y());
00106 }
00107
00108 bool State::inSystemStatus(SystemStatus test_status) const {
00109 return (getSystemStatus() & test_status) == test_status;
00110 }
00111
00112 bool State::setSystemStatus(SystemStatus new_status) {
00113 if (new_status == system_status_) return true;
00114
00115
00116 for(std::vector<SystemStatusCallback>::const_iterator it = status_callbacks_.begin(); it != status_callbacks_.end(); ++it)
00117 if (!(*it)(new_status)) return false;
00118
00119 SystemStatus set = new_status & ~system_status_;
00120 SystemStatus cleared = system_status_ & ~new_status;
00121 if (set) ROS_INFO_STREAM("Set system status " << getSystemStatusString(new_status, set));
00122 if (cleared) ROS_INFO_STREAM("Cleared system status " << getSystemStatusString(cleared, cleared));
00123
00124 system_status_ = new_status;
00125 return true;
00126 }
00127
00128 bool State::setMeasurementStatus(SystemStatus new_measurement_status) {
00129 SystemStatus set = new_measurement_status & ~measurement_status_;
00130 SystemStatus cleared = measurement_status_ & ~new_measurement_status;
00131 if (set) ROS_INFO_STREAM("Set measurement status " << getSystemStatusString(new_measurement_status, set));
00132 if (cleared) ROS_INFO_STREAM("Cleared measurement status " << getSystemStatusString(cleared, cleared));
00133
00134 measurement_status_ = new_measurement_status;
00135 return true;
00136 }
00137
00138 bool State::updateSystemStatus(SystemStatus set, SystemStatus clear) {
00139 return setSystemStatus((system_status_ & ~clear) | set);
00140 }
00141
00142 bool State::updateMeasurementStatus(SystemStatus set, SystemStatus clear) {
00143 return setMeasurementStatus((measurement_status_ & ~clear) | set);
00144 }
00145
00146 void State::addSystemStatusCallback(const SystemStatusCallback& callback) {
00147
00148
00149 status_callbacks_.push_back(callback);
00150 }
00151
00152 double State::normalize() {
00153 double s = 1.0 / orientation().norm();
00154 orientation() = orientation() * s;
00155 return s;
00156 }
00157
00158 template class SubState_<0>;
00159
00160 }