get_drive.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Dec 25 17:35:56 2023
  5. @author: dell
  6. """
  7. # coding: utf-8
  8. # !/usr/bin/env python2
  9. import os
  10. import rosbag
  11. import csv
  12. import math
  13. import sys
  14. import time
  15. def parsebag(input_dir, output_dir):
  16. dic_object_detection = ['Time', 'Strg_Angle', 'Accel_Pos', 'BrkPel_Pos', 'Real_Speed', 'latitude', 'longitude']
  17. object_detection_file = open(output_dir + "/" + "drive.csv", 'w')
  18. writer_object_detection = csv.writer(object_detection_file)
  19. writer_object_detection.writerow(dic_object_detection)
  20. frame_max = sys.maxsize
  21. count = 1
  22. with rosbag.Bag(input_dir, 'r') as bag:
  23. flag = False
  24. for topic, msg, t in bag.read_messages(): # t代表时间
  25. if topic == "/cicv_location":
  26. flag = True
  27. latitude = msg.latitude
  28. longitude = msg.longitude
  29. if topic == "/data_read": # 10hz
  30. count += 1
  31. if count % 10 == 0 and flag:
  32. message_location = [str(t)[:-6], msg.Strg_Angle_Real_Value, msg.VCU_Accel_Pos_Value,
  33. msg.VCU_BrkPel_Pos_Value,
  34. msg.VCU_Real_Speed * 3.6, latitude, longitude]
  35. writer_object_detection.writerow(message_location)
  36. object_detection_file.close()
  37. if __name__ == "__main__":
  38. # print("Input the path of file...."+'\n')
  39. # input_dir = sys.argv[1]
  40. input_dir = '/media/dell/BFAC-F22B/data/jinlong_datareturn/test_1116/jinlong_data_merge_2023-12-13-05-59-34_TTC_7.bag'
  41. bagname = input_dir.split('/')[-1].split('.')[0]
  42. # output_dir = sys.argv[2]
  43. output_dir = '/media/dell/BFAC-F22B/data/jinlong_datareturn/test_1116/'
  44. output_dir = os.path.join(output_dir, bagname)
  45. if not os.path.exists(output_dir):
  46. os.makedirs(output_dir)
  47. parsebag(input_dir, output_dir)
  48. '''
  49. try:
  50. parsebag(input_dir, output_dir)
  51. print('successfully analysis '+input_dir)
  52. except Exception as e:
  53. print(e)
  54. '''
  55. def parse(input_dir, output_dir):
  56. bagname = input_dir.split('/')[-1].split('.')[0]
  57. output_dir = os.path.join(output_dir, bagname)
  58. if not os.path.exists(output_dir):
  59. os.makedirs(output_dir)
  60. parsebag(input_dir, output_dir)
  61. return output_dir