delta_computations.cpp
Go to the documentation of this file.
1 //
2 // Created by leutrim on 16/05/18.
3 //
4 
5 //
6 // Created by leutrim on 16/05/18.
7 //
8 #include <ros/ros.h>
9 #include <sensor_msgs/Imu.h>
10 
11 static bool init_gyro = false;
12 static bool init_acc = false;
13 
14 void gyro_cb(const sensor_msgs::ImuConstPtr &gyro_in)
15 {
16  double dth_x, dth_y, dth_z;
17  static ros::Time last_gyro;
18 
19  if (!init_gyro)
20  {
21  init_gyro = true;
22  last_gyro = gyro_in->header.stamp;
23  return;
24  }
25 
26 
27  double sampling_time = (gyro_in->header.stamp - last_gyro).toSec();
28 
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;
32 
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;
39 
40  last_gyro = gyro_in->header.stamp;
41 }
42 
43 void acc_cb(const sensor_msgs::ImuConstPtr &acc_in)
44 {
45  double dv_x, dv_y, dv_z;
46  static ros::Time last_acc;
47 
48  if (!init_acc)
49  {
50  init_acc = true;
51  last_acc = acc_in->header.stamp;
52  return;
53  }
54 
55 
56  double sampling_time = (acc_in->header.stamp - last_acc).toSec();
57 
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;
61 
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;
68 
69  last_acc = acc_in->header.stamp;
70 }
71 
72 int main(int argc, char **argv)
73 {
74  ros::init(argc, argv, "dmu");
75  ros::NodeHandle nh;
76 
77  ros::Subscriber gyro_sub = nh.subscribe("/imu/data_raw_gyro", 10, gyro_cb);
78  ros::Subscriber acc_sub = nh.subscribe("/imu/data_raw_acc", 10, acc_cb);
79 
80  while (ros::ok())
81  ros::spin();
82 
83  return 0;
84 }
static bool init_gyro
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static bool init_acc
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
ROSCPP_DECL bool ok()
void acc_cb(const sensor_msgs::ImuConstPtr &acc_in)
int main(int argc, char **argv)
void gyro_cb(const sensor_msgs::ImuConstPtr &gyro_in)


dmu_ros
Author(s): Leutrim Gruda
autogenerated on Mon Jun 10 2019 13:05:49