ros-callback
REAL-LXJ opened this issue · 1 comments
I want to use ros callback to filter imu msg real time, but the result is not good.
double filter(double ax) { double axf; const float fs = 200; const float cutoff = 10; Iir::Butterworth::LowPass<4> lowpass; lowpass.setup(fs, cutoff); axf = lowpass.filter(ax); return axf; }
void imu_callback(const sensor_msgs::Imu &imu_msg) { double ax = imu_msg.linear_acceleration.x; double axf = filter(ax); std::cout << "ax = " << ax << std::endl; std::cout << "axf = " << axf << std::endl; }
You are creating a new filter instance at every time step and then calling the filter design at every time-step. This will wipe out the memory of the filter. You need to create the instance only once and call setup only once. Only lowpass.filter(ax) should be called in the callback. Hope you find the feedback useful. Sorry, won't have time to comment more on your code. Best of luck with the ROS coding.
Stating "the result is not good" is not helpful. For future reference always provide a reproducible test-case and a description what you'd expect and what is the actual result.