I am trying to read and compute the integral of two quantities, Linear speed and Angular speed. But for some reason, the orientation integral has a large offset, something of order of 6000000. Given that the loops are only called when the data is published (around 50Hz) and the size of the Imu-data is off the order of 0.05 the offset can't be drifting.
#include "ros/ros.h"
#include <sensor_msgs/Imu.h>
ros::Time current_time_;
ros::Time last_time_;
double rotation = 0;
double dt = 0;
void chatterCallback(const sensor_msgs::Imu::ConstPtr& scout_imu){
//data parsing
sensor_msgs::Imu imu_msg;
imu_msg = *scout_imu;
current_time_ = imu_msg.header.stamp;
//the step size
dt= (current_time_ - last_time_).toSec();
//integration
rotation =rotation + imu_msg.angular_velocity.z*dt;
ROS_INFO("rotation: [%f,%f,%f]",rotation,dt,imu_msg.angular_velocity.z);
last_time_ = current_time_;
}
int main(int argc, char **argv){
ros::init(argc, argv, "scout_subs");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/mavros/imu/data_raw", 1000, chatterCallback);
ros::spin();
return 0;
}
The reading part is ok. The problem is in the implementation of Integral. enter image description here