• ubuntu1804发布kitti数据集的gps资料,imu资料(包含发布图片,点云过程)


    这是一套完整的学习过程,从发布图片,点云到发布gps,imu,并实现他们的可视化

    具体的学习链接如下,是对学习的记录,方便自己回顾,同时也希望帮到需要帮助的人。

    系列1:Ubuntu1804里进行KITTI数据集可视化操作_FYY2LHH的博客-CSDN博客

    系列2:自己编写程序publish出kitti数据集,可视化kitti数据集_FYY2LHH的博客-CSDN博客

    系列3:ubuntu1804自己编写程序发布kitti数据集的点云数据_FYY2LHH的博客-CSDN博客

    系列4:在rviz中利用KITTI数据集画出自己的车子以及照相机的视野_FYY2LHH的博客-CSDN博客

    本章节记录内容为发布imu并实现可视化,发布gps,并查看话题发布类型

    1、仍然是三个py文件,第一个publish

    1. #!/usr/bin/env python
    2. import rospy
    3. from std_msgs.msg import Header
    4. from visualization_msgs.msg import Marker,MarkerArray
    5. from sensor_msgs.msg import Image, PointCloud2, Imu, NavSatFix
    6. from geometry_msgs.msg import Point
    7. import sensor_msgs.point_cloud2 as pcl2
    8. from cv_bridge import CvBridge
    9. import tf
    10. import numpy as np
    11. FRAME_ID = 'map'
    12. def publish_camera(cam_pub, bridge, image):
    13. cam_pub.publish(bridge.cv2_to_imgmsg(image,"bgr8"))
    14. def publish_point_cloud(pcl_pub,point_cloud):
    15. header = Header()
    16. header.stamp = rospy.Time.now()
    17. header.frame_id = FRAME_ID
    18. pcl_pub.publish(pcl2.create_cloud_xyz32(header, point_cloud[:,:3]))
    19. def publish_ego_car(ego_car_pub):
    20. # publish left and right 45 degree FOV lines and ego car model mesh
    21. marker_array = MarkerArray()
    22. marker = Marker()
    23. marker.header.frame_id = FRAME_ID
    24. marker.header.stamp = rospy.Time.now()
    25. marker.id = 0
    26. marker.action = Marker.ADD
    27. marker.lifetime = rospy.Duration()
    28. marker.type = Marker.LINE_STRIP
    29. # line
    30. marker.color.r = 0.0
    31. marker.color.g = 1.0
    32. marker.color.b = 0.0
    33. marker.color.a = 1.0
    34. marker.scale.x = 0.2 # line width
    35. marker.points = []
    36. # check the kitti axis model
    37. marker.points.append(Point(5,-5,0)) # left up
    38. marker.points.append(Point(0,0,0)) # center
    39. marker.points.append(Point(5, 5,0)) # right up
    40. marker_array.markers.append(marker111)
    41. ego_car_pub.publish(marker)
    42. def publish_car_model(model_pub):
    43. mesh_marker = Marker()
    44. mesh_marker.header.frame_id = FRAME_ID
    45. mesh_marker.header.stamp = rospy.Time.now()
    46. mesh_marker.id = -1
    47. mesh_marker.lifetime = rospy.Duration()
    48. mesh_marker.type = Marker.MESH_RESOURCE
    49. mesh_marker.mesh_resource = "/root/catkin_ws/src/kitti_tutorial/AudiR8.dae" #LOAD ERROR, DON'T KNOW WHY
    50. mesh_marker.pose.position.x = 0.0
    51. mesh_marker.pose.position.y = 0.0
    52. mesh_marker.pose.position.z = -1.73
    53. q = tf.transformations.quaternion_from_euler(np.pi/2,0,np.pi)
    54. mesh_marker.pose.orientation.x = q[0]
    55. mesh_marker.pose.orientation.y = q[1]
    56. mesh_marker.pose.orientation.z = q[2]
    57. mesh_marker.pose.orientation.w = q[3]
    58. mesh_marker.color.r = 1.0
    59. mesh_marker.color.g = 1.0
    60. mesh_marker.color.b = 1.0
    61. mesh_marker.color.a = 1.0
    62. mesh_marker.scale.x = 0.9
    63. mesh_marker.scale.y = 0.9
    64. mesh_marker.scale.z = 0.9
    65. model_pub.publish(mesh_marker)
    66. def publish_imu(imu_pub, imu_data, log=False):
    67. """
    68. Publish IMU data
    69. http://docs.ros.org/melodic/api/sensor_msgs/html/msg/Imu.html
    70. """
    71. imu = Imu()
    72. imu.header.frame_id = FRAME_ID
    73. imu.header.stamp = rospy.Time.now()
    74. q = tf.transformations.quaternion_from_euler(float(imu_data.roll), float(imu_data.pitch), \
    75. float(imu_data.yaw)) # prevent the data from being overwritten
    76. imu.orientation.x = q[0]
    77. imu.orientation.y = q[1]
    78. imu.orientation.z = q[2]
    79. imu.orientation.w = q[3]
    80. imu.linear_acceleration.x = imu_data.af
    81. imu.linear_acceleration.y = imu_data.al
    82. imu.linear_acceleration.z = imu_data.au
    83. imu.angular_velocity.x = imu_data.wf
    84. imu.angular_velocity.y = imu_data.wl
    85. imu.angular_velocity.z = imu_data.wu
    86. imu_pub.publish(imu)
    87. if log:
    88. rospy.loginfo("imu msg published")
    89. def publish_gps(gps_pub, gps_data, log=False):
    90. """
    91. Publish GPS data
    92. """
    93. gps = NavSatFix()
    94. gps.header.frame_id = FRAME_ID
    95. gps.header.stamp = rospy.Time.now()
    96. gps.latitude = gps_data.lat
    97. gps.longitude = gps_data.lon
    98. gps.altitude = gps_data.alt
    99. gps_pub.publish(gps)
    100. if log:
    101. rospy.loginfo("gps msg published")

    2、data_utils.py

    1. #!/usr/bin/env python
    2. import cv2
    3. import numpy as np
    4. import pandas as pd
    5. IMU_COLUMN_NAMES = ['lat', 'lon', 'alt', 'roll', 'pitch', 'yaw', 'vn', 've', 'vf', 'vl', 'vu', 'ax', 'ay', 'az', 'af','al', 'au', 'wx', 'wy', 'wz', 'wf', 'wl', 'wu', 'posacc', 'velacc', 'navstat', 'numsats', 'posmode','velmode', 'orimode']
    6. def read_camera(path):
    7. return cv2.imread(path)
    8. def read_point_cloud(path):
    9. return np.fromfile(path,dtype=np.float32).reshape(-1, 4)
    10. def read_imu(path):
    11. df = pd.read_csv(path, header=None, sep=' ')
    12. df.columns = IMU_COLUMN_NAMES
    13. return df

    3、kitti.py

    1. #!/usr/bin/env python
    2. from data_utils import *
    3. from publish_utils import *
    4. import os
    5. DATA_PATH = '/home/ros/dianyun/2011_09_26_drive_0005_sync/2011_09_26/2011_09_26_drive_0005_sync/'
    6. if __name__ == "__main__":
    7. frame = 0
    8. rospy.init_node('kitti_node',anonymous=True)
    9. cam_pub = rospy.Publisher('kitti_cam', Image, queue_size=10)
    10. pcl_pub = rospy.Publisher('kitti_point_cloud', PointCloud2, queue_size=10)
    11. bridge = CvBridge()
    12. ego_pub = rospy.Publisher('kitti_ego_car',Marker, queue_size=10)
    13. # model_car_pub = rospy.Publisher('kitti_model_car',Marker, queue_size=10)
    14. imu_pub = rospy.Publisher('kitti_imu',Imu, queue_size=10)
    15. gps_pub = rospy.Publisher('kitti_gps',NavSatFix, queue_size=10)
    16. rate = rospy.Rate(10)
    17. while not rospy.is_shutdown():
    18. image = read_camera(os.path.join(DATA_PATH, 'image_02/data/%010d.png'%frame))
    19. point_cloud = read_point_cloud(os.path.join(DATA_PATH, 'velodyne_points/data/%010d.bin'%frame))
    20. imu_data = read_imu(os.path.join(DATA_PATH,'oxts/data/%010d.txt'%frame))
    21. publish_camera(cam_pub, bridge, image)
    22. publish_point_cloud(pcl_pub, point_cloud)
    23. publish_ego_car(ego_pub)
    24. # publish_car_model(model_car_pub)
    25. publish_imu(imu_pub, imu_data )
    26. publish_gps(gps_pub, imu_data ) #gps rviz cannot visulize, only use rostopic echo
    27. rospy.loginfo("kitti published")
    28. rate.sleep()
    29. frame += 1
    30. frame %= 154

    三个文件的路径还是原来的的路径

    4、在rviz中添加imu的话题

     紫色的长度代表速度,偏向代表方向

    5、查看gps的话题

    新开一个终端

    第一行rostopic list查看发布哪些话题

    第二行rostopic info /kitti_gps查看gps的话题类型

    第三行rostopic echo /kitti_gps查看gps发布的具体话题的详细细信息

  • 相关阅读:
    Pinia入门
    网站推广爬虫
    执行计划管理 (SPM)
    神策分析 2.5 上线「经营分析」:可视化分析能力重磅升级!
    数据库(mysql)基本概念
    如何运用java代码操作Redis
    [NOIP2012 提高组] 国王游戏(贪心,排序,高精度)
    号外: 我开通了英语专栏
    Spring MVC处理用户请求的完整流程
    C++常用格式化输出转换
  • 原文地址:https://blog.csdn.net/m0_64346597/article/details/127030344