time_monitor.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * Copyright 2015-2019 Autoware Foundation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* ----header---- */
  17. /* common header */
  18. #include "ros/ros.h"
  19. #include <sstream>
  20. #include <vector>
  21. #include <boost/circular_buffer.hpp>
  22. #include "std_msgs/Time.h"
  23. /* user header */
  24. #include "sensor_msgs/Image.h"
  25. #include "sensor_msgs/PointCloud2.h"
  26. #include "geometry_msgs/PoseStamped.h"
  27. #include "visualization_msgs/MarkerArray.h"
  28. #include "autoware_msgs/ImageObj.h"
  29. #include "autoware_msgs/PointsImage.h"
  30. #include "autoware_msgs/ImageObjRanged.h"
  31. #include "autoware_msgs/ImageObjTracked.h"
  32. #include "autoware_msgs/ObjLabel.h"
  33. #include "autoware_msgs/Centroids.h"
  34. #include "autoware_msgs/SyncTimeMonitor.h"
  35. #include "autoware_msgs/SyncTimeDiff.h"
  36. /* ----var---- */
  37. /* common var */
  38. /* user var */
  39. class KeyPair
  40. {
  41. boost::circular_buffer<ros::Time> sensor;
  42. boost::circular_buffer<ros::Time> execution;
  43. public:
  44. KeyPair() {
  45. sensor.resize(1);
  46. execution.resize(1);
  47. }
  48. void resize(int size) {
  49. sensor.resize(size);
  50. execution.resize(size);
  51. }
  52. void push_front(ros::Time sensor_time, ros::Time execution_time) {
  53. sensor.push_front(sensor_time);
  54. execution.push_front(execution_time);
  55. }
  56. ros::Time front(void) {
  57. return execution.front();
  58. }
  59. ros::Time find(ros::Time sensor_time) {
  60. boost::circular_buffer<ros::Time>::iterator it = sensor.begin();
  61. for (int i = 0; it != sensor.end(); it++, i++) {
  62. if (it->sec == sensor_time.sec && it->nsec == sensor_time.nsec) {
  63. return execution.at(i); // find
  64. }
  65. }
  66. ROS_ERROR("error:not found a pair");
  67. ros::Time failed;
  68. failed.sec = 0;
  69. failed.nsec = 0;
  70. return failed; // not find
  71. }
  72. };
  73. class TimeManager
  74. {
  75. /*
  76. * KeyPair
  77. */
  78. KeyPair image_raw_;
  79. KeyPair points_raw_;
  80. KeyPair points_image_;
  81. KeyPair vscan_points_;
  82. KeyPair vscan_image_;
  83. KeyPair image_obj_;
  84. KeyPair image_obj_ranged_;
  85. KeyPair image_obj_tracked_;
  86. KeyPair current_pose_;
  87. KeyPair obj_label_;
  88. KeyPair cluster_centroids_;
  89. KeyPair obj_pose_;
  90. // sync
  91. KeyPair sync_image_obj_ranged_;
  92. KeyPair sync_image_obj_tracked_;
  93. KeyPair sync_obj_label_;
  94. KeyPair sync_obj_pose_;
  95. // time difference
  96. KeyPair time_diff_;
  97. /*
  98. * Nodehandle, Subscriber, Publisher
  99. */
  100. // Nodehandle
  101. ros::NodeHandle nh;
  102. // Subscriber
  103. ros::Subscriber image_raw_sub;
  104. ros::Subscriber points_raw_sub;
  105. ros::Subscriber points_image_sub;
  106. ros::Subscriber vscan_points_sub;
  107. ros::Subscriber vscan_image_sub;
  108. ros::Subscriber image_obj_sub;
  109. ros::Subscriber image_obj_ranged_sub;
  110. ros::Subscriber image_obj_tracked_sub;
  111. ros::Subscriber current_pose_sub;
  112. ros::Subscriber obj_label_sub;
  113. ros::Subscriber cluster_centroids_sub;
  114. ros::Subscriber obj_pose_sub;
  115. ros::Subscriber time_diff_sub;
  116. ros::Subscriber sync_image_obj_ranged_sub; // sync
  117. ros::Subscriber sync_image_obj_tracked_sub; // sync
  118. ros::Subscriber sync_obj_label_sub; // sync
  119. ros::Subscriber sync_obj_pose_sub; // sync
  120. // Publisher
  121. ros::Publisher time_monitor_pub;
  122. bool is_points_image_;
  123. bool is_vscan_image_;
  124. ros::Time get_walltime_now() {
  125. ros::WallTime non_sim_current_time = ros::WallTime::now();
  126. ros::Time casted_time;
  127. casted_time.sec = non_sim_current_time.sec;
  128. casted_time.nsec = non_sim_current_time.nsec;
  129. return casted_time;
  130. }
  131. double ros_time2msec(ros::Time time) {
  132. return (double)time.sec*1000L + (double)time.nsec/1000000L;
  133. }
  134. double time_diff(ros::Time sensor_time, ros::Time execution_time) {
  135. if (execution_time.sec == 0 && execution_time.nsec == 0) { // not find
  136. ROS_ERROR("error:execution time is 0");
  137. return 0.0;
  138. }
  139. if (sensor_time.sec == 0 && sensor_time.nsec == 0) { // not find
  140. ROS_ERROR("error:execution time is 0");
  141. return 0.0;
  142. }
  143. double time_diff = ros_time2msec(execution_time) - ros_time2msec(sensor_time);
  144. if (time_diff >= 0)
  145. return time_diff;
  146. else
  147. ROS_ERROR("error:time difference is less than 0");
  148. return 0.0;
  149. }
  150. public:
  151. TimeManager(int);
  152. void image_raw_callback(const sensor_msgs::Image::ConstPtr& image_raw_msg);
  153. void points_raw_callback(const sensor_msgs::PointCloud2::ConstPtr& points_raw_msg);
  154. void points_image_callback(const autoware_msgs::PointsImage::ConstPtr& points_image_msg);
  155. void vscan_points_callback(const sensor_msgs::PointCloud2::ConstPtr& vscan_points_msg);
  156. void vscan_image_callback(const autoware_msgs::PointsImage::ConstPtr& vscan_image_msg);
  157. void image_obj_callback(const autoware_msgs::ImageObj::ConstPtr& image_obj_msg);
  158. void image_obj_ranged_callback(const autoware_msgs::ImageObjRanged::ConstPtr& image_obj_ranged_msg);
  159. void image_obj_tracked_callback(const autoware_msgs::ImageObjTracked::ConstPtr& image_obj_tracked_msg);
  160. void current_pose_callback(const geometry_msgs::PoseStamped::ConstPtr& current_pose_msg);
  161. void obj_label_callback(const autoware_msgs::ObjLabel::ConstPtr& obj_label_msg) ;
  162. void cluster_centroids_callback(const autoware_msgs::Centroids::ConstPtr& cluster_centroids_msg);
  163. // void obj_pose_callback(const visualization_msgs::MarkerArray::ConstPtr& obj_pose_msg);
  164. void obj_pose_callback(const std_msgs::Time::ConstPtr& obj_pose_timestamp_msg);
  165. // sync
  166. void sync_image_obj_ranged_callback(const autoware_msgs::ImageObj::ConstPtr& sync_image_obj_msg);
  167. void sync_image_obj_tracked_callback(const autoware_msgs::ImageObjRanged::ConstPtr& sync_image_obj_ranged_msg);
  168. void sync_obj_label_callback(const autoware_msgs::ImageObjTracked::ConstPtr& sync_image_obj_tracked_msg);
  169. void sync_obj_pose_callback(const autoware_msgs::ObjLabel::ConstPtr& sync_obj_label_msg);
  170. // time difference
  171. void time_diff_callback(const autoware_msgs::SyncTimeDiff::ConstPtr& time_diff_msg);
  172. void run();
  173. };
  174. TimeManager::TimeManager(int buffer_size) {
  175. ros::NodeHandle private_nh("~");
  176. private_nh.param("is_points_image", is_points_image_, true);
  177. private_nh.param("is_vscan_image", is_vscan_image_, false);
  178. if (is_vscan_image_ == is_points_image_) {
  179. ROS_ERROR("choose is_points_image or is_vscan_image");
  180. is_points_image_ = true;
  181. is_vscan_image_ = false;
  182. }
  183. time_monitor_pub = nh.advertise<autoware_msgs::SyncTimeMonitor> ("/times", 10);
  184. image_raw_sub = nh.subscribe("/sync_drivers/image_raw", 10, &TimeManager::image_raw_callback, this);
  185. points_raw_sub = nh.subscribe("/sync_drivers/points_raw", 10, &TimeManager::points_raw_callback, this);
  186. points_image_sub = nh.subscribe("/points_image", 10, &TimeManager::points_image_callback, this);
  187. vscan_points_sub = nh.subscribe("/vscan_points", 10, &TimeManager::vscan_points_callback, this);
  188. vscan_image_sub = nh.subscribe("/vscan_image", 10, &TimeManager::vscan_image_callback, this);
  189. image_obj_sub = nh.subscribe("/image_obj", 10, &TimeManager::image_obj_callback, this);
  190. image_obj_ranged_sub = nh.subscribe("/image_obj_ranged", 10, &TimeManager::image_obj_ranged_callback, this);
  191. image_obj_tracked_sub = nh.subscribe("/image_obj_tracked", 10, &TimeManager::image_obj_tracked_callback, this);
  192. current_pose_sub = nh.subscribe("/current_pose", 10, &TimeManager::current_pose_callback, this);
  193. obj_label_sub = nh.subscribe("/obj_label", 10, &TimeManager::obj_label_callback, this);
  194. cluster_centroids_sub = nh.subscribe("/cluster_centroids", 10, &TimeManager::cluster_centroids_callback, this);
  195. obj_pose_sub = nh.subscribe("/obj_pose_timestamp", 10, &TimeManager::obj_pose_callback, this);
  196. // obj_pose_sub = nh.subscribe("/obj_car/obj_pose", 10, &TimeManager::obj_pose_callback, this);
  197. // sync
  198. sync_image_obj_ranged_sub = nh.subscribe("/sync_ranging/image_obj", 10 , &TimeManager::sync_image_obj_ranged_callback, this);
  199. sync_image_obj_tracked_sub = nh.subscribe("/sync_tracking/image_obj_ranged", 10, &TimeManager::sync_image_obj_tracked_callback, this);
  200. sync_obj_label_sub = nh.subscribe("/sync_reprojection/image_obj_tracked", 10, &TimeManager::sync_obj_label_callback, this);
  201. sync_obj_pose_sub = nh.subscribe("/sync_obj_fusion/obj_label", 10, &TimeManager::sync_obj_pose_callback, this);
  202. // time difference
  203. time_diff_sub = nh.subscribe("/time_difference", 10, &TimeManager::time_diff_callback, this);
  204. image_raw_.resize(buffer_size);
  205. points_raw_.resize(buffer_size);
  206. points_image_.resize(buffer_size);
  207. vscan_points_.resize(buffer_size);
  208. vscan_image_.resize(buffer_size);
  209. image_obj_.resize(buffer_size);
  210. image_obj_ranged_.resize(buffer_size);
  211. image_obj_tracked_.resize(buffer_size);
  212. current_pose_.resize(buffer_size);
  213. obj_label_.resize(buffer_size);
  214. obj_pose_.resize(buffer_size);
  215. cluster_centroids_.resize(buffer_size);
  216. sync_image_obj_ranged_.resize(buffer_size);
  217. sync_image_obj_tracked_.resize(buffer_size);
  218. sync_obj_label_.resize(buffer_size);
  219. sync_obj_pose_.resize(buffer_size);
  220. time_diff_.resize(buffer_size);
  221. }
  222. void TimeManager::image_raw_callback(const sensor_msgs::Image::ConstPtr& image_raw_msg) {
  223. // ROS_INFO("image_raw: \t\t\t%d.%d", image_raw_msg->header.stamp.sec, image_raw_msg->header.stamp.nsec);
  224. image_raw_.push_front(image_raw_msg->header.stamp, get_walltime_now());
  225. }
  226. void TimeManager::points_raw_callback(const sensor_msgs::PointCloud2::ConstPtr& points_raw_msg) {
  227. // ROS_INFO("points_raw: \t\t\t%d.%d", points_raw_msg->header.stamp.sec, points_raw_msg->header.stamp.nsec);
  228. points_raw_.push_front(points_raw_msg->header.stamp, get_walltime_now());
  229. }
  230. void TimeManager::points_image_callback(const autoware_msgs::PointsImage::ConstPtr& points_image_msg) {
  231. // ROS_INFO("vscan_image: \t\t\t%d.%d", vscan_image_msg->header.stamp.sec, vscan_image_msg->header.stamp.nsec);
  232. points_image_.push_front(points_image_msg->header.stamp, get_walltime_now());
  233. }
  234. void TimeManager::vscan_points_callback(const sensor_msgs::PointCloud2::ConstPtr& vscan_points_msg) {
  235. // ROS_INFO("vscan_points: \t\t\t%d.%d", vscan_points_msg->header.stamp.sec, vscan_points_msg->header.stamp.nsec);
  236. vscan_points_.push_front(vscan_points_msg->header.stamp, get_walltime_now());
  237. }
  238. void TimeManager::vscan_image_callback(const autoware_msgs::PointsImage::ConstPtr& vscan_image_msg) {
  239. // ROS_INFO("vscan_image: \t\t\t%d.%d", vscan_image_msg->header.stamp.sec, vscan_image_msg->header.stamp.nsec);
  240. vscan_image_.push_front(vscan_image_msg->header.stamp, get_walltime_now());
  241. }
  242. void TimeManager::image_obj_callback(const autoware_msgs::ImageObj::ConstPtr& image_obj_msg) {
  243. // ROS_INFO("image_obj: \t\t\t%d.%d", image_obj_msg->header.stamp.sec, image_obj_msg->header.stamp.nsec);
  244. image_obj_.push_front(image_obj_msg->header.stamp, get_walltime_now());
  245. }
  246. void TimeManager::image_obj_ranged_callback(const autoware_msgs::ImageObjRanged::ConstPtr& image_obj_ranged_msg) {
  247. // ROS_INFO("image_obj_ranged: \t\t%d.%d", image_obj_ranged_msg->header.stamp.sec, image_obj_ranged_msg->header.stamp.nsec);
  248. image_obj_ranged_.push_front(image_obj_ranged_msg->header.stamp, get_walltime_now());
  249. }
  250. void TimeManager::image_obj_tracked_callback(const autoware_msgs::ImageObjTracked::ConstPtr& image_obj_tracked_msg) {
  251. // ROS_INFO("image_obj_tracked: \t\t%d.%d", image_obj_tracked_msg->header.stamp.sec, image_obj_tracked_msg->header.stamp.nsec);
  252. image_obj_tracked_.push_front(image_obj_tracked_msg->header.stamp, get_walltime_now());
  253. }
  254. void TimeManager::current_pose_callback(const geometry_msgs::PoseStamped::ConstPtr& current_pose_msg) {
  255. // ROS_INFO("current_pose: \t\t\t%d.%d", current_pose_msg->header.stamp.sec, current_pose_msg->header.stamp.nsec);
  256. current_pose_.push_front(current_pose_msg->header.stamp, get_walltime_now());
  257. }
  258. void TimeManager::obj_label_callback(const autoware_msgs::ObjLabel::ConstPtr& obj_label_msg) {
  259. // ROS_INFO("obj_label: \t\t\t%d.%d", obj_label_msg->header.stamp.sec, obj_label_msg->header.stamp.nsec);
  260. obj_label_.push_front(obj_label_msg->header.stamp, get_walltime_now());
  261. }
  262. void TimeManager::cluster_centroids_callback(const autoware_msgs::Centroids::ConstPtr& cluster_centroids_msg) {
  263. // ROS_INFO("cluster_centroids: \t\t%d.%d", cluster_centroids_msg->header.stamp.sec, cluster_centroids_msg->header.stamp.nsec);
  264. cluster_centroids_.push_front(cluster_centroids_msg->header.stamp, get_walltime_now());
  265. }
  266. /* sync */
  267. void TimeManager::sync_image_obj_ranged_callback(const autoware_msgs::ImageObj::ConstPtr& sync_image_obj_msg) {
  268. // ROS_INFO("sync_image_obj_ranged: \t\t%d.%d", sync_image_obj_msg->header.stamp.sec, sync_image_obj_msg->header.stamp.nsec);
  269. sync_image_obj_ranged_.push_front(sync_image_obj_msg->header.stamp, get_walltime_now());
  270. }
  271. void TimeManager::sync_image_obj_tracked_callback(const autoware_msgs::ImageObjRanged::ConstPtr& sync_image_obj_ranged_msg) {
  272. // ROS_INFO("sync_image_obj_tracked: \t%d.%d", sync_image_obj_ranged_msg->header.stamp.sec, sync_image_obj_ranged_msg->header.stamp.nsec);
  273. sync_image_obj_tracked_.push_front(sync_image_obj_ranged_msg->header.stamp, get_walltime_now());
  274. }
  275. void TimeManager::sync_obj_label_callback(const autoware_msgs::ImageObjTracked::ConstPtr& sync_image_obj_tracked_msg) {
  276. // ROS_INFO("sync_obj_label: \t\t%d.%d", sync_image_obj_tracked_msg->header.stamp.sec, sync_image_obj_tracked_msg->header.stamp.nsec);
  277. sync_obj_label_.push_front(sync_image_obj_tracked_msg->header.stamp, get_walltime_now());
  278. }
  279. void TimeManager::sync_obj_pose_callback(const autoware_msgs::ObjLabel::ConstPtr& sync_obj_label_msg) {
  280. // ROS_INFO("sync_obj_pose: \t\t\t%d.%d", sync_obj_label_msg->header.stamp.sec, sync_obj_label_msg->header.stamp.nsec);
  281. sync_obj_pose_.push_front(sync_obj_label_msg->header.stamp, get_walltime_now());
  282. }
  283. /* time difference */
  284. void TimeManager::time_diff_callback(const autoware_msgs::SyncTimeDiff::ConstPtr& time_diff_msg) {
  285. ros::Time sensors_time_diff;
  286. double lidar = (double)time_diff_msg->lidar.sec + (double)time_diff_msg->lidar.nsec/1000000000.0L;
  287. double camera = (double)time_diff_msg->camera.sec + (double)time_diff_msg->camera.nsec/1000000000.0L;
  288. if (time_diff_msg->lidar.sec > time_diff_msg->camera.sec) {
  289. sensors_time_diff.sec = time_diff_msg->lidar.sec - time_diff_msg->camera.sec;
  290. if (time_diff_msg->lidar.nsec >= time_diff_msg->camera.nsec) {
  291. sensors_time_diff.nsec = time_diff_msg->lidar.nsec - time_diff_msg->camera.nsec;
  292. } else {
  293. sensors_time_diff.sec -= 1;
  294. sensors_time_diff.nsec = 1000000000L + time_diff_msg->lidar.nsec - time_diff_msg->camera.nsec;
  295. }
  296. } else if (time_diff_msg->lidar.sec < time_diff_msg->camera.sec) {
  297. sensors_time_diff.sec = time_diff_msg->camera.sec - time_diff_msg->lidar.sec;
  298. if (time_diff_msg->camera.nsec >= time_diff_msg->lidar.nsec) {
  299. sensors_time_diff.nsec = time_diff_msg->camera.nsec - time_diff_msg->lidar.nsec;
  300. } else {
  301. sensors_time_diff.sec -= 1;
  302. sensors_time_diff.nsec = 1000000000L + time_diff_msg->camera.nsec - time_diff_msg->lidar.nsec;
  303. }
  304. } else if (time_diff_msg->lidar.sec == time_diff_msg->camera.sec) {
  305. sensors_time_diff.sec = 0;
  306. if (time_diff_msg->lidar.nsec >= time_diff_msg->camera.nsec) {
  307. sensors_time_diff.nsec = time_diff_msg->lidar.nsec - time_diff_msg->camera.nsec;
  308. } else {
  309. sensors_time_diff.nsec = time_diff_msg->camera.nsec - time_diff_msg->lidar.nsec;
  310. }
  311. } else {
  312. // not impl
  313. ROS_ERROR("Exception error");
  314. }
  315. time_diff_.push_front(time_diff_msg->header.stamp, sensors_time_diff);
  316. }
  317. void TimeManager::obj_pose_callback(const std_msgs::Time::ConstPtr& obj_pose_timestamp_msg) {
  318. // ROS_INFO("obj_pose: \t\t\t%d.%d", obj_pose_timestamp_msg->data.sec, obj_pose_timestamp_msg->data.nsec);
  319. obj_pose_.push_front(obj_pose_timestamp_msg->data, get_walltime_now());
  320. static ros::Time pre_sensor_time;
  321. autoware_msgs::SyncTimeMonitor time_monitor_msg;
  322. time_monitor_msg.header.frame_id = "0";
  323. time_monitor_msg.header.stamp = ros::Time::now();
  324. // ROS_INFO("-------------------------------------");
  325. // ROS_INFO("image_raw");
  326. if (!ros::Time::isSimTime()) {
  327. time_monitor_msg.image_raw = time_diff(obj_pose_timestamp_msg->data,
  328. image_raw_.find(obj_pose_timestamp_msg->data));
  329. } else {
  330. time_monitor_msg.image_raw = 0;
  331. }
  332. // ROS_INFO("points_raw");
  333. if (!ros::Time::isSimTime()) {
  334. time_monitor_msg.points_raw = time_diff(obj_pose_timestamp_msg->data,
  335. points_raw_.find(obj_pose_timestamp_msg->data));
  336. } else {
  337. time_monitor_msg.points_raw = 0;
  338. }
  339. if (is_points_image_) {
  340. // ROS_INFO("points_image");
  341. time_monitor_msg.points_image = time_diff(points_raw_.find(obj_pose_timestamp_msg->data),
  342. points_image_.find(obj_pose_timestamp_msg->data));
  343. }
  344. if (is_vscan_image_) {
  345. // ROS_INFO("vscan_points");
  346. time_monitor_msg.vscan_points = time_diff(points_raw_.find(obj_pose_timestamp_msg->data),
  347. vscan_points_.find(obj_pose_timestamp_msg->data));
  348. // ROS_INFO("vscan_image");
  349. time_monitor_msg.vscan_image = time_diff(vscan_points_.find(obj_pose_timestamp_msg->data),
  350. vscan_image_.find(obj_pose_timestamp_msg->data));
  351. }
  352. // ROS_INFO("image_obj");
  353. time_monitor_msg.image_obj = time_diff(image_raw_.find(obj_pose_timestamp_msg->data),
  354. image_obj_.find(obj_pose_timestamp_msg->data));
  355. // ROS_INFO("image_obj_ranged");
  356. time_monitor_msg.image_obj_ranged = time_diff(sync_image_obj_ranged_.find(obj_pose_timestamp_msg->data),
  357. image_obj_ranged_.find(obj_pose_timestamp_msg->data));
  358. // ROS_INFO("image_obj_tracked");
  359. time_monitor_msg.image_obj_tracked = time_diff(sync_image_obj_tracked_.find(obj_pose_timestamp_msg->data),
  360. image_obj_tracked_.find(obj_pose_timestamp_msg->data));
  361. // ROS_INFO("current_pose");
  362. time_monitor_msg.current_pose = time_diff(points_raw_.find(obj_pose_timestamp_msg->data),
  363. current_pose_.find(obj_pose_timestamp_msg->data));
  364. // ROS_INFO("obj_label");
  365. time_monitor_msg.obj_label = time_diff(sync_obj_label_.find(obj_pose_timestamp_msg->data),
  366. obj_label_.find(obj_pose_timestamp_msg->data));
  367. // ROS_INFO("cluster_centroids");
  368. time_monitor_msg.cluster_centroids = time_diff(points_raw_.find(obj_pose_timestamp_msg->data),
  369. cluster_centroids_.find(obj_pose_timestamp_msg->data));
  370. // ROS_INFO("obj_pose");
  371. time_monitor_msg.obj_pose = time_diff(sync_obj_pose_.find(obj_pose_timestamp_msg->data),
  372. obj_pose_.find(obj_pose_timestamp_msg->data));
  373. // ROS_INFO("-------------------------------------");
  374. if (!ros::Time::isSimTime()) {
  375. time_monitor_msg.execution_time = time_diff(obj_pose_timestamp_msg->data, obj_pose_.find(obj_pose_timestamp_msg->data));
  376. } else {
  377. time_monitor_msg.execution_time = time_diff(points_raw_.find(obj_pose_timestamp_msg->data), obj_pose_.find(obj_pose_timestamp_msg->data));
  378. }
  379. time_monitor_msg.cycle_time = time_diff(pre_sensor_time, obj_pose_timestamp_msg->data); // cycle time
  380. time_monitor_msg.time_diff = ros_time2msec(time_diff_.find(obj_pose_timestamp_msg->data)); // time difference
  381. time_monitor_pub.publish(time_monitor_msg);
  382. pre_sensor_time = obj_pose_timestamp_msg->data;
  383. }
  384. void TimeManager::run() {
  385. ros::spin();
  386. }
  387. int main(int argc, char **argv) {
  388. ros::init(argc, argv, "time_monitor");
  389. TimeManager time_manager(64);
  390. time_manager.run();
  391. return 0;
  392. }