1 #ifndef RPYKALMANFILTER_H 2 #define RPYKALMANFILTER_H 6 #include "hrpsys/util/Hrpsys.h" 16 F(0,0) = 1; F(0,1) =-0.005;
17 F(1,0) = 0; F(1,1) = 1;
19 P(0,0) = 0; P(0,1) = 0;
20 P(1,0) = 0; P(1,1) = 0;
22 Q(0,0) = 0.001 * 0.005; Q(0,1) = 0.000 * 0.005;
23 Q(1,0) = 0.000 * 0.005; Q(1,1) = 0.003 * 0.005;
27 B(0) = 0.005;
B(1) = 0;
29 H(0,0) = 1; H(0,1) = 0;
34 I = hrp::dmatrix::Identity(2,2);
36 void setF(
const double _f0,
const double _f1,
const double _f2,
const double _f3) { F << _f0, _f1, _f2, _f3; };
37 void setP(
const double _p0,
const double _p1,
const double _p2,
const double _p3) { P << _p0, _p1, _p2, _p3; };
38 void setQ(
const double _q0,
const double _q1,
const double _q2,
const double _q3) { Q << _q0, _q1, _q2, _q3; };
39 void setR(
const double _R) {
R = _R; }
40 void setB(
const double _b0,
const double _b1) {
B << _b0, _b1; };
42 void update(
const double u,
const double _z) {
46 P = F * P * F.transpose() + Q;
52 double S = H * P * H.transpose() +
R;
54 K = P * H.transpose() / S;
65 Eigen::Matrix<double, 1, 2>
H;
84 double g = sqrt(acc(0) * acc(0) + acc(1) * acc(1) + acc(2) * acc(2));
87 b = atan2( - acc(0) / g, sqrt( acc(1)/g * acc(1)/g + acc(2)/g * acc(2)/g ) );
88 a = atan2( ( acc(1)/g ), ( acc(2)/g ) );
102 double roll = r_filter.getx()[0];
103 double pitch = p_filter.getx()[0];
104 double yaw = y_filter.getx()[0];
106 tmpMat << 1.0, sin(roll)*sin(pitch)/cos(pitch), cos(roll)*sin(pitch)/cos(pitch),
107 0, cos(roll), -sin(roll),
108 0, sin(roll)/cos(pitch), cos(roll)/cos(pitch);
109 gyro2 = tmpMat * gyro;
111 r_filter.update(gyro2(0), rpyRaw(0));
112 p_filter.update(gyro2(1), rpyRaw(1));
113 y_filter.update(gyro2(2), rpyRaw(2));
116 hrp::Matrix33 realRotationMatrix = imaginaryRotationMatrix * m_sensorR;
123 baseRpyCurrent(0) = euler2(0);
124 baseRpyCurrent(1) = euler2(1);
125 baseRpyCurrent(2) = euler2(2);
127 void setParam (
const double _dt,
const double _Q_angle,
const double _Q_rate,
const double _R_angle,
const std::string print_str =
"")
132 r_filter.setF(1, -_dt, 0, 1);
133 r_filter.setP(0, 0, 0, 0);
134 r_filter.setQ(Q_angle*_dt, 0, 0, Q_rate*_dt);
135 r_filter.setR(R_angle);
136 r_filter.setB(_dt, 0);
138 p_filter.setF(1, -_dt, 0, 1);
139 p_filter.setP(0, 0, 0, 0);
140 p_filter.setQ(Q_angle*_dt, 0, 0, Q_rate*_dt);
141 p_filter.setR(R_angle);
142 p_filter.setB(_dt, 0);
144 y_filter.setF(1, -_dt, 0, 1);
145 y_filter.setP(0, 0, 0, 0);
146 y_filter.setQ(Q_angle*_dt, 0, 0, Q_rate*_dt);
147 y_filter.setR(R_angle);
148 y_filter.setB(_dt, 0);
149 std::cerr <<
"[" << print_str <<
"] Q_angle=" << Q_angle <<
", Q_rate=" << Q_rate <<
", R_angle=" << R_angle << std::endl;
153 r_filter.resetStateByObservation();
154 p_filter.resetStateByObservation();
155 y_filter.resetStateByObservation();
160 double getRangle ()
const {
return R_angle;};
void resetKalmanFilterState()
OpenHRP::matrix33 Matrix33
Eigen::Matrix< double, 1, 2 > H
void setSensorR(const hrp::Matrix33 &sr)
void setB(const double _b0, const double _b1)
Matrix33 rotFromRpy(const Vector3 &rpy)
void resetStateByObservation()
void setParam(const double _dt, const double _Q_angle, const double _Q_rate, const double _R_angle, const std::string print_str="")
const hrp::Vector2 & getx()
void setR(const double _R)
void main_one(hrp::Vector3 &rpy, hrp::Vector3 &rpyRaw, hrp::Vector3 &baseRpyCurrent, const hrp::Vector3 &acc, const hrp::Vector3 &gyro, const double &sl_y, const hrp::Matrix33 &BtoS)
void update(const double u, const double _z)
HRP_UTIL_EXPORT Vector3 rpyFromRot(const Matrix33 &m)
void setP(const double _p0, const double _p1, const double _p2, const double _p3)
void setF(const double _f0, const double _f1, const double _f2, const double _f3)
void setQ(const double _q0, const double _q1, const double _q2, const double _q3)