9 #include <sensor_msgs/Imu.h> 14 void gyro_cb(
const sensor_msgs::ImuConstPtr &gyro_in)
16 double dth_x, dth_y, dth_z;
22 last_gyro = gyro_in->header.stamp;
27 double sampling_time = (gyro_in->header.stamp - last_gyro).toSec();
29 dth_x = (gyro_in->linear_acceleration.x * 180 / M_PI) * sampling_time;
30 dth_y = (gyro_in->linear_acceleration.y * 180 / M_PI) * sampling_time;
31 dth_z = (gyro_in->linear_acceleration.z * 180 / M_PI) * sampling_time;
33 std::cout <<
"Delta Theta X: " << gyro_in->angular_velocity.x * 180 / M_PI
34 <<
" Delta Theta Y: " << gyro_in->angular_velocity.y * 180 / M_PI
35 <<
" Delta Theta Z: " << gyro_in->angular_velocity.z * 180 / M_PI << std::endl;
36 std::cout <<
"Delta Computed Theta X: " << dth_x
37 <<
" Delta Computed Theta Y: " << dth_y
38 <<
" Delta Computed Theta Z: " << dth_z << std::endl << std::endl;
40 last_gyro = gyro_in->header.stamp;
43 void acc_cb(
const sensor_msgs::ImuConstPtr &acc_in)
45 double dv_x, dv_y, dv_z;
51 last_acc = acc_in->header.stamp;
56 double sampling_time = (acc_in->header.stamp - last_acc).toSec();
58 dv_x = acc_in->linear_acceleration.x * sampling_time;
59 dv_y = acc_in->linear_acceleration.y * sampling_time;
60 dv_z = acc_in->linear_acceleration.z * sampling_time;
62 std::cout <<
"Delta Velocity X: " << acc_in->angular_velocity.x
63 <<
" Delta Velocity Y: " << acc_in->angular_velocity.y
64 <<
" Delta Velocity Z: " << acc_in->angular_velocity.z << std::endl;
65 std::cout <<
"Delta Computed Velocity X: " << dv_x
66 <<
" Delta Computed Velocity Y: " << dv_y
67 <<
" Delta Computed Velocity Z: " << dv_z << std::endl << std::endl;
69 last_acc = acc_in->header.stamp;
72 int main(
int argc,
char **argv)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
void acc_cb(const sensor_msgs::ImuConstPtr &acc_in)
int main(int argc, char **argv)
void gyro_cb(const sensor_msgs::ImuConstPtr &gyro_in)