carla ros bridge自车轨迹录制

import ros_compatibility as roscomp
from ros_compatibility.node import CompatibleNode
import csv
from nav_msgs.msg import Path
from geometry_msgs.msg import PoseStamped
from nav_msgs.msg import Odometry
from sensor_msgs.msg import NavSatFix


# uint8 COVARIANCE_TYPE_UNKNOWN=0
# uint8 COVARIANCE_TYPE_APPROXIMATED=1
# uint8 COVARIANCE_TYPE_DIAGONAL_KNOWN=2
# uint8 COVARIANCE_TYPE_KNOWN=3
# std_msgs/Header header
#   uint32 seq
#   time stamp
#   string frame_id
# sensor_msgs/NavSatStatus status
#   int8 STATUS_NO_FIX=-1
#   int8 STATUS_FIX=0
#   int8 STATUS_SBAS_FIX=1
#   int8 STATUS_GBAS_FIX=2
#   uint16 SERVICE_GPS=1
#   uint16 SERVICE_GLONASS=2
#   uint16 SERVICE_COMPASS=4
#   uint16 SERVICE_GALILEO=8
#   int8 status
#   uint16 service
# float64 latitude
# float64 longitude
# float64 altitude
# float64[9] position_covariance
# uint8 position_covariance_type

# nancyhu@nancyhu-pc:~/Desktop/lcl_prj/carla/carla_ros_bridge/catkin_ws$ rosmsg show sensor_msgs/NavSatFix




ROS_VERSION = roscomp.get_ros_version()

class record_globalroute(CompatibleNode):
    def __init__(self):
        self.csv_data= open("./src/ros-bridge/ros-bridge-master/carla_globalroute/src/global_route/test.csv", "w")
        self.csv_header=["header.stamp","header.frame_id","poses.header.stamp","poses.header.frame_id",
        "poses.pose.position.x","poses.pose.position.y","poses.pose.position.z","poses.pose.orientation.x",
        "poses.pose.orientation.y","poses.pose.orientation.z","poses.pose.orientation.w","latitude","longitude","altitude",
        "position_covariance"]
        self.writer_data = csv.DictWriter(self.csv_data, self.csv_header)
        self.writer_data.writeheader()
    def run(self):
        self.callback_group = roscomp.callback_groups.ReentrantCallbackGroup()
        # self.global_route_subscriber = self.new_subscription(
        #         Odometry,
        #         "/carla/ego_vehicle/odometry",
        #         self.record_data,
        #         qos_profile=10, callback_group=self.callback_group)
        self.global_gnss_subscriber = self.new_subscription(
                NavSatFix,
                "/carla/ego_vehicle/gnss",
                self.record_data,
                qos_profile=10, callback_group=self.callback_group)
    def record_data(self,data):
        #ego
        # self.writer_data.writerow({
        #  "header.stamp": " ",
        #  "header.frame_id": " ",
        #  "poses.header.stamp": " ",
        #  "poses.header.frame_id": " ",
        #  "poses.pose.position.x": data.pose.pose.position.x,
        #  "poses.pose.position.y": data.pose.pose.position.y,
        #  "poses.pose.position.z": data.pose.pose.position.z,
        #  "poses.pose.orientation.x": data.pose.pose.orientation.x,
        #  "poses.pose.orientation.y": data.pose.pose.orientation.y,
        #  "poses.pose.orientation.z": data.pose.pose.orientation.z,
        #  "poses.pose.orientation.w": data.pose.pose.orientation.w,
        #  "latitude": " ",
        #  "longitude": " "
        #  })
         #gnss
        self.writer_data.writerow({
        "header.stamp": " ",
        "header.frame_id": " ",
        "poses.header.stamp": " ",
        "poses.header.frame_id": " ",
        "poses.pose.position.x": " ",
        "poses.pose.position.y": " ",
        "poses.pose.position.z": " ",
        "poses.pose.orientation.x": " ",
        "poses.pose.orientation.y": " ",
        "poses.pose.orientation.z": " ",
        "poses.pose.orientation.w": " ",
        "latitude": data.latitude,
        "longitude": data.longitude
        })

    def close(self):
        self.csv_data.close()
        self.destroy_subscription( self.global_route_subscriber)
        
def main(args=None):
    roscomp.init("carla_record_globalroute", args=args)
    record_globalroute_tmp = record_globalroute()
    try:
        record_globalroute_tmp.run()
        record_globalroute_tmp.spin()
    except KeyboardInterrupt:
        pass
    finally:
        roscomp.shutdown()
        record_globalroute_tmp.close()

if __name__ == "__main__":
    main()


主要是录制成csv文件

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值