5 #ifndef SPIDAR_POSE_ESTIMATION_HPP 6 #define SPIDAR_POSE_ESTIMATION_HPP 12 #include "../math/Vector.hpp" 13 #include "../math/Matrix.hpp" 14 #include "../math/Cholesky.hpp" 33 typedef typename TraitsType::SpecType
SpecType;
39 typedef typename TraitsType::PoseType
PoseType;
40 typedef typename TraitsType::WireType
WireType;
46 PoseEstimation(
void) : initialized_(false), repeatCount_(64), sigma_(ValueType(0.001)) {};
55 const PoseType&
pose(
void)
const {
return pose_; }
58 const WireType&
wireVector(
void)
const {
return wireVector_; }
60 bool initialize(
const SpecType& spec, uint32_t frequency);
61 void calibrate(
const int32_t(&count)[MOTOR_COUNT]);
62 void estimate(
const int32_t (&count)[MOTOR_COUNT]);
65 void makeWireVector(
void);
66 void convertWireLength(
const int32_t (&count)[MOTOR_COUNT]);
72 ValueType controlFrequency_;
74 ValueType gripRadius_;
96 VectorFilterType velocityFilter_;
99 VectorFilterType angularVelocityFilter_;
115 const double PI = 3.14159265358979323846;
119 motorPosition_[i] = spec.motorPosition[i];
120 gripPosition_[i] = spec.gripPosition[i];
122 ValueType lengthPerCount =
static_cast<ValueType>(spec.pulleyRadius[i] * 2.0 * PI / spec.encoderResolution[i]);
124 lengthPerCount_[i] = lengthPerCount * spec.encoderDirection[i];
125 wireOffsetCount_[i] =
static_cast<long>((motorPosition_[i] - gripPosition_[i]).norm() / lengthPerCount_[i]);
128 gripRadius_ = spec.gripRadius;
131 double timeConstatnt = 0.008;
133 if (spec.majorLoopTimeConstant > 0) timeConstatnt = spec.majorLoopTimeConstant;
135 double deltaTime = 1.0 /
static_cast<ValueType>(frequency);
137 velocityFilter_.initialize(deltaTime, spec.majorLoopTimeConstant);
138 angularVelocityFilter_.initialize(deltaTime, spec.majorLoopTimeConstant);
142 deltaLengthFilter_[i].initialize(deltaTime, spec.majorLoopTimeConstant);
157 velocityFilter_.clear();
158 angularVelocityFilter_.clear();
162 deltaLengthFilter_[i].clear();
167 convertWireLength(count);
181 convertWireLength(count);
193 for (
size_t step=0; step<repeatCount_; ++step)
196 for (
int i=0; i<8; ++i)
198 a[0][i] = wireVector_.direction[i].x();
199 a[1][i] = wireVector_.direction[i].y();
200 a[2][i] = wireVector_.direction[i].z();
201 a[3][i] = wireVector_.moment[i].x();
202 a[4][i] = wireVector_.moment[i].y();
203 a[5][i] = wireVector_.moment[i].z();
205 deltaLength[i] = wireVector_.estimate[i] - wireVector_.measurement[i] - deltaLengthFilter_[i].value();
212 for(
int i=0; i<6; ++i)
215 for(
int k=0; k<8; ++k)
217 v[i] += a[i][k] * deltaLength[k];
230 deltaPosition[0] = v[0];
231 deltaPosition[1] = v[1];
232 deltaPosition[2] = v[2];
234 deltaRotation[0] = v[3];
235 deltaRotation[1] = v[4];
236 deltaRotation[2] = v[5];
239 if (deltaPosition.norm() > FLT_EPSILON)
241 pose_.position += deltaPosition;
244 if (deltaRotation.norm() > FLT_EPSILON)
246 pose_.rotation = (pose_.rotation.derivative(deltaRotation) + pose_.rotation).unit();
254 pose_.velocity = velocityFilter_.filter(pose_.position - prevPose.position) * controlFrequency_;
255 pose_.angularVelocity = angularVelocityFilter_.filter(pose_.rotation.angularVelocity(pose_.rotation - prevPose.rotation)) * controlFrequency_;
258 for (
size_t i=0; i<8; ++i)
260 deltaLengthFilter_[i].filter(wireVector_.estimate[i] - wireVector_.measurement[i]);
273 VectorType rotateGripPos = pose_.rotation.rotate(gripPosition_[i]);
279 wireVector_.estimate[i] = wireVector.norm();
282 wireVector_.direction[i] = wireVector / wireVector_.estimate[i];
285 wireVector_.moment[i] = rotateGripPos.cross(wireVector_.direction[i]);
298 wireVector_.measurement[i] = lengthPerCount_[i] * (wireOffsetCount_[i] + count[i]);
305 #endif // SPIDAR_POSE_ESTIMATION_HPP
TraitsType::ValueType ValueType
値の型
static const size_t MOTOR_COUNT
モータの数(=ワイヤの本数)
bool initialize(const SpecType &spec, uint32_t frequency)
初期化関数です.
TraitsType::QuaternionType QuaternionType
四元数の型
TraitsType::ValueFilterType ValueFilterType
値のためのローパスフィルタの型
TraitsType::WireType WireType
ワイヤベクトルの型
void estimate(const int32_t(&count)[MOTOR_COUNT])
グリップ姿勢の推定を行います.
姿勢推定を行い,ワイヤベクトルを計算するクラスです.
static void solve(MatrixType &mat, VectorType &vec)
コレスキー分解を用いて連立一次方程式を解きます.
TraitsType::VectorFilterType VectorFilterType
ベクトルのためのローパスフィルタの型
void calibrate(const int32_t(&count)[MOTOR_COUNT])
グリップ姿勢のキャリブレーションを行います.
TraitsType::VectorType VectorType
ベクトルの型
PoseEstimation(void)
コンストラクタ.
~PoseEstimation(void)
デストラクタ.
const WireType & wireVector(void) const
ワイヤベクトルを取得します.
TraitsType::SpecType SpecType
デバイス情報の型
TraitsType::PoseType PoseType
グリップ姿勢の型
const PoseType & pose(void) const
グリップ姿勢を取得します.
ValueType gripRadius(void) const
グリップ半径を取得します.