19 #include <yarp/os/LogStream.h>
23 #include <yarp/os/Time.h>
27 using namespace yarp::os;
28 using namespace yarp::sig;
33 ImuFilter::ImuFilter(): gyroFilt(1,Vector(3,0.0)), magFilt(1,Vector(3,0.0)),
34 velEst(40,0.05), biasInt(0.0,Vector(3,0.0)),
46 Vector gyroFiltered, magn;
50 yError()<<
"imuFilter: the imu is not attached";
58 yError()<<
"imuFilter: unable to get gyro";
62 if (std::fabs(gyroTs - prevTs) < 1
e-6 ){
70 yError()<<
"imuFilter: unable to get magnetometer measures";
75 double t0=Time::now();
78 gyroFiltered = gyroFilt.
filt(gyro);
81 gyroFiltered -= gyroBias;
84 Vector mag_filt=magFilt.
filt(magn);
87 adaptGyroBias=adaptGyroBias?(magVel<mag_vel_thres_up):(magVel<mag_vel_thres_down);
88 gyroBias=biasInt.
integrate(adaptGyroBias?gyroFiltered:Vector(3,0.0));
89 double dt=Time::now()-t0;
91 if (bPort.getOutputCount()>0)
93 bPort.prepare()=gyroBias;
94 bPort.setEnvelope(stampBias);
100 yInfo(
"imuFilter: magVel = %g => [%s]",magVel,adaptGyroBias?
"adapt-gyroBias":
"no-adaption");
101 yInfo(
"imuFilter: gyro = %s",gyro.toString(3,3).c_str());
102 yInfo(
"imuFilter: gyroBias = %s",gyroBias.toString(3,3).c_str());
103 yInfo(
"imuFilter: dt = %.0f [us]",dt*1e6);
119 yError()<<
"ImuFilter: failed to open proxy device";
123 string name=config.check(
"name",Value(
"imuFilter")).asString();
124 string robot=config.check(
"robot",Value(
"icub")).asString();
125 size_t gyro_order=(size_t)config.check(
"gyro-order",Value(5)).asInt32();
126 size_t mag_order=(size_t)config.check(
"mag-order",Value(51)).asInt32();
128 mag_vel_thres_up=config.check(
"mag-vel-thres-up",Value(0.04)).asFloat64();
129 mag_vel_thres_down=config.check(
"mag-vel-thres-down",Value(0.02)).asFloat64();
130 bias_gain=config.check(
"bias-gain",Value(0.001)).asFloat64();
131 verbose=config.check(
"verbose");
135 biasInt.
setTs(bias_gain);
136 gyroBias.resize(3,0.0);
139 m_period_ms=config.check(
"period",Value(20)).asInt32();
141 if (name.at(0) !=
'/')
143 ok &= bPort.open(name+
"/bias:o");
145 this->setPeriod(m_period_ms / 1000.0);
148 yError()<<
"imuFilter: failed to open the bias port";
165 return this->start();
168 yError()<<
"imuFilter: attach failed";
173 this->PeriodicThread::stop();
181 yError() <<
"imuFilter: sens_index must be equal to 0 as there exists only one sensor";
Basic element for adaptive polynomial fitting.
yarp::sig::Vector estimate()
Execute the algorithm upon the elements list, with the max deviation threshold given by D.
const yarp::sig::Vector & integrate(const yarp::sig::Vector &x)
Executes one-step integration of input vector.
void setTs(const double _Ts)
Sets the sample time.
bool attachAll(const yarp::dev::PolyDriverList &p) override
bool detachAll() override
bool threadInit() override
bool open(yarp::os::Searchable &config) override
bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
void threadRelease() override
bool attachAll(const yarp::dev::PolyDriverList &p) override
yarp::dev::IThreeAxisGyroscopes * proxyIGyro
yarp::dev::IThreeAxisMagnetometers * proxyIMagn
bool open(yarp::os::Searchable &config) override
bool detachAll() override
double norm(const yarp::sig::Matrix &M, int col)
Returns the norm of the vector given in the form: matrix(:,col).
Copyright (C) 2008 RobotCub Consortium.