14 #include <dynamic-graph/factory.h> 22 namespace dg = ::dynamicgraph;
29 #define PROFILE_MADGWICKAHRS_COMPUTATION "MadgwickAHRS computation" 31 #define INPUT_SIGNALS m_accelerometerSIN << m_gyroscopeSIN 32 #define OUTPUT_SIGNALS m_imu_quatSOUT 49 m_gyroscopeSIN << m_accelerometerSIN),
50 m_initSucceeded(false),
63 "Timestep in seconds (double)")));
84 if (beta < 0.0 || beta > 1.0)
90 assert(imu_quat.size() == 4);
104 "Cannot compute signal imu_quat before initialization!");
114 accelerometer(0), accelerometer(1), accelerometer(2));
115 if (
s.size() != 4)
s.resize(4);
143 return (1.0 / sqrt(x));
148 double ax,
double ay,
double az) {
150 double s0, s1, s2, s3;
151 double qDot1, qDot2, qDot3, qDot4;
152 double o2q0, o2q1, o2q2, o2q3, o4q0, o4q1, o4q2, o8q1, o8q2;
153 double q0q0, q1q1, q2q2, q3q3;
163 if (!((ax == 0.0) && (ay == 0.0) && (az == 0.0))) {
165 recipNorm =
invSqrt(ax * ax + ay * ay + az * az);
186 s0 = o4q0 * q2q2 + o2q2 * ax + o4q0 * q1q1 - o2q1 * ay;
187 s1 = o4q1 * q3q3 - o2q3 * ax + 4.0 * q0q0 * m_q1 - o2q0 * ay - o4q1 +
188 o8q1 * q1q1 + o8q1 * q2q2 + o4q1 * az;
189 s2 = 4.0 * q0q0 * m_q2 + o2q0 * ax + o4q2 * q3q3 - o2q3 * ay - o4q2 +
190 o8q2 * q1q1 + o8q2 * q2q2 + o4q2 * az;
191 s3 = 4.0 * q1q1 * m_q3 - o2q1 * ax + 4.0 * q2q2 * m_q3 - o2q2 * ay;
192 if (!((s0 == 0.0) && (s1 == 0.0) && (s2 == 0.0) && (s3 == 0.0))) {
194 recipNorm =
invSqrt(s0 * s0 + s1 * s1 + s2 * s2 + s3 * s3);
215 recipNorm =
invSqrt(
m_q0 *
m_q0 + m_q1 * m_q1 + m_q2 * m_q2 + m_q3 * m_q3);
227 os <<
"MadgwickAHRS " <<
getName();
std::string docDirectGetter(const std::string &name, const std::string &type)
void set_imu_quat(const dynamicgraph::Vector &imu_quat)
Set the quaternion as [w,x,y,z].
DirectGetter< E, T > * makeDirectGetter(E &entity, T *ptr, const std::string &docString)
bool m_initSucceeded
true if the entity has been successfully initialized
void stop(std::string perf_name)
void madgwickAHRSupdateIMU(double gx, double gy, double gz, double ax, double ay, double az)
void signalRegistration(const SignalArray< int > &signals)
#define CONSTRUCT_SIGNAL_IN(name, type)
DEFINE_SIGNAL_OUT_FUNCTION(x_filtered, dynamicgraph::Vector)
CommandVoid1< E, T > * makeCommandVoid1(E &entity, boost::function< void(const T &)> function, const std::string &docString)
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
std::string docCommandVoid1(const std::string &doc, const std::string &type)
double m_q0
quaternion of sensor frame
FilterDifferentiator EntityClassName
void set_beta(const double &beta)
#define SEND_MSG(msg, type)
double m_sampleFreq
sample frequency in Hz
#define CONSTRUCT_SIGNAL_OUT(name, type, dep)
Stopwatch & getProfiler()
#define PROFILE_MADGWICKAHRS_COMPUTATION
void init(const double &dt)
const std::string & getName() const
double m_beta
2 * proportional gain (Kp)
#define SEND_WARNING_STREAM_MSG(msg)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW MadgwickAHRS(const std::string &name)
void start(std::string perf_name)
virtual void display(std::ostream &os) const
void addCommand(const std::string &name, command::Command *command)
void report_all(int precision=2, std::ostream &output=std::cout)