repo_id
stringlengths
19
138
file_path
stringlengths
32
200
content
stringlengths
1
12.9M
__index_level_0__
int64
0
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH64_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidarCH64/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH64w_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidarCH64w/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar16_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidar16/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar1v4_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidar1v4/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH120_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidarCH120/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH16_conf.pb.txt
model: LSLIDAR_CH16 device_ip: "192.168.1.200" msop_port: 2368 difop_port: 2369 packet_size: 1206 time_synchronization: true add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidarCH16/PointCloud2" frame_id: "lslidarCH16" scan_channel: "/apollo/sensor/lslidarCH16/Scan" min_range: 0.15 max_range: 150.0 calibration: false calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LSCH16_calibration.yaml" #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH16_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidarCH16/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar8v4_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidar8v4/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar401_conf.pb.txt
model: LSLIDAR401 device_ip: "192.168.1.222" msop_port: 2368 packet_size: 1206 time_synchronization: false add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidar401/PointCloud2" frame_id: "lslidar401" scan_channel: "/apollo/sensor/lslidar401/Scan" min_range: 0.3 max_range: 100.0 scan_start_angle: 0.0 scan_end_angle: 36000.0
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar1v4_conf.pb.txt
model: LSLIDAR_C1_V4 device_ip: "192.168.1.200" msop_port: 2368 difop_port: 2369 return_mode: 1 degree_mode: 2 #2: 均匀1度校准两列 1://均匀0.33度校准两列 distance_unit: 0.4 packet_size: 1212 time_synchronization: true add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidar1v4/PointCloud2" frame_id: "lslidar1v4" scan_channel: "/apollo/sensor/lslidar1v4/Scan" min_range: 0.15 max_range: 150.0 config_vert: true scan_start_angle: 0.0 scan_end_angle: 36000.0 #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidartest_conf.pb.txt
model: LSLIDAR_C1_V4 device_ip: "192.168.1.200" msop_port: 2368 difop_port: 2369 return_mode: 1 degree_mode: 2 #2: 均匀2度校准两列 1://均匀1.33度校准两列 distance_unit: 0.4 packet_size: 1212 time_synchronization: true add_multicast: false group_ip: "224.1.1.2" rpm: 600 #雷达转速 10hz:600rpm, 20hz:1200rpm, 5hz:300rpm convert_channel_name: "/apollo/sensor/lslidar1v4/PointCloud2" frame_id: "lslidar16" scan_channel: "/apollo/sensor/lslidar1v4/Scan" min_range: 0.15 max_range: 150.0 config_vert: true scan_start_angle: 0.0 scan_end_angle: 36000.0 #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 #calibration: false #calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LS16_calibration.yaml" pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar32_conf.pb.txt
model: LSLIDAR32P device_ip: "192.168.1.200" msop_port: 2368 difop_port: 2369 return_mode: 1 degree_mode: 2 #2: 均匀1度校准两列 1://均匀0.33度校准两列 distance_unit: 0.4 packet_size: 1206 time_synchronization: false add_multicast: false group_ip: "224.1.1.2" rpm: 300 #雷达转速 10hz:600rpm, 20hz:1200rpm, 5hz:300rpm convert_channel_name: "/apollo/sensor/lslidar32/PointCloud2" frame_id: "lslidar32" scan_channel: "/apollo/sensor/lslidar32/Scan" min_range: 0.15 max_range: 150.0 config_vert: true scan_start_angle: 0.0 scan_end_angle: 36000.0 #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 calibration: false calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LS32_calibration.yaml" pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarLS128S2_conf.pb.txt
model: LSLIDAR_LS128S2 device_ip: "192.168.1.200" msop_port: 2368 difop_port: 2369 packet_size: 1206 time_synchronization: false add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidarLS128S2/PointCloud2" frame_id: "lslidarLS128S2" scan_channel: "/apollo/sensor/lslidarLS128S2/Scan" min_range: 0.15 max_range: 500.0 scan_start_angle: -60.0 scan_end_angle: 60.0 calibration: false calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LS128S2_calibration.yaml" #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH128X1_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidarCH128X1/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH64_conf.pb.txt
model: LSLIDAR_CH64 device_ip: "192.168.1.200" msop_port: 2368 difop_port: 2369 packet_size: 1206 time_synchronization: true add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidarCH64/PointCloud2" frame_id: "lslidarCH64" scan_channel: "/apollo/sensor/lslidarCH64/Scan" min_range: 0.15 max_range: 150.0 calibration: true calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LSCH64_calibration.yaml" #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar32_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidar32/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar401_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidar401/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar16_conf.pb.txt
model: LSLIDAR16P device_ip: "192.168.1.201" msop_port: 2370 difop_port: 2371 return_mode: 1 degree_mode: 2 #2: 均匀2度校准两列 1://均匀1.33度校准两列 distance_unit: 0.25 packet_size: 1206 time_synchronization: false add_multicast: false group_ip: "224.1.1.2" rpm: 600 #雷达转速 10hz:600rpm, 20hz:1200rpm, 5hz:300rpm convert_channel_name: "/apollo/sensor/lslidar16/PointCloud2" frame_id: "lslidar16" scan_channel: "/apollo/sensor/lslidar16/Scan" min_range: 0.15 max_range: 150.0 config_vert: true scan_start_angle: 0.0 scan_end_angle: 36000.0 #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 calibration: false calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LS16_calibration.yaml" pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidar8v4_conf.pb.txt
model: LSLIDAR_C8_V4 device_ip: "192.168.1.200" msop_port: 2368 difop_port: 2369 return_mode: 1 degree_mode: 2 #2: 均匀1度校准两列 1://均匀0.33度校准两列 distance_unit: 0.4 packet_size: 1212 time_synchronization: true add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidar8v4/PointCloud2" frame_id: "lslidar8v4" scan_channel: "/apollo/sensor/lslidar8v4/Scan" min_range: 0.15 max_range: 150.0 config_vert: true scan_start_angle: 0.0 scan_end_angle: 36000.0 #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH64w_conf.pb.txt
model: LSLIDAR_CH64w device_ip: "192.168.1.200" msop_port: 2370 difop_port: 2371 packet_size: 1206 time_synchronization: false add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidarCH64w/PointCloud2" frame_id: "lslidarCH64w" scan_channel: "/apollo/sensor/lslidarCH64w/Scan" min_range: 0.15 max_range: 150.0 calibration: false calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LSCH64w_calibration.yaml" #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 pcap_path: "/ch64w_201.pcap" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarLS128S2_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lslidarLS128S2/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/lslidar
apollo_public_repos/apollo/modules/drivers/lidar/lslidar/conf/lslidarCH120_conf.pb.txt
model: LSLIDAR_CH120 device_ip: "192.168.1.210" msop_port: 2378 difop_port: 2379 packet_size: 1206 time_synchronization: true add_multicast: false group_ip: "224.1.1.2" rpm: 600 convert_channel_name: "/apollo/sensor/lslidarCH120/PointCloud2" frame_id: "lslidarCH120" scan_channel: "/apollo/sensor/lslidarCH120/Scan" min_range: 0.15 max_range: 150.0 calibration: false calibration_file: "/apollo/modules/drivers/lidar/lslidar/params/LSCH120_calibration.yaml" #要屏蔽的矩形区域参数 bottom_left_x: 0.0 #左下 x值 bottom_left_y: 0.0 #左下 y值 top_right_x: 0.0 #右上 x值 top_right_y: 0.0 #右上 y值 pcap_path: "" #读取pcap包,测试时使用,连接雷达的时候,将此值设置为空
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/robosense_config.proto
syntax = "proto2"; package apollo.drivers.robosense; message Config { optional string model = 1; optional string frame_id = 2; optional string ip = 3; optional uint32 msop_port = 4; optional uint32 difop_port = 5; optional uint32 echo_mode=6; optional uint32 start_angle = 8; optional uint32 end_angle = 9; optional uint32 min_distance = 10; optional uint32 max_distance = 11; optional uint32 cut_angle = 12; optional string pointcloud_channel = 13; optional string scan_channel = 14; optional string calibration_file=15; optional bool use_lidar_clock = 16; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/hesai.proto
syntax = "proto2"; package apollo.drivers.hesai; import "modules/common_msgs/basic_msgs/header.proto"; enum Model { UNKNOWN = 0; HESAI40P = 1; HESAI64 = 2; } message HesaiScanPacket { optional uint64 stamp = 1; optional bytes data = 2; } message HesaiScan { optional apollo.common.Header header = 1; optional Model model = 2; // hesai device model repeated HesaiScanPacket firing_pkts = 3; optional uint64 basetime = 4 [default = 0]; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/robosense.proto
syntax = "proto2"; package apollo.drivers.robosense; import "modules/common_msgs/basic_msgs/header.proto"; message RobosenseScanPacket { optional uint64 stamp = 1; optional bytes data = 2; } message RobosenseScan { optional apollo.common.Header header = 1; optional string model = 2; // robosense device model repeated RobosenseScanPacket firing_pkts = 3; optional uint64 basetime = 4 [default = 0]; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/velodyne.proto
syntax = "proto2"; package apollo.drivers.velodyne; import "modules/common_msgs/basic_msgs/header.proto"; enum Model { UNKNOWN = 0; HDL64E_S3S = 1; HDL64E_S3D = 2; HDL64E_S2 = 3; HDL32E = 4; VLP16 = 5; VLP32C = 6; VLS128 = 7; } enum Mode { STRONGEST = 1; LAST = 2; DUAL = 3; } message VelodynePacket { optional uint64 stamp = 1; optional bytes data = 2; } message VelodyneScan { optional apollo.common.Header header = 1; optional Model model = 2; // velodyne device model optional Mode mode = 3; // velodyne work mode repeated VelodynePacket firing_pkts = 4; // for HDL32 and VLP16 repeated VelodynePacket positioning_pkts = 5; // velodyne device serial number, corresponds to a specific calibration file optional string sn = 6; optional uint64 basetime = 7 [default = 0]; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/hesai_config.proto
syntax = "proto2"; package apollo.drivers.hesai; import "modules/drivers/lidar/proto/hesai.proto"; message Config { optional Model model = 1; optional string ip = 2 [default = "192.168.20.13"]; optional uint32 lidar_recv_port = 3; optional uint32 gps_recv_port = 4; optional uint32 start_angle = 5; optional string pointcloud_channel = 6; optional uint32 time_zone = 7; optional string frame_id = 8; optional string scan_channel = 9; optional bool is_online_calibration = 11 [default = true]; optional string calibration_file = 12; optional uint32 tcp_cmd_port = 13 [default = 9347]; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/lidar_parameter.proto
syntax = "proto2"; package apollo.drivers.lidar; message LidarParameter { enum LidarBrand { VELODYNE = 0; HESAI = 1; ROBOSENSE = 2; } enum LidarChannelId { CHANNEL_ID_ZERO = 0; CHANNEL_ID_ONE = 1; CHANNEL_ID_TWO = 2; CHANNEL_ID_THREE = 3; } required LidarBrand brand = 1; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/velodyne_config.proto
syntax = "proto2"; package apollo.drivers.velodyne; import "modules/drivers/lidar/proto/velodyne.proto"; message Config { optional string frame_id = 1; optional string scan_channel = 2; optional double rpm = 3 [default = 600.0]; optional Model model = 4; optional Mode mode = 21; optional string pcap = 5; optional int32 prefix_angle = 6; optional int32 firing_data_port = 7; optional int32 positioning_data_port = 8; optional bool use_sensor_sync = 9; optional double max_range = 10; optional double min_range = 11; optional double max_angle = 12; optional double min_angle = 13; optional double view_direction = 14; optional double view_width = 15; optional bool calibration_online = 16; optional string calibration_file = 17; optional bool organized = 18; optional string convert_channel_name = 19; optional int32 npackets = 20; optional bool use_gps_time = 23; optional bool use_poll_sync = 24; optional bool is_main_frame = 25; } message FusionConfig { optional uint32 max_interval_ms = 1; optional bool drop_expired_data = 2; optional string fusion_channel = 3; repeated string input_channel = 4; optional float wait_time_s = 5; } message CompensatorConfig { optional string output_channel = 1; optional float transform_query_timeout = 2 [default = 0.02]; optional string world_frame_id = 3 [default = "world"]; optional string target_frame_id = 4; optional uint32 point_cloud_size = 5; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/BUILD
## Auto generated by `proto_build_generator.py` load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("//tools:python_rules.bzl", "py_proto_library") package(default_visibility = ["//visibility:public"]) cc_proto_library( name = "robosense_config_cc_proto", deps = [ ":robosense_config_proto", ], ) proto_library( name = "robosense_config_proto", srcs = ["robosense_config.proto"], ) py_proto_library( name = "robosense_config_py_pb2", deps = [ ":robosense_config_proto", ], ) cc_proto_library( name = "hesai_cc_proto", deps = [ ":hesai_proto", ], ) proto_library( name = "hesai_proto", srcs = ["hesai.proto"], deps = [ "//modules/common_msgs/basic_msgs:header_proto", ], ) py_proto_library( name = "hesai_py_pb2", deps = [ ":hesai_proto", "//modules/common_msgs/basic_msgs:header_py_pb2", ], ) cc_proto_library( name = "robosense_cc_proto", deps = [ ":robosense_proto", ], ) proto_library( name = "robosense_proto", srcs = ["robosense.proto"], deps = [ "//modules/common_msgs/basic_msgs:header_proto", ], ) py_proto_library( name = "robosense_py_pb2", deps = [ ":robosense_proto", "//modules/common_msgs/basic_msgs:header_py_pb2", ], ) cc_proto_library( name = "velodyne_cc_proto", deps = [ ":velodyne_proto", ], ) proto_library( name = "velodyne_proto", srcs = ["velodyne.proto"], deps = [ "//modules/common_msgs/basic_msgs:header_proto", ], ) py_proto_library( name = "velodyne_py_pb2", deps = [ ":velodyne_proto", "//modules/common_msgs/basic_msgs:header_py_pb2", ], ) cc_proto_library( name = "hesai_config_cc_proto", deps = [ ":hesai_config_proto", ], ) proto_library( name = "hesai_config_proto", srcs = ["hesai_config.proto"], deps = [ ":hesai_proto", ], ) py_proto_library( name = "hesai_config_py_pb2", deps = [ ":hesai_config_proto", ":hesai_py_pb2", ], ) cc_proto_library( name = "lidar_parameter_cc_proto", deps = [ ":lidar_parameter_proto", ], ) proto_library( name = "lidar_parameter_proto", srcs = ["lidar_parameter.proto"], ) py_proto_library( name = "lidar_parameter_py_pb2", deps = [ ":lidar_parameter_proto", ], ) cc_proto_library( name = "velodyne_config_cc_proto", deps = [ ":velodyne_config_proto", ], ) proto_library( name = "velodyne_config_proto", srcs = ["velodyne_config.proto"], deps = [ ":velodyne_proto", ], ) py_proto_library( name = "velodyne_config_py_pb2", deps = [ ":velodyne_config_proto", ":velodyne_py_pb2", ], ) cc_proto_library( name = "config_cc_proto", deps = [ ":config_proto", ], ) proto_library( name = "config_proto", srcs = ["config.proto"], deps = [ ":hesai_config_proto", ":velodyne_config_proto", ":lidar_parameter_proto", ":robosense_config_proto", ], ) py_proto_library( name = "config_py_pb2", deps = [ ":config_proto", ":hesai_config_py_pb2", ":velodyne_config_py_pb2", ":lidar_parameter_py_pb2", ":robosense_config_py_pb2", ], )
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/proto/config.proto
syntax = "proto2"; package apollo.drivers.lidar; import "modules/drivers/lidar/proto/hesai_config.proto"; import "modules/drivers/lidar/proto/velodyne_config.proto"; import "modules/drivers/lidar/proto/lidar_parameter.proto"; import "modules/drivers/lidar/proto/robosense_config.proto"; message config { optional LidarParameter.LidarBrand brand = 1; optional apollo.drivers.hesai.Config hesai = 2; optional apollo.drivers.robosense.Config robosense = 3; optional apollo.drivers.velodyne.Config velodyne = 4; }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/launch/driver.launch
<cyber> <module> <name>lidar_driver</name> <dag_conf>/apollo/modules/drivers/lidar/dag/velodyne_lidar.dag</dag_conf> <process_name>lidar_driver</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/dag/robosense_lidar.dag
# Define all coms in DAG streaming. module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/liblidar_driver_component.so" components { class_name : "LidarDriverComponent" config { name : "lidar_driver" config_file_path : "/apollo/modules/drivers/lidar/conf/lidar_config.pb.txt" readers {channel: "/apollo/sensor/lidar/driver"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "RS16_Compensator" config_file_path : "/apollo/modules/drivers/lidar/robosense/conf/rs16_compensator.pb.txt" readers {channel: "/apollo/sensor/rs16/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/dag/velodyne_lidar.dag
# Define all coms in DAG streaming. module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/liblidar_driver_component.so" components { class_name : "LidarDriverComponent" config { name : "lidar_driver" config_file_path : "/apollo/modules/drivers/lidar/conf/lidar_config.pb.txt" readers {channel: "/apollo/sensor/lidar/driver"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/parser/libvelodyne_convert_component.so" components { class_name : "VelodyneConvertComponent" config { name : "velodyne_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt" readers {channel: "/apollo/sensor/lidar16/Scan"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar16/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/lidar_robosense
apollo_public_repos/apollo/modules/drivers/lidar/lidar_robosense/component/component_convert.h
/****************************************************************************** * Copyright 2021 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <deque> #include <memory> #include <string> #include <thread> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include "cyber/cyber.h" #include "modules/drivers/lidar/robosense/parser/convert.h" #include "modules/drivers/lidar/robosense/proto/sensor_suteng.pb.h" #include "modules/drivers/proto/pointcloud.pb.h" namespace apollo { namespace drivers { namespace robosense { using apollo::cyber::Component; class CompRoboConvert : public Component<apollo::drivers::suteng::SutengScan> { public: bool Init() { // read config file apollo::drivers::suteng::SutengConfig config; if (!apollo::cyber::common::GetProtoFromFile(config_file_path_, &config)) { AERROR << "Failed to load config file"; return false; } AINFO << "config:" << config.DebugString(); conv_.reset(new Convert(config)); if (!conv_->Init()) { return false; } writer_ = node_->CreateWriter<apollo::drivers::PointCloud>(config.pc_channel()); uint32_t point_size = 28800; // 32256; AINFO << "pc fixed size:" << point_size; point_cloud_deque_.resize(size_); for (uint i = 0; i < size_; ++i) { point_cloud_deque_[i] = std::make_shared<apollo::drivers::PointCloud>(); if (point_cloud_deque_[i] == nullptr) { AERROR << " fail to make shared"; return false; } point_cloud_deque_[i]->mutable_point()->Reserve(point_size); } AINFO << "CompRoboConvert Init SUCC" << ", frame_id:" << config.frame_id(); return true; } bool Proc(const std::shared_ptr<apollo::drivers::suteng::SutengScan>& scan) { uint64_t start = apollo::cyber::Time().Now().ToNanosecond(); if (index_ >= size_) { index_ = 0; } auto point_cloud_send = point_cloud_deque_.at(index_++); if (point_cloud_send == nullptr) { AINFO << "null point cloud"; return false; } // just clear header now, we will reset all other value in pb. point_cloud_send->mutable_header()->Clear(); point_cloud_send->Clear(); conv_->convert_robosense_to_pointcloud(scan, point_cloud_send); if (point_cloud_send == nullptr || point_cloud_send->point_size() == 0) { AINFO << "discard null point cloud"; return false; } uint64_t diff = apollo::cyber::Time().Now().ToNanosecond() - start; point_cloud_send->mutable_header()->set_sequence_num(seq_); writer_->Write(point_cloud_send); if (seq_ % 10 == 0) { AINFO << " total:" << seq_ + 1 << "-RS-cost:" << diff << "-meta:" << point_cloud_send->header().lidar_timestamp(); } seq_++; return true; } private: std::unique_ptr<Convert> conv_ = nullptr; std::deque<std::shared_ptr<apollo::drivers::PointCloud>> point_cloud_deque_; uint64_t index_ = 0; uint64_t seq_ = 0; uint64_t size_ = 8; std::shared_ptr<apollo::cyber::Writer<apollo::drivers::PointCloud>> writer_; }; CYBER_REGISTER_COMPONENT(CompRoboConvert); } // namespace robosense } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/common
apollo_public_repos/apollo/modules/drivers/lidar/common/driver_factory/driver_base.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /** * @file * @brief Defines the CanFrame struct and CanClient interface. */ #pragma once #include <cstdint> #include <cstring> #include <memory> #include <sstream> #include <string> #include <vector> #include "cyber/common/log.h" #include "cyber/cyber.h" /** * @namespace apollo::drivers::lidar * @brief apollo::drivers::lidar */ namespace apollo { namespace drivers { namespace lidar { /** * @class LidarDriver * @brief The class which defines the lidar driver . */ class LidarDriver { public: /** * @brief Constructor */ LidarDriver() {} explicit LidarDriver(const std::shared_ptr<::apollo::cyber::Node>& node) : node_(node) {} /** * @brief Destructor */ virtual ~LidarDriver() = default; /** * @brief Initialize the lidar driver. * @return If the initialization is successful. */ virtual bool Init() = 0; protected: std::shared_ptr<cyber::Node> node_; }; } // namespace lidar } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/common
apollo_public_repos/apollo/modules/drivers/lidar/common/driver_factory/lidar_driver_factory.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /** * @file * @brief Defines the LidarFactory class. */ #pragma once #include <memory> #include <unordered_map> #include "modules/drivers/lidar/proto/config.pb.h" #include "modules/drivers/lidar/proto/lidar_parameter.pb.h" #include "cyber/common/macros.h" #include "cyber/cyber.h" #include "modules/common/util/factory.h" #include "modules/drivers/lidar/common/driver_factory/driver_base.h" #include "modules/drivers/lidar/hesai/parser/parser.h" /** * @namespace apollo::drivers::lidar * */ namespace apollo { namespace drivers { namespace lidar { class LidarDriverFactory : public apollo::common::util::Factory< LidarParameter::LidarBrand, LidarDriver, LidarDriver* (*)(const std::shared_ptr<::apollo::cyber::Node>& node, const apollo::drivers::lidar::config& config)> { public: LidarDriverFactory(const apollo::drivers::lidar::config& config); /** * @brief Register the lidar driver of all brands. This function call the * Function apollo::common::util::Factory::Register() for all of the * lidar. */ void RegisterLidarClients(); /** * @brief Create a pointer to a specified brand of lidar. The brand is * set in the parameter. * @param parameter The parameter to create the CAN client. * @return A pointer to the created CAN client. */ std::unique_ptr<LidarDriver> CreateLidarDriver( const std::shared_ptr<::apollo::cyber::Node>& node, const apollo::drivers::lidar::config& parameter); protected: private: DECLARE_SINGLETON(LidarDriverFactory) }; } // namespace lidar } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/common
apollo_public_repos/apollo/modules/drivers/lidar/common/driver_factory/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "lidar_driver_factory", srcs = ["lidar_driver_factory.cc"], hdrs = ["lidar_driver_factory.h"], deps = [ ":driver_base", "//cyber", "//modules/common/util:util_tool", "//modules/drivers/lidar/hesai/driver", "//modules/drivers/lidar/proto:config_cc_proto", "//modules/drivers/lidar/proto:lidar_parameter_cc_proto", # "//modules/drivers/lidar/robosense/driver", "//modules/drivers/lidar/velodyne/driver", ], ) cc_library( name = "driver_base", hdrs = ["driver_base.h"], deps = [ "//modules/common/util", "//modules/common/util:util_tool", ], ) cpplint()
0
apollo_public_repos/apollo/modules/drivers/lidar/common
apollo_public_repos/apollo/modules/drivers/lidar/common/driver_factory/lidar_driver_factory.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/common/driver_factory/lidar_driver_factory.h" #include "modules/drivers/lidar/hesai/driver/driver.h" // #include "modules/drivers/lidar/robosense/driver/driver.h" #include "modules/drivers/lidar/velodyne/driver/driver.h" namespace apollo { namespace drivers { namespace lidar { LidarDriverFactory::LidarDriverFactory() {} LidarDriverFactory::LidarDriverFactory( const apollo::drivers::lidar::config& config) {} void LidarDriverFactory::RegisterLidarClients() { Register(LidarParameter::HESAI, [](const std::shared_ptr<::apollo::cyber::Node>& node, const apollo::drivers::lidar::config& config) -> LidarDriver* { return new hesai::HesaiDriver(node, config); }); // Register(LidarParameter::ROBOSENSE, // [](const std::shared_ptr<::apollo::cyber::Node>& node, // const apollo::drivers::lidar::config& config) -> LidarDriver* // { // return new robosense::RobosenseDriver(node, config); // }); // Register(LidarParameter::VELODYNE, [](const std::shared_ptr<::apollo::cyber::Node>& node, const apollo::drivers::lidar::config& config) -> LidarDriver* { return velodyne::VelodyneDriverFactory::CreateDriver( node, config.velodyne()); }); } std::unique_ptr<LidarDriver> LidarDriverFactory::CreateLidarDriver( const std::shared_ptr<::apollo::cyber::Node>& node, const apollo::drivers::lidar::config& parameter) { auto factory = CreateObject(parameter.brand(), node, parameter); if (!factory) { AERROR << "Failed to create lidar with parameter: " << parameter.DebugString(); } return factory; } } // namespace lidar } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/hesai/BUILD
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") load("//tools/install:install.bzl", "install") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) HESAI_COPTS = ['-DMODULE_NAME=\\"hesai\\"'] install( name = "install", data_dest = "drivers/addition_data/lidar/hesai", library_dest = "drivers/lib/lidar/hesai", data = [ ":runtime_data", ], targets = [ "libhesai_driver_component.so", ], ) filegroup( name = "runtime_data", srcs = glob([ "conf/*.txt", "conf/*.conf", "dag/*.dag", "launch/*.launch", ]), ) cc_binary( name = "libhesai_driver_component.so", linkshared = True, linkstatic = True, deps = [ ":hesai_convert_component", "//modules/drivers/lidar/hesai/driver:hesai_component", ], ) cc_library( name = "hesai_convert_component", srcs = ["parser/hesai_convert_component.cc"], hdrs = ["parser/hesai_convert_component.h"], copts = HESAI_COPTS, deps = [ ":parser_factory", "//cyber", "//modules/drivers/lidar/hesai/driver", "//modules/drivers/lidar/proto:hesai_config_cc_proto", ], alwayslink = True, ) cc_library( name = "parser_factory", srcs = ["parser/parser_factory.cc"], hdrs = ["parser/parser_factory.h"], copts = HESAI_COPTS, deps = [ ":hesai40_parser", ":hesai64_parser", ":parser", "//cyber", ], ) cc_library( name = "hesai64_parser", srcs = ["parser/hesai64_parser.cc"], hdrs = ["parser/hesai64_parser.h"], copts = HESAI_COPTS, deps = [ ":parser", "//cyber", ], ) cc_library( name = "hesai40_parser", srcs = ["parser/hesai40_parser.cc"], hdrs = ["parser/hesai40_parser.h"], copts = HESAI_COPTS, deps = [ ":parser", "//cyber", ], ) cc_library( name = "parser", srcs = ["parser/parser.cc"], hdrs = ["parser/parser.h"], copts = HESAI_COPTS, deps = [ ":tcp_cmd_client", ":type_defs", "//cyber", "//modules/drivers/lidar/proto:hesai_cc_proto", "//modules/drivers/lidar/proto:hesai_config_cc_proto", "//modules/common_msgs/sensor_msgs:pointcloud_cc_proto", ], ) cc_library( name = "udp_input", srcs = ["input/udp_input.cc"], hdrs = ["input/udp_input.h"], copts = HESAI_COPTS, deps = [ ":type_defs", "//cyber", ], ) cc_library( name = "tcp_cmd_client", srcs = ["parser/tcp_cmd_client.cc"], hdrs = ["parser/tcp_cmd_client.h"], copts = HESAI_COPTS, deps = ["//cyber"], ) cc_library( name = "type_defs", hdrs = ["common/type_defs.h"], deps = [":const_var"], ) cc_library( name = "const_var", hdrs = ["common/const_var.h"], ) cpplint()
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/input/udp_input.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #ifndef LIDAR_HESAI_SRC_INPUT_H_ #define LIDAR_HESAI_SRC_INPUT_H_ #include <cstdint> #include "modules/drivers/lidar/hesai/common/type_defs.h" namespace apollo { namespace drivers { namespace hesai { class Input { public: Input(uint16_t port, uint16_t gpsPort); ~Input(); int GetPacket(HesaiPacket *pkt); private: int socketForLidar = -1; int socketForGPS = -1; int socketNumber = -1; }; } // namespace hesai } // namespace drivers } // namespace apollo #endif // SRC_INPUT_H_
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/input/udp_input.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/hesai/input/udp_input.h" #include <arpa/inet.h> #include <fcntl.h> #include <poll.h> #include <sys/file.h> #include <sys/socket.h> #include <cerrno> #include <cstring> #include <sstream> #include "cyber/cyber.h" namespace apollo { namespace drivers { namespace hesai { Input::Input(uint16_t port, uint16_t gpsPort) { socketForLidar = -1; socketForLidar = socket(PF_INET, SOCK_DGRAM, 0); if (-1 == socketForLidar) { AERROR << "socket open error"; return; } sockaddr_in myAddress; // my address information memset(&myAddress, 0, sizeof(myAddress)); // initialize to zeros myAddress.sin_family = AF_INET; // host byte order myAddress.sin_port = htons(port); // port in network byte order myAddress.sin_addr.s_addr = INADDR_ANY; // automatically fill in my IP if (bind(socketForLidar, reinterpret_cast<sockaddr *>(&myAddress), sizeof(sockaddr)) == -1) { AERROR << "bind error, port:" << port; return; } if (fcntl(socketForLidar, F_SETFL, O_NONBLOCK | FASYNC) < 0) { AERROR << "fcntl error"; return; } if (port == gpsPort) { socketNumber = 1; return; } // gps socket socketForGPS = -1; socketForGPS = socket(PF_INET, SOCK_DGRAM, 0); if (socketForGPS == -1) { return; } sockaddr_in myAddressGPS; // my address information memset(&myAddressGPS, 0, sizeof(myAddressGPS)); // initialize to zeros myAddressGPS.sin_family = AF_INET; // host byte order myAddressGPS.sin_port = htons(gpsPort); // port in network byte order myAddressGPS.sin_addr.s_addr = INADDR_ANY; // automatically fill in my IP if (bind(socketForGPS, reinterpret_cast<sockaddr *>(&myAddressGPS), sizeof(sockaddr)) == -1) { AERROR << "gps bind error"; return; } if (fcntl(socketForGPS, F_SETFL, O_NONBLOCK | FASYNC) < 0) { AERROR << "gps fcntl error"; return; } socketNumber = 2; } Input::~Input(void) { if (socketForGPS > 0) close(socketForGPS); if (socketForLidar > 0) (void)close(socketForLidar); } // return : 0 - lidar // 1 - gps // -1 - error int Input::GetPacket(HesaiPacket *pkt) { struct pollfd fds[socketNumber]; if (socketNumber == 2) { fds[0].fd = socketForGPS; fds[0].events = POLLIN; fds[1].fd = socketForLidar; fds[1].events = POLLIN; } else if (socketNumber == 1) { fds[0].fd = socketForLidar; fds[0].events = POLLIN; } static const int POLL_TIMEOUT = 1000; // one second (in msec) sockaddr_in senderAddress; socklen_t senderAddressLen = sizeof(senderAddress); int retval = poll(fds, socketNumber, POLL_TIMEOUT); if (retval < 0) { if (errno != EINTR) { AERROR << "poll() error:" << strerror(errno); } return -1; } if (retval == 0) { AERROR << "poll() timeout"; return -1; } if ((fds[0].revents & POLLERR) || (fds[0].revents & POLLHUP) || (fds[0].revents & POLLNVAL)) { AERROR << "poll() reports hesai error"; return -1; } senderAddressLen = sizeof(senderAddress); ssize_t nbytes = 0; for (int i = 0; i != socketNumber; ++i) { if (fds[i].revents & POLLIN) { nbytes = recvfrom(fds[i].fd, &pkt->data[0], ETHERNET_MTU, 0, reinterpret_cast<sockaddr *>(&senderAddress), &senderAddressLen); break; } } if (nbytes < 0) { if (errno != EWOULDBLOCK) { AERROR << "recvfrom error"; return -1; } } pkt->size = nbytes; return 0; } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/driver/driver.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/hesai/driver/driver.h" namespace apollo { namespace drivers { namespace hesai { bool HesaiDriver::Init() { if (node_ == nullptr) { AERROR << "node is nullptr"; return false; } Parser* hesai_parser = ParserFactory::CreateParser(node_, conf_); if (hesai_parser == nullptr) { AERROR << "create parser error"; } parser_.reset(hesai_parser); scan_writer_ = node_->CreateWriter<HesaiScan>(conf_.scan_channel()); if (scan_writer_ == nullptr) { AERROR << "writer:" << conf_.scan_channel() << " create error, check cyber is inited."; return false; } if (conf_.model() == HESAI40P) { pkt_buffer_capacity_ = HESAI40_MAX_PACKETS * 10; } else if (conf_.model() == HESAI64) { pkt_buffer_capacity_ = HESAI64_MAX_PACKETS * 10; } else { AERROR << "Not support model:" << conf_.model(); return false; } AINFO << "packet buffer capacity:" << pkt_buffer_capacity_; pkt_buffer_.resize(pkt_buffer_capacity_); for (int i = 0; i < pkt_buffer_capacity_; ++i) { pkt_buffer_[i] = std::make_shared<HesaiPacket>(); } if (!parser_->Init()) { AERROR << "parser init error"; return false; } scan_buffer_.resize(scan_buffer_size_); for (int i = 0; i < scan_buffer_size_; ++i) { scan_buffer_[i] = std::make_shared<HesaiScan>(); if (scan_buffer_[i] == nullptr) { AERROR << "make scan buffer error"; return false; } } tz_second_ = conf_.time_zone() * 3600; input_.reset(new Input(conf_.lidar_recv_port(), conf_.gps_recv_port())); poll_thread_ = std::thread(&HesaiDriver::PollThread, this); process_thread_ = std::thread(&HesaiDriver::ProcessThread, this); return true; } void HesaiDriver::PollThread() { AINFO << "Poll thread start"; while (running_) { auto start = std::chrono::steady_clock::now(); std::shared_ptr<HesaiPacket>& pkt = pkt_buffer_[pkt_index_]; if (input_->GetPacket(pkt.get()) == -1) { continue; } auto end = std::chrono::steady_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start) .count(); if (duration > 50) { AWARN << "recv packet cost:" << duration; } { std::lock_guard<std::mutex> lck(packet_mutex_); pkt_queue_.push_back(pkt); packet_condition_.notify_all(); } pkt_index_ = (pkt_index_ + 1) % pkt_buffer_capacity_; } } void HesaiDriver::ProcessGps(const HesaiPacket& pkt) { if (pkt.size != GPS_PACKET_SIZE) { return; } const uint8_t* recvbuf = pkt.data; int index = 0; GPS gps; gps.flag = (recvbuf[index] & 0xff) | ((recvbuf[index + 1] & 0xff) << 8); index += GPS_PACKET_FLAG_SIZE; gps.year = ((recvbuf[index] & 0xff) - 0x30) + ((recvbuf[index + 1] & 0xff) - 0x30) * 10; index += GPS_PACKET_YEAR_SIZE; gps.month = ((recvbuf[index] & 0xff) - 0x30) + ((recvbuf[index + 1] & 0xff) - 0x30) * 10; index += GPS_PACKET_MONTH_SIZE; gps.day = ((recvbuf[index] & 0xff) - 0x30) + ((recvbuf[index + 1] & 0xff) - 0x30) * 10; index += GPS_PACKET_DAY_SIZE; gps.second = ((recvbuf[index] & 0xff) - 0x30) + ((recvbuf[index + 1] & 0xff) - 0x30) * 10; index += GPS_PACKET_SECOND_SIZE; gps.minute = ((recvbuf[index] & 0xff) - 0x30) + ((recvbuf[index + 1] & 0xff) - 0x30) * 10; index += GPS_PACKET_MINUTE_SIZE; gps.hour = ((recvbuf[index] & 0xff) - 0x30) + ((recvbuf[index + 1] & 0xff) - 0x30) * 10; index += GPS_PACKET_HOUR_SIZE; gps.fineTime = (recvbuf[index] & 0xff) | (recvbuf[index + 1] & 0xff) << 8 | ((recvbuf[index + 2] & 0xff) << 16) | ((recvbuf[index + 3] & 0xff) << 24); struct tm t; t.tm_sec = gps.second; t.tm_min = gps.minute; t.tm_hour = gps.hour; t.tm_mday = gps.day; // UTC's month start from 1, but mktime only accept month from 0. t.tm_mon = gps.month - 1; // UTC's year only include 0 - 99 year , which indicate 2000 to 2099. // and mktime's year start from 1900 which is 0. so we need add 100 year. t.tm_year = gps.year + 100; t.tm_isdst = 0; // static_cast<double>(mktime(&t) + tz_second_)); uint64_t gps_timestamp = static_cast<uint64_t>(timegm(&t)); auto now = apollo::cyber::Time().Now().ToNanosecond(); AINFO << "hesai gps time:" << gps_timestamp << ", sys time:" << now << ", diff:" << now - gps_timestamp; } void HesaiDriver::ProcessThread() { std::shared_ptr<HesaiPacket> pkt = nullptr; bool is_end = false; int seq = 0; AINFO << "packet process thread start"; while (running_) { { std::unique_lock<std::mutex> lck(packet_mutex_); if (pkt_queue_.empty()) { packet_condition_.wait(lck); } if (pkt_queue_.empty()) { // exit notify empty continue; } pkt = pkt_queue_.front(); pkt_queue_.pop_front(); } if (pkt->size == GPS_PACKET_SIZE) { ProcessGps(*pkt); continue; } scan_buffer_[index_]->add_firing_pkts()->set_data(pkt->data, pkt->size); parser_->Parse(pkt->data, pkt->size, &is_end); if (is_end && scan_buffer_[index_]->firing_pkts_size() > 0) { is_end = false; auto now = apollo::cyber::Time().Now(); scan_buffer_[index_]->mutable_header()->set_timestamp_sec(now.ToSecond()); scan_buffer_[index_]->mutable_header()->set_frame_id(conf_.frame_id()); scan_buffer_[index_]->mutable_header()->set_sequence_num(seq++); scan_buffer_[index_]->set_model(conf_.model()); scan_buffer_[index_]->set_basetime(0); scan_writer_->Write(scan_buffer_[index_]); AINFO << "publish scan size:" << scan_buffer_[index_]->firing_pkts_size() << ", index:" << index_; ++index_; index_ = index_ % scan_buffer_size_; scan_buffer_[index_]->Clear(); } } } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/driver/hesai_component.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/hesai/driver/hesai_component.h" namespace apollo { namespace drivers { namespace hesai { bool HesaiComponent::Init() { if (!GetProtoConfig(&hesai_conf_)) { AERROR << "load config error, file:" << config_file_path_; return false; } AINFO << "conf:" << hesai_conf_.DebugString(); driver_.reset(new HesaiDriver(node_, hesai_conf_)); if (!driver_->Init()) { AERROR << "driver init error"; return false; } return true; } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/driver/driver.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #ifndef LIDAR_HESAI_DRIVER_H_ #define LIDAR_HESAI_DRIVER_H_ #include <atomic> #include <condition_variable> #include <deque> #include <functional> #include <list> #include <memory> #include <mutex> #include <string> #include <thread> #include <vector> #include "modules/drivers/lidar/proto/config.pb.h" #include "cyber/cyber.h" #include "modules/drivers/lidar/common/driver_factory/driver_base.h" #include "modules/drivers/lidar/hesai/input/udp_input.h" #include "modules/drivers/lidar/hesai/parser/parser.h" #include "modules/drivers/lidar/hesai/parser/parser_factory.h" namespace apollo { namespace drivers { namespace hesai { class HesaiDriver : public apollo::drivers::lidar::LidarDriver { public: HesaiDriver(const std::shared_ptr<::apollo::cyber::Node>& node, const ::apollo::drivers::lidar::config& conf) : node_(node), conf_(conf.hesai()) {} HesaiDriver(const std::shared_ptr<::apollo::cyber::Node>& node, const ::apollo::drivers::hesai::Config& conf) : node_(node), conf_(conf) {} ~HesaiDriver() { Stop(); } bool Init() override; private: std::shared_ptr<::apollo::cyber::Node> node_ = nullptr; Config conf_; std::shared_ptr<Parser> parser_ = nullptr; std::shared_ptr<Input> input_ = nullptr; std::shared_ptr<::apollo::cyber::Writer<HesaiScan>> scan_writer_ = nullptr; std::mutex packet_mutex_; std::condition_variable packet_condition_; std::thread poll_thread_; std::thread process_thread_; std::atomic<bool> running_ = {true}; std::deque<std::shared_ptr<HesaiScan>> scan_buffer_; int scan_buffer_size_ = 10; int index_ = 0; int tz_second_ = 0; std::vector<std::shared_ptr<HesaiPacket>> pkt_buffer_; int pkt_index_ = 0; int pkt_buffer_capacity_ = 0; std::list<std::shared_ptr<HesaiPacket>> pkt_queue_; private: void PollThread(); void ProcessThread(); void ProcessGps(const HesaiPacket& pkt); void Stop() { AINFO << "driver stoping..."; running_.store(false); packet_condition_.notify_all(); if (poll_thread_.joinable()) { poll_thread_.join(); } if (process_thread_.joinable()) { process_thread_.join(); } } }; } // namespace hesai } // namespace drivers } // namespace apollo #endif
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/driver/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) HESAI_COPTS = ['-DMODULE_NAME=\\"hesai\\"'] cc_library( name = "hesai_component", srcs = ["hesai_component.cc"], hdrs = ["hesai_component.h"], copts = HESAI_COPTS, deps = [ ":driver", "//cyber", "//modules/drivers/lidar/hesai:parser_factory", "//modules/drivers/lidar/proto:hesai_config_cc_proto", ], alwayslink = True, ) cc_library( name = "driver", srcs = ["driver.cc"], hdrs = ["driver.h"], copts = HESAI_COPTS, deps = [ "//cyber", "//modules/drivers/lidar/common/driver_factory:driver_base", "//modules/drivers/lidar/hesai:parser", "//modules/drivers/lidar/hesai:parser_factory", "//modules/drivers/lidar/hesai:type_defs", "//modules/drivers/lidar/hesai:udp_input", "//modules/drivers/lidar/proto:config_cc_proto", ], ) cpplint()
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/driver/hesai_component.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include <string> #include "modules/drivers/lidar/proto/config.pb.h" #include "cyber/cyber.h" #include "modules/drivers/lidar/hesai/driver/driver.h" #include "modules/drivers/lidar/hesai/parser/parser_factory.h" namespace apollo { namespace drivers { namespace hesai { class HesaiComponent : public ::apollo::cyber::Component<> { public: ~HesaiComponent() {} bool Init() override; private: std::shared_ptr<HesaiDriver> driver_; Config hesai_conf_; }; CYBER_REGISTER_COMPONENT(HesaiComponent) } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/launch/hesai40.launch
<cyber> <module> <name>hesai40</name> <dag_conf>/apollo/modules/drivers/lidar/hesai/dag/hesai40.dag</dag_conf> <process_name>hesai</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/launch/hesai64.launch
<cyber> <module> <name>hesai64</name> <dag_conf>/apollo/modules/drivers/lidar/hesai/dag/hesai64.dag</dag_conf> <process_name>hesai</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/dag/hesai40.dag
module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/hesai/libhesai_driver_component.so" components { class_name : "HesaiComponent" config { name : "hesai40p_driver" config_file_path : "/apollo/modules/drivers/lidar/hesai/conf/hesai40p.pb.txt" } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "hesai40p_compensator" config_file_path : "/apollo/modules/drivers/lidar/hesai/conf/hesai40p_compensator.pb.txt" readers {channel: "/apollo/sensor/hesai40/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/dag/hesai64.dag
module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/hesai/libhesai_driver_component.so" components { class_name : "HesaiComponent" config { name : "hesai64_driver" config_file_path : "/apollo/modules/drivers/lidar/hesai/conf/hesai64.pb.txt" } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "hesai64_compensator" config_file_path : "/apollo/modules/drivers/lidar/hesai/conf/hesai64_compensator.pb.txt" readers {channel: "/apollo/sensor/hesai64/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/hesai_convert_component.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/hesai/parser/hesai_convert_component.h" namespace apollo { namespace drivers { namespace hesai { using apollo::cyber::Component; bool HesaiConvertComponent::Init() { if (!GetProtoConfig(&conf_)) { AERROR << "load config error, file:" << config_file_path_; return false; } AINFO << "conf:" << conf_.DebugString(); Parser* parser = ParserFactory::CreateParser(node_, conf_); if (parser == nullptr) { AERROR << "create parser error"; return false; } parser_.reset(parser); if (!parser_->Init()) { return false; } AINFO << "HesaiConvertComponent init success"; return true; } bool HesaiConvertComponent::Proc(const std::shared_ptr<HesaiScan>& scan) { return parser_->Parse(scan); } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/hesai64_parser.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/hesai/parser/hesai64_parser.h" namespace apollo { namespace drivers { namespace hesai { using Node = ::apollo::cyber::Node; using apollo::drivers::PointXYZIT; Hesai64Parser::Hesai64Parser(const std::shared_ptr<Node> &node, const Config &conf) : Parser(node, conf) { // init the block time offset, us block_offset_[5] = 55.56 * 0.0 + 42.58; block_offset_[4] = 55.56 * 1.0 + 42.58; block_offset_[3] = 55.56 * 2.0 + 42.58; block_offset_[2] = 55.56 * 3.0 + 42.58; block_offset_[1] = 55.56 * 4.0 + 42.58; block_offset_[0] = 55.56 * 5.0 + 42.58; // init the laser shot time offset, us laser_offset_[50] = 1.304 * 0 + 1.968 * 0 + 3.62; laser_offset_[60] = 1.304 * 0 + 1.968 * 0 + 3.62; laser_offset_[44] = 1.304 * 1 + 1.968 * 0 + 3.62; laser_offset_[59] = 1.304 * 1 + 1.968 * 0 + 3.62; laser_offset_[38] = 1.304 * 2 + 1.968 * 0 + 3.62; laser_offset_[56] = 1.304 * 2 + 1.968 * 0 + 3.62; laser_offset_[8] = 1.304 * 3 + 1.968 * 0 + 3.62; laser_offset_[54] = 1.304 * 3 + 1.968 * 0 + 3.62; laser_offset_[48] = 1.304 * 4 + 1.968 * 0 + 3.62; laser_offset_[62] = 1.304 * 4 + 1.968 * 0 + 3.62; laser_offset_[42] = 1.304 * 5 + 1.968 * 0 + 3.62; laser_offset_[58] = 1.304 * 5 + 1.968 * 0 + 3.62; laser_offset_[6] = 1.304 * 6 + 1.968 * 0 + 3.62; laser_offset_[55] = 1.304 * 6 + 1.968 * 0 + 3.62; laser_offset_[52] = 1.304 * 7 + 1.968 * 0 + 3.62; laser_offset_[63] = 1.304 * 7 + 1.968 * 0 + 3.62; laser_offset_[46] = 1.304 * 8 + 1.968 * 0 + 3.62; laser_offset_[61] = 1.304 * 8 + 1.968 * 0 + 3.62; laser_offset_[40] = 1.304 * 9 + 1.968 * 0 + 3.62; laser_offset_[57] = 1.304 * 9 + 1.968 * 0 + 3.62; laser_offset_[5] = 1.304 * 10 + 1.968 * 0 + 3.62; laser_offset_[53] = 1.304 * 10 + 1.968 * 0 + 3.62; laser_offset_[4] = 1.304 * 11 + 1.968 * 0 + 3.62; laser_offset_[47] = 1.304 * 11 + 1.968 * 0 + 3.62; laser_offset_[3] = 1.304 * 12 + 1.968 * 0 + 3.62; laser_offset_[49] = 1.304 * 12 + 1.968 * 0 + 3.62; laser_offset_[2] = 1.304 * 13 + 1.968 * 0 + 3.62; laser_offset_[51] = 1.304 * 13 + 1.968 * 0 + 3.62; laser_offset_[1] = 1.304 * 14 + 1.968 * 0 + 3.62; laser_offset_[45] = 1.304 * 14 + 1.968 * 0 + 3.62; laser_offset_[0] = 1.304 * 15 + 1.968 * 0 + 3.62; laser_offset_[43] = 1.304 * 15 + 1.968 * 0 + 3.62; laser_offset_[23] = 1.304 * 15 + 1.968 * 1 + 3.62; laser_offset_[32] = 1.304 * 15 + 1.968 * 1 + 3.62; laser_offset_[26] = 1.304 * 15 + 1.968 * 2 + 3.62; laser_offset_[41] = 1.304 * 15 + 1.968 * 2 + 3.62; laser_offset_[20] = 1.304 * 15 + 1.968 * 3 + 3.62; laser_offset_[35] = 1.304 * 15 + 1.968 * 3 + 3.62; laser_offset_[14] = 1.304 * 15 + 1.968 * 4 + 3.62; laser_offset_[29] = 1.304 * 15 + 1.968 * 4 + 3.62; laser_offset_[21] = 1.304 * 15 + 1.968 * 5 + 3.62; laser_offset_[36] = 1.304 * 15 + 1.968 * 5 + 3.62; laser_offset_[15] = 1.304 * 15 + 1.968 * 6 + 3.62; laser_offset_[30] = 1.304 * 15 + 1.968 * 6 + 3.62; laser_offset_[9] = 1.304 * 15 + 1.968 * 7 + 3.62; laser_offset_[24] = 1.304 * 15 + 1.968 * 7 + 3.62; laser_offset_[18] = 1.304 * 15 + 1.968 * 8 + 3.62; laser_offset_[33] = 1.304 * 15 + 1.968 * 8 + 3.62; laser_offset_[12] = 1.304 * 15 + 1.968 * 9 + 3.62; laser_offset_[27] = 1.304 * 15 + 1.968 * 9 + 3.62; laser_offset_[19] = 1.304 * 15 + 1.968 * 10 + 3.62; laser_offset_[34] = 1.304 * 15 + 1.968 * 10 + 3.62; laser_offset_[13] = 1.304 * 15 + 1.968 * 11 + 3.62; laser_offset_[28] = 1.304 * 15 + 1.968 * 11 + 3.62; laser_offset_[7] = 1.304 * 15 + 1.968 * 12 + 3.62; laser_offset_[22] = 1.304 * 15 + 1.968 * 12 + 3.62; laser_offset_[16] = 1.304 * 15 + 1.968 * 13 + 3.62; laser_offset_[31] = 1.304 * 15 + 1.968 * 13 + 3.62; laser_offset_[10] = 1.304 * 15 + 1.968 * 14 + 3.62; laser_offset_[25] = 1.304 * 15 + 1.968 * 14 + 3.62; laser_offset_[17] = 1.304 * 15 + 1.968 * 15 + 3.62; laser_offset_[37] = 1.304 * 15 + 1.968 * 15 + 3.62; laser_offset_[11] = 1.304 * 15 + 1.968 * 16 + 3.62; laser_offset_[39] = 1.304 * 15 + 1.968 * 16 + 3.62; for (int j = 0; j < LASER_COUNT_L64; j++) { elev_angle_map_[j] = pandarGeneral_elev_angle_map[j]; horizatal_azimuth_offset_map_[j] = pandarGeneral_horizatal_azimuth_offset_map[j]; } min_packets_ = HESAI64_MIN_PACKETS; max_packets_ = HESAI64_MAX_PACKETS; } Hesai64Parser::~Hesai64Parser() {} void Hesai64Parser::ParseRawPacket(const uint8_t *buf, const int len, bool *is_end) { if (len != PACKET_SIZE_L64 && len != PACKET_SIZE_L64_WITH_UDPSEQ) { AWARN << "packet size:" << len << " mismatch internal size:" << PACKET_SIZE_L64; return; } // Parser Packet Hesai64Packet packet; int index = 0; int block = 0; // Parse 8 bytes header packet.header.sob = (buf[index] & 0xff) << 8 | ((buf[index + 1] & 0xff)); packet.header.chLaserNumber = buf[index + 2] & 0xff; packet.header.chBlockNumber = buf[index + 3] & 0xff; packet.header.chReturnType = buf[index + 4] & 0xff; packet.header.chDisUnit = buf[index + 5] & 0xff; index += HEAD_SIZE; if (packet.header.sob != 0xEEFF) { AERROR << "error start of packet!"; return; } for (block = 0; block < packet.header.chBlockNumber; block++) { packet.blocks[block].azimuth = (buf[index] & 0xff) | ((buf[index + 1] & 0xff) << 8); index += BLOCK_AZIMUTH_SIZE; uint8_t unit = 0; for (unit = 0; unit < packet.header.chLaserNumber; unit++) { uint32_t range = (buf[index] & 0xff) | ((buf[index + 1] & 0xff) << 8); packet.blocks[block].units[unit].distance = static_cast<double>(range * packet.header.chDisUnit) / 1000.0; packet.blocks[block].units[unit].reflectivity = (buf[index + 2] & 0xff); index += HS_LIDAR_L64_UNIT_SIZE; } } index += RESERVE_SIZE; index += ENGINE_VELOCITY_SIZE; packet.timestamp = (buf[index] & 0xff) | (buf[index + 1] & 0xff) << 8 | ((buf[index + 2] & 0xff) << 16) | ((buf[index + 3] & 0xff) << 24); index += TIMESTAMP_SIZE; packet.echo = buf[index] & 0xff; index += ECHO_SIZE; index += FACTORY_INFO_SIZE; packet.utc_time[0] = buf[index] & 0xff; packet.utc_time[1] = buf[index + 1] & 0xff; packet.utc_time[2] = buf[index + 2] & 0xff; packet.utc_time[3] = buf[index + 3] & 0xff; packet.utc_time[4] = buf[index + 4] & 0xff; packet.utc_time[5] = buf[index + 5] & 0xff; // CalcPointXYZIT for (int i = 0; i < packet.header.chBlockNumber; ++i) { int azimuthGap = 0; if (last_azimuth_ > packet.blocks[i].azimuth) { azimuthGap = static_cast<int>(packet.blocks[i].azimuth) + (36000 - static_cast<int>(last_azimuth_)); } else { azimuthGap = static_cast<int>(packet.blocks[i].azimuth) - static_cast<int>(last_azimuth_); } if (last_azimuth_ != packet.blocks[i].azimuth && azimuthGap < 600) { if ((last_azimuth_ > packet.blocks[i].azimuth && start_angle_ <= packet.blocks[i].azimuth) || (last_azimuth_ < start_angle_ && start_angle_ <= packet.blocks[i].azimuth)) { *is_end = true; } } CalcPointXYZIT(&packet, i, packet.header.chLaserNumber); last_azimuth_ = packet.blocks[i].azimuth; } } void Hesai64Parser::CalcPointXYZIT(Hesai64Packet *pkt, int blockid, uint8_t chLaserNumber) { Hesai64Block *block = &pkt->blocks[blockid]; struct tm tTm; // UTC's year only include 0 - 99 year , which indicate 2000 to 2099. // and mktime's year start from 1900 which is 0. so we need add 100 year. tTm.tm_year = pkt->utc_time[0] + 100; // UTC's month start from 1, but mktime only accept month from 0. tTm.tm_mon = pkt->utc_time[1] - 1; tTm.tm_mday = pkt->utc_time[2]; tTm.tm_hour = pkt->utc_time[3]; tTm.tm_min = pkt->utc_time[4]; tTm.tm_sec = pkt->utc_time[5]; tTm.tm_isdst = 0; double unix_second = static_cast<double>(mktime(&tTm) + tz_second_); double timestamp = unix_second + (static_cast<double>(pkt->timestamp)) / 1000000.0; CheckPktTime(timestamp); for (int i = 0; i < chLaserNumber; i++) { /* for all the units in a block */ Hesai64Unit &unit = block->units[i]; /* skip wrong distance */ if (unit.distance < 0.1 || unit.distance > 200.0) { continue; } double xyDistance = unit.distance * cosf(degreeToRadian(elev_angle_map_[i])); float x = static_cast<float>( xyDistance * sinf(degreeToRadian(horizatal_azimuth_offset_map_[i] + (static_cast<double>(block->azimuth)) / 100.0))); float y = static_cast<float>( xyDistance * cosf(degreeToRadian(horizatal_azimuth_offset_map_[i] + (static_cast<double>(block->azimuth)) / 100.0))); float z = static_cast<float>(unit.distance * sinf(degreeToRadian(elev_angle_map_[i]))); PointXYZIT *new_point = raw_pointcloud_out_->add_point(); new_point->set_x(-y); new_point->set_y(x); new_point->set_z(z); new_point->set_intensity(unit.reflectivity); if (pkt->echo == 0x39) { // dual return, block 0&1 (2&3 , 4*5 ...)'s timestamp is the same. timestamp -= (static_cast<double>(block_offset_[blockid / 2] + laser_offset_[i]) / 1000000.0f); } else { timestamp -= (static_cast<double>(block_offset_[blockid] + laser_offset_[i]) / 1000000.0f); } uint64_t stamp = static_cast<uint64_t>(timestamp * 1e9); new_point->set_timestamp(stamp); } } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/tcp_cmd_client.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include <arpa/inet.h> #include <fcntl.h> #include <net/if.h> #include <netinet/in.h> #include <stdarg.h> #include <stdlib.h> #include <sys/ioctl.h> #include <sys/msg.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> #include <linux/sockios.h> #include <cerrno> #include <csignal> #include <cstdio> #include <cstring> #include "cyber/cyber.h" #include "modules/drivers/lidar/hesai/parser/tcp_cmd_client.h" namespace apollo { namespace drivers { namespace hesai { int TcpCmdClient::BuildCmdHeader(const Command& cmd, unsigned char* buffer) { int index = 0; buffer[index++] = 0x47; buffer[index++] = 0x74; buffer[index++] = cmd.header.cmd; buffer[index++] = cmd.header.ret_code; // color or mono buffer[index++] = (cmd.header.len >> 24) & 0xff; buffer[index++] = (cmd.header.len >> 16) & 0xff; buffer[index++] = (cmd.header.len >> 8) & 0xff; buffer[index++] = (cmd.header.len >> 0) & 0xff; return index; } bool TcpCmdClient::GetCalibration(std::string* content) { std::lock_guard<std::mutex> lck(mutex_); if (!Open()) { return false; } Command cmd; memset(&cmd, 0, sizeof(Command)); cmd.header.cmd = PTC_COMMAND_GET_LIDAR_CALIBRATION; cmd.header.len = 0; cmd.data = NULL; if (!WriteCmd(cmd)) { Close(); return false; } Command feedback; if (!ReadCmd(&feedback)) { Close(); return false; } *content = std::string(reinterpret_cast<char*>(feedback.data)); Close(); return true; } void TcpCmdClient::ParseHeader(const unsigned char* buffer, const int len, CommandHeader* header) { int index = 0; header->cmd = buffer[index++]; header->ret_code = buffer[index++]; header->len = ((buffer[index] & 0xff) << 24) | ((buffer[index + 1] & 0xff) << 16) | ((buffer[index + 2] & 0xff) << 8) | ((buffer[index + 3] & 0xff) << 0); } bool TcpCmdClient::WriteCmd(const Command& cmd) { unsigned char buffer[128]; int size = BuildCmdHeader(cmd, buffer); int ret = write(socket_fd_, buffer, size); if (ret != size) { AERROR << "write header error"; return false; } if (cmd.header.len > 0 && cmd.data) { ret = write(socket_fd_, cmd.data, cmd.header.len); int len = static_cast<int>(cmd.header.len); if (ret != len) { AERROR << "write data error"; return false; } } AINFO << "write cmd success"; return true; } bool TcpCmdClient::ReadCmd(Command* feedback) { if (feedback == nullptr) { return false; } unsigned char buffer[1500]; memset(buffer, 0, 10 * sizeof(char)); int ret = Read(buffer, 2); if (ret <= 0 || buffer[0] != 0x47 || buffer[1] != 0x74) { AERROR << "server read header failed"; return false; } ret = Read(buffer + 2, 6); if (ret != 6) { AERROR << "server read header failed"; return false; } ParseHeader(buffer + 2, 6, &feedback->header); if (feedback->header.len == 0) { AINFO << "no data response, only header return"; return false; } feedback->data = (unsigned char*)malloc(feedback->header.len + 1); if (!feedback->data) { AERROR << "malloc data error, oom"; return false; } memset(feedback->data, 0, feedback->header.len + 1); ret = Read(feedback->data, feedback->header.len); if (ret != static_cast<int>(feedback->header.len)) { AERROR << "server read data failed"; return false; } AINFO << "read data success, size:" << feedback->header.len; return true; } int TcpCmdClient::Read(unsigned char* buffer, int n) { int nleft = -1, nread = -1; unsigned char* ptr = buffer; nleft = n; while (nleft > 0) { if ((nread = read(socket_fd_, ptr, nleft)) < 0) { if (errno == EINTR) { nread = 0; } else { AERROR << "read() buffer error " << strerror(errno); return -1; } } else if (nread == 0) { break; } nleft -= nread; ptr += nread; } return n - nleft; } void TcpCmdClient::Close() { if (socket_fd_ >= 0) { close(socket_fd_); socket_fd_ = -1; } } bool TcpCmdClient::Open() { int sockfd = -1; struct sockaddr_in servaddr; bzero(&servaddr, sizeof(servaddr)); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { AERROR << "socket() error " << strerror(errno); return false; } servaddr.sin_family = AF_INET; servaddr.sin_port = htons(port_); if (inet_pton(AF_INET, ip_.c_str(), &servaddr.sin_addr) <= 0) { AERROR << "inet_pton() error, ip:" << ip_; close(sockfd); return false; } if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == -1) { close(sockfd); AERROR << "connect() error " << strerror(errno); return false; } socket_fd_ = sockfd; AINFO << "connect success"; return true; } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/parser.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #ifndef LIDAR_HESAI_SRC_PARSE_H #define LIDAR_HESAI_SRC_PARSE_H #include <deque> #include <memory> #include <string> #include <thread> #include <vector> #include "modules/drivers/lidar/proto/hesai_config.pb.h" #include "modules/drivers/lidar/proto/hesai.pb.h" #include "modules/common_msgs/sensor_msgs/pointcloud.pb.h" #include "cyber/cyber.h" #include "modules/drivers/lidar/hesai/parser/tcp_cmd_client.h" #include "modules/drivers/lidar/hesai/common/type_defs.h" namespace apollo { namespace drivers { namespace hesai { inline double degreeToRadian(double degree) { return degree * PI / 180; } class Parser { public: Parser(const std::shared_ptr<::apollo::cyber::Node>& node, const Config& conf); virtual ~Parser(); void Parse(const uint8_t* data, int size, bool* is_end); bool Parse(const std::shared_ptr<HesaiScan>& scan); bool Init(); private: std::thread online_calibration_thread_; void GetCalibrationThread(); bool CheckIsEnd(bool is_end); void LoadCalibrationThread(); bool LoadCalibration(const std::string& content); bool LoadCalibration(const char* path_file); void PublishRawPointCloud(int ret = -1); bool inited_ = false; void Stop(); std::atomic<bool> running_ = {true}; protected: virtual void ParseRawPacket(const uint8_t* buf, const int len, bool* is_end) = 0; void CheckPktTime(double time_sec); void ResetRawPointCloud(); bool is_calibration_ = false; std::shared_ptr<::apollo::cyber::Node> node_; Config conf_; std::shared_ptr<::apollo::cyber::Writer<PointCloud>> raw_pointcloud_writer_; int pool_size_ = 8; int pool_index_ = 0; uint64_t raw_last_time_ = 0; int seq_index_ = 0; std::deque<std::shared_ptr<PointCloud>> raw_pointcloud_pool_; // std::shared_ptr<CCObjectPool<PointCloud>> raw_pointcloud_pool_ = nullptr; std::shared_ptr<PointCloud> raw_pointcloud_out_ = nullptr; int last_azimuth_ = 0; int tz_second_ = 0; int start_angle_ = 0; uint32_t min_packets_ = HESAI40_MIN_PACKETS; uint32_t max_packets_ = HESAI40_MAX_PACKETS; uint32_t packet_nums_ = 0; double elev_angle_map_[LASER_COUNT_L64] = {0}; double horizatal_azimuth_offset_map_[LASER_COUNT_L64] = {0}; }; } // namespace hesai } // namespace drivers } // namespace apollo #endif
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/hesai_convert_component.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include <string> #include "modules/drivers/lidar/proto/hesai.pb.h" #include "modules/drivers/lidar/proto/hesai_config.pb.h" #include "cyber/cyber.h" #include "modules/drivers/lidar/hesai/parser/parser_factory.h" namespace apollo { namespace drivers { namespace hesai { class HesaiConvertComponent : public ::apollo::cyber::Component<HesaiScan> { public: virtual ~HesaiConvertComponent() = default; bool Init() override; bool Proc(const std::shared_ptr<HesaiScan>& scan) override; private: std::shared_ptr<Parser> parser_; Config conf_; }; CYBER_REGISTER_COMPONENT(HesaiConvertComponent) } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/parser.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include <cmath> #include <memory> #include <string> #include "modules/drivers/lidar/hesai/parser/parser.h" namespace apollo { namespace drivers { namespace hesai { using apollo::drivers::PointCloud; Parser::Parser(const std::shared_ptr<::apollo::cyber::Node>& node, const Config& conf) : node_(node), conf_(conf) { tz_second_ = conf_.time_zone() * 3600; start_angle_ = static_cast<int>(conf_.start_angle() * 100); } Parser::~Parser() { Stop(); } bool Parser::Init() { if (inited_) { return true; } // init calibration if (!conf_.is_online_calibration() && conf_.calibration_file() != "") { if (!LoadCalibration(conf_.calibration_file().c_str())) { AERROR << "load local calibration file[" << conf_.calibration_file() << "] error"; return false; } is_calibration_ = true; } else { online_calibration_thread_ = std::thread(&Parser::LoadCalibrationThread, this); } // init writer raw_pointcloud_writer_ = node_->CreateWriter<PointCloud>(conf_.pointcloud_channel()); if (raw_pointcloud_writer_ == nullptr) { AERROR << "create writer:" << conf_.pointcloud_channel() << " error, check cyber is init?"; return false; } // raw_pointcloud_pool_.reset(new CCObjectPool<PointCloud>(pool_size_)); // raw_pointcloud_pool_->ConstructAll(); // for (int i = 0; i < pool_size_; i++) { // auto point_cloud = raw_pointcloud_pool_->GetObject(); // if (point_cloud == nullptr) { // AERROR << "fail to getobject, i: " << i; // return false; // } // point_cloud->mutable_point()->Reserve(70000); // } raw_pointcloud_pool_.resize(pool_size_); for (int i = 0; i < pool_size_; i++) { raw_pointcloud_pool_[i] = std::make_shared<PointCloud>(); if (raw_pointcloud_pool_[i] == nullptr) { AERROR << "make shared PointCloud error,oom"; return false; } raw_pointcloud_pool_[i]->mutable_point()->Reserve(70000); } ResetRawPointCloud(); inited_ = true; return true; } void Parser::ResetRawPointCloud() { // raw_pointcloud_out_ = raw_pointcloud_pool_->GetObject(); // if (raw_pointcloud_out_ == nullptr) { // raw_pointcloud_out_ = std::make_shared<PointCloud>(); // raw_pointcloud_out_->mutable_point()->Reserve(70000); // AWARN << "raw pointcloud out make new"; // } // raw_pointcloud_out_->Clear(); // raw_pointcloud_out_ = raw_pointcloud_pool_.at(pool_index_); AINFO << "pool index:" << pool_index_; raw_pointcloud_out_->Clear(); raw_pointcloud_out_->mutable_point()->Reserve(70000); pool_index_ = (pool_index_ + 1) % pool_size_; } bool Parser::Parse(const std::shared_ptr<HesaiScan>& scan) { ResetRawPointCloud(); bool is_end = false; for (int i = 0; i < scan->firing_pkts_size(); ++i) { const auto& pkt = scan->firing_pkts(i); uint8_t* data = reinterpret_cast<uint8_t*>(const_cast<char*>(pkt.data().c_str())); ParseRawPacket(data, pkt.data().size(), &is_end); } PublishRawPointCloud(scan->header().sequence_num()); return true; } void Parser::Parse(const uint8_t* data, int size, bool* is_end) { bool t_is_end = false; ParseRawPacket(data, size, &t_is_end); ++packet_nums_; *is_end = CheckIsEnd(t_is_end); if (*is_end == false) { return; } packet_nums_ = 0; PublishRawPointCloud(); ResetRawPointCloud(); } bool Parser::CheckIsEnd(bool is_end) { if (packet_nums_ >= max_packets_) { AWARN << "over max packets, packets:" << packet_nums_ << ", max packets:" << max_packets_; return true; } if (is_end && packet_nums_ < min_packets_) { AWARN << "receive too less packets:" << packet_nums_ << ", not end" << ", min packets:" << min_packets_; return false; } return is_end; } void Parser::PublishRawPointCloud(int seq) { int size = raw_pointcloud_out_->point_size(); if (size == 0) { AWARN << "All points size is NAN! Please check hesai:" << conf_.model(); return; } raw_pointcloud_out_->mutable_header()->set_sequence_num(seq_index_++); if (seq > 0) { raw_pointcloud_out_->mutable_header()->set_sequence_num(seq); } raw_pointcloud_out_->mutable_header()->set_frame_id(conf_.frame_id()); raw_pointcloud_out_->mutable_header()->set_timestamp_sec( cyber::Time().Now().ToSecond()); raw_pointcloud_out_->set_height(1); raw_pointcloud_out_->set_width(size); const auto timestamp = raw_pointcloud_out_->point(static_cast<int>(size) - 1).timestamp(); raw_pointcloud_out_->set_measurement_time(static_cast<double>(timestamp) / 1e9); raw_pointcloud_out_->mutable_header()->set_lidar_timestamp(timestamp); raw_pointcloud_writer_->Write(raw_pointcloud_out_); } void Parser::LoadCalibrationThread() { TcpCmdClient tcp_cmd(conf_.ip(), conf_.tcp_cmd_port()); std::string content; AINFO << "start LoadCalibrationThread"; while (running_) { AWARN << "calibration has not inited"; if (!tcp_cmd.GetCalibration(&content)) { AERROR << "tcp get calibration error"; sleep(1); continue; } if (!LoadCalibration(content)) { AERROR << "load calibration error"; continue; } AINFO << "online calibration success"; is_calibration_ = true; break; } AINFO << "exit LoadCalibrationThread, calibration:" << is_calibration_; } void Parser::Stop() { running_.store(false); if (online_calibration_thread_.joinable()) { online_calibration_thread_.join(); } } bool Parser::LoadCalibration(const char* path_file) { std::string path(path_file); std::string content; if (!apollo::cyber::common::GetContent(path, &content)) { AERROR << "get calibration file content error, file:" << path_file; return false; } return LoadCalibration(content); } bool Parser::LoadCalibration(const std::string& content) { AINFO << "parse calibration content:" << content; std::istringstream ifs(content); std::string line; if (!std::getline(ifs, line)) { // first line "Laser id,Elevation,Azimuth" AERROR << "lidar calibration content is empty, content:" << content; return false; } double azimuthOffset[LASER_COUNT_L64]; double elev_angle[LASER_COUNT_L64]; int line_counter = 0; while (std::getline(ifs, line)) { if (line_counter++ >= LASER_COUNT_L64) { break; } double elev = 0, azimuth = 0; int line_id = 0; std::stringstream ss(line); std::string subline; std::getline(ss, subline, ','); std::stringstream(subline) >> line_id; std::getline(ss, subline, ','); std::stringstream(subline) >> elev; std::getline(ss, subline, ','); std::stringstream(subline) >> azimuth; if (line_id != line_counter) { AERROR << "parser lidar calibration content error, line_id[" << line_id << "] != line_counter[" << line_counter << "]"; return false; } elev_angle[line_id - 1] = elev; azimuthOffset[line_id - 1] = azimuth; } AINFO << "laser count:" << line_counter; if (line_counter != LASER_COUNT && line_counter != LASER_COUNT_L64) { AERROR << "now only support hesai40p, hesai64"; return false; } for (int i = 0; i < line_counter; ++i) { elev_angle_map_[i] = elev_angle[i]; horizatal_azimuth_offset_map_[i] = azimuthOffset[i]; } return true; } void Parser::CheckPktTime(double time_sec) { double now = apollo::cyber::Time().Now().ToSecond(); double diff = std::abs(now - time_sec); if (diff > 0.1) { // AWARN << conf_.frame_id() << " time too big, diff:" << diff // << "host time:" << now << ";lidar time:" << time_sec; } } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/hesai40_parser.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include "cyber/cyber.h" #include "modules/drivers/lidar/hesai/parser/parser.h" namespace apollo { namespace drivers { namespace hesai { class Hesai40Parser : public Parser { public: Hesai40Parser(const std::shared_ptr<::apollo::cyber::Node>& node, const Config& conf); ~Hesai40Parser(); protected: void ParseRawPacket(const uint8_t* buf, const int len, bool* is_end) override; private: void CalcPointXYZIT(Hesai40Packet* pkt, int blockid); double block_offset_[BLOCKS_PER_PACKET]; double laser_offset_[LASER_COUNT]; }; } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/tcp_cmd_client.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #ifndef LIDAR_HESAI_SRC_TCP_CMD_CLIENT_H_ #define LIDAR_HESAI_SRC_TCP_CMD_CLIENT_H_ #include <mutex> #include <string> namespace apollo { namespace drivers { namespace hesai { typedef enum { PTC_COMMAND_GET_CALIBRATION = 0, PTC_COMMAND_SET_CALIBRATION, PTC_COMMAND_HEARTBEAT, PTC_COMMAND_RESET_CALIBRATION, PTC_COMMAND_TEST, PTC_COMMAND_GET_LIDAR_CALIBRATION, } PTC_COMMAND; typedef struct CommandHeader { unsigned char cmd = '\0'; unsigned char ret_code = '\0'; uint32_t len = 0; } CommandHeader; typedef struct Command { CommandHeader header; unsigned char* data = nullptr; ~Command() { if (data != nullptr) { free(data); } } } Command; class TcpCmdClient { public: TcpCmdClient(const std::string& ip, uint32_t port) : ip_(ip), port_(port) {} ~TcpCmdClient() { Close(); } bool GetCalibration(std::string* content); private: bool Open(); void Close(); bool ReadCmd(Command* feedBack); int Read(unsigned char* buffer, int n); bool WriteCmd(const Command& cmd); int BuildCmdHeader(const Command& cmd, unsigned char* buffer); void ParseHeader(const unsigned char* buffer, const int len, CommandHeader* header); std::string ip_; uint32_t port_ = 0; int socket_fd_ = -1; std::mutex mutex_; }; } // namespace hesai } // namespace drivers } // namespace apollo #endif
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/parser_factory.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/hesai/parser/parser_factory.h" #include "modules/drivers/lidar/hesai/parser/hesai40_parser.h" #include "modules/drivers/lidar/hesai/parser/hesai64_parser.h" namespace apollo { namespace drivers { namespace hesai { using ::apollo::cyber::Node; Parser* ParserFactory::CreateParser(const std::shared_ptr<Node>& node, const Config& conf) { if (conf.model() == HESAI40P) { return new Hesai40Parser(node, conf); } else if (conf.model() == HESAI64) { return new Hesai64Parser(node, conf); } AERROR << "only support HESAI40P | HESAI64"; return nullptr; } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/hesai64_parser.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include "cyber/cyber.h" #include "modules/drivers/lidar/hesai/parser/parser.h" namespace apollo { namespace drivers { namespace hesai { class Hesai64Parser : public Parser { public: Hesai64Parser(const std::shared_ptr<::apollo::cyber::Node>& node, const Config& conf); ~Hesai64Parser(); protected: void ParseRawPacket(const uint8_t* buf, const int len, bool* is_end) override; private: void CalcPointXYZIT(Hesai64Packet* pkt, int blockid, uint8_t chLaserNumber); double block_offset_[BLOCKS_PER_PACKET_L64] = {0}; double laser_offset_[LASER_COUNT_L64] = {0}; }; } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/hesai40_parser.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/hesai/parser/hesai40_parser.h" namespace apollo { namespace drivers { namespace hesai { using ::apollo::cyber::Node; using apollo::drivers::PointXYZIT; Hesai40Parser::Hesai40Parser(const std::shared_ptr<Node> &node, const Config &conf) : Parser(node, conf) { // init the block time offset, us block_offset_[9] = 55.56 * 0.0 + 28.58; block_offset_[8] = 55.56 * 1.0 + 28.58; block_offset_[7] = 55.56 * 2.0 + 28.58; block_offset_[6] = 55.56 * 3.0 + 28.58; block_offset_[5] = 55.56 * 4.0 + 28.58; block_offset_[4] = 55.56 * 5.0 + 28.58; block_offset_[3] = 55.56 * 6.0 + 28.58; block_offset_[2] = 55.56 * 7.0 + 28.58; block_offset_[1] = 55.56 * 8.0 + 28.58; block_offset_[0] = 55.56 * 9.0 + 28.58; // init the laser shot time offset, us laser_offset_[3] = 3.62; laser_offset_[39] = 3.62; laser_offset_[35] = 4.92; laser_offset_[27] = 6.23; laser_offset_[11] = 8.19; laser_offset_[15] = 8.19; laser_offset_[31] = 9.5; laser_offset_[23] = 11.47; laser_offset_[28] = 12.77; laser_offset_[16] = 14.74; laser_offset_[2] = 16.04; laser_offset_[38] = 16.04; laser_offset_[34] = 17.35; laser_offset_[24] = 18.65; laser_offset_[8] = 20.62; laser_offset_[12] = 20.62; laser_offset_[30] = 21.92; laser_offset_[20] = 23.89; laser_offset_[25] = 25.19; laser_offset_[13] = 27.16; laser_offset_[1] = 28.47; laser_offset_[37] = 28.47; laser_offset_[33] = 29.77; laser_offset_[5] = 31.74; laser_offset_[21] = 31.7447; laser_offset_[9] = 33.71; laser_offset_[29] = 35.01; laser_offset_[17] = 36.98; laser_offset_[22] = 38.95; laser_offset_[10] = 40.91; laser_offset_[0] = 42.22; laser_offset_[36] = 42.22; laser_offset_[32] = 43.52; laser_offset_[4] = 45.49; laser_offset_[18] = 45.49; laser_offset_[6] = 47.46; laser_offset_[26] = 48.76; laser_offset_[14] = 50.73; laser_offset_[19] = 52.7; laser_offset_[9] = 54.67; for (int i = 0; i < LASER_COUNT; i++) { elev_angle_map_[i] = pandar40p_elev_angle_map[i]; horizatal_azimuth_offset_map_[i] = pandar40p_horizatal_azimuth_offset_map[i]; } } Hesai40Parser::~Hesai40Parser() {} void Hesai40Parser::ParseRawPacket(const uint8_t *buf, const int len, bool *is_end) { // PrintMem(buf, len); if (len != PACKET_SIZE && len != PACKET_SIZE_WITH_UDPSEQ) { AWARN << "packet size:" << len << " mismatch internal size:" << PACKET_SIZE; return; } Hesai40Packet packet; int index = 0; // 10 BLOCKs for (int i = 0; i < BLOCKS_PER_PACKET; i++) { Hesai40PBlock &block = packet.blocks[i]; block.sob = (buf[index] & 0xff) | ((buf[index + 1] & 0xff) << 8); block.azimuth = (buf[index + 2] & 0xff) | ((buf[index + 3] & 0xff) << 8); index += SOB_ANGLE_SIZE; // 40x units for (int j = 0; j < LASER_COUNT; j++) { Hesai40PUnit &unit = block.units[j]; uint32_t range = (buf[index] & 0xff) | ((buf[index + 1] & 0xff) << 8); // distance is M. unit.distance = static_cast<double>(range) * LASER_RETURN_TO_DISTANCE_RATE; unit.intensity = (buf[index + 2] & 0xff); // TODO(Philip.Pi): Filtering wrong data for LiDAR. if ((unit.distance == 0x010101 && unit.intensity == 0x0101) || unit.distance > (200 * 1000 / 2 /* 200m -> 2mm */)) { unit.distance = 0; unit.intensity = 0; } index += RAW_MEASURE_SIZE; } } index += RESERVE_SIZE; // skip reserved bytes index += REVOLUTION_SIZE; packet.usec = (buf[index] & 0xff) | (buf[index + 1] & 0xff) << 8 | ((buf[index + 2] & 0xff) << 16) | ((buf[index + 3] & 0xff) << 24); packet.usec %= 1000000; index += TIMESTAMP_SIZE; packet.echo = buf[index] & 0xff; index += FACTORY_INFO_SIZE + ECHO_SIZE; // parse the UTC Time. // UTC's year only include 0 - 99 year , which indicate 2000 to 2099. // and mktime's year start from 1900 which is 0. so we need add 100 year. packet.t.tm_year = (buf[index + 0] & 0xff) + 100; // UTC's month start from 1, but mktime only accept month from 0. packet.t.tm_mon = (buf[index + 1] & 0xff) - 1; packet.t.tm_mday = buf[index + 2] & 0xff; packet.t.tm_hour = buf[index + 3] & 0xff; packet.t.tm_min = buf[index + 4] & 0xff; packet.t.tm_sec = buf[index + 5] & 0xff; packet.t.tm_isdst = 0; // calc point xyzi for (int i = 0; i < BLOCKS_PER_PACKET; ++i) { int azimuthGap = 0; /* To do */ if (last_azimuth_ > packet.blocks[i].azimuth) { azimuthGap = static_cast<int>(packet.blocks[i].azimuth) + (36000 - static_cast<int>(last_azimuth_)); } else { azimuthGap = static_cast<int>(packet.blocks[i].azimuth) - static_cast<int>(last_azimuth_); } if (last_azimuth_ != packet.blocks[i].azimuth && azimuthGap < 600 /* 6 degree*/) { /* for all the blocks */ if ((last_azimuth_ > packet.blocks[i].azimuth && start_angle_ <= packet.blocks[i].azimuth) || (last_azimuth_ < start_angle_ && start_angle_ <= packet.blocks[i].azimuth)) { *is_end = true; } } CalcPointXYZIT(&packet, i); last_azimuth_ = packet.blocks[i].azimuth; } } void Hesai40Parser::CalcPointXYZIT(Hesai40Packet *pkt, int blockid) { Hesai40PBlock *block = &pkt->blocks[blockid]; double unix_second = static_cast<double>(mktime(&pkt->t) + tz_second_); double timestamp = unix_second + (static_cast<double>(pkt->usec)) / 1000000.0; CheckPktTime(timestamp); for (int i = 0; i < LASER_COUNT; ++i) { /* for all the units in a block */ Hesai40PUnit &unit = block->units[i]; /* skip wrong points */ if (unit.distance <= 0.5 || unit.distance > 200.0) { continue; } double xyDistance = unit.distance * cosf(degreeToRadian(elev_angle_map_[i])); float x = static_cast<float>( xyDistance * sinf(degreeToRadian(horizatal_azimuth_offset_map_[i] + (static_cast<double>(block->azimuth)) / 100.0))); float y = static_cast<float>( xyDistance * cosf(degreeToRadian(horizatal_azimuth_offset_map_[i] + (static_cast<double>(block->azimuth)) / 100.0))); float z = static_cast<float>(unit.distance * sinf(degreeToRadian(elev_angle_map_[i]))); PointXYZIT *new_point = raw_pointcloud_out_->add_point(); new_point->set_x(-y); new_point->set_y(x); new_point->set_z(z); new_point->set_intensity(unit.intensity); if (pkt->echo == 0x39) { // dual return, block 0&1 (2&3 , 4*5 ...)'s timestamp is the same. timestamp -= (static_cast<double>(block_offset_[blockid / 2] + laser_offset_[i]) / 1000000.0f); } else { timestamp -= (static_cast<double>(block_offset_[blockid] + laser_offset_[i]) / 1000000.0f); } uint64_t stamp = static_cast<uint64_t>(timestamp * 1e9); new_point->set_timestamp(stamp); } } } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/parser/parser_factory.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include "cyber/cyber.h" #include "modules/drivers/lidar/hesai/parser/parser.h" namespace apollo { namespace drivers { namespace hesai { class ParserFactory { public: static Parser* CreateParser( const std::shared_ptr<::apollo::cyber::Node>& node, const Config& conf); }; } // namespace hesai } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/common/type_defs.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #ifndef LIDAR_HESAI_SRC_TYPE_DEFS_H_ #define LIDAR_HESAI_SRC_TYPE_DEFS_H_ #include <ctime> #include "modules/drivers/lidar/hesai/common/const_var.h" namespace apollo { namespace drivers { namespace hesai { typedef struct HesaiPacket { double stamp; uint8_t data[ETHERNET_MTU]; uint32_t size; } HesaiPacket; /**************Hesai40P****************************/ typedef struct Hesai40PUnit { uint8_t intensity; double distance; } Hesai40PUnit; typedef struct Hesai40PBlock { uint16_t azimuth; uint16_t sob; Hesai40PUnit units[LASER_COUNT]; } Hesai40PBlock; typedef struct Hesai40Packet { Hesai40PBlock blocks[BLOCKS_PER_PACKET]; struct tm t; uint32_t usec; int echo; } Hesai40Packet; /************Hesai64*******************************/ typedef struct Hesai64Header { uint16_t sob; // 0xFFEE 2bytes uint8_t chLaserNumber; // laser number 1byte uint8_t chBlockNumber; // block number 1byte uint8_t chReturnType; // return mode 1 byte // when dual return 0 // Single Return // 1-The first block is the 1 st return. // 2-The first block is the 2 nd return uint8_t chDisUnit; // Distance unit, 6mm/5mm/4mm public: Hesai64Header() { sob = 0; chLaserNumber = 0; chBlockNumber = 0; chReturnType = 0; chDisUnit = 0; } } Hesai64Header; typedef struct Hesai64Unit { double distance; uint8_t reflectivity; // reflectivity } Hesai64Unit; typedef struct Hesai64Block { uint16_t azimuth; // packet angle ,Azimuth = RealAzimuth * 100 Hesai64Unit units[LASER_COUNT_L64]; } Hesai64Block; typedef struct Hesai64Packet { Hesai64Header header; Hesai64Block blocks[BLOCKS_PER_PACKET_L64]; uint8_t echo; unsigned int timestamp; // ms unsigned char utc_time[UTC_TIME]; } Hesai64Packet; /***************GPS****************************/ typedef struct GPS { uint16_t flag; uint16_t year; uint16_t month; uint16_t day; uint16_t second; uint16_t minute; uint16_t hour; uint32_t fineTime; } Gps; } // namespace hesai } // namespace drivers } // namespace apollo #endif
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/common/const_var.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #ifndef LIDAR_HESAI_CONST_VAR_H_ #define LIDAR_HESAI_CONST_VAR_H_ namespace apollo { namespace drivers { namespace hesai { // hesai 40 const int SOB_ANGLE_SIZE = 4; const int RAW_MEASURE_SIZE = 3; const int LASER_COUNT = 40; const int BLOCKS_PER_PACKET = 10; const int BLOCK_SIZE = RAW_MEASURE_SIZE * LASER_COUNT + SOB_ANGLE_SIZE; const int HESAI40_ONE_PACKET_POINTS = LASER_COUNT * BLOCKS_PER_PACKET; const int HESAI40_MAX_PACKETS = 200; const int HESAI40_MIN_PACKETS = 90; const int TIMESTAMP_SIZE = 4; const int FACTORY_INFO_SIZE = 1; const int ECHO_SIZE = 1; const int RESERVE_SIZE = 8; const int REVOLUTION_SIZE = 2; const int INFO_SIZE = (TIMESTAMP_SIZE + FACTORY_INFO_SIZE + ECHO_SIZE + RESERVE_SIZE + REVOLUTION_SIZE); const int UTC_TIME = 6; const int UDP_SEQUENCE_SIZE = 4; const int PACKET_SIZE = (BLOCK_SIZE * BLOCKS_PER_PACKET + INFO_SIZE + UTC_TIME); const int PACKET_SIZE_WITH_UDPSEQ = (PACKET_SIZE + UDP_SEQUENCE_SIZE); const double LASER_RETURN_TO_DISTANCE_RATE = 0.004; // hesai 64 const int HEAD_SIZE = 8; const int BLOCKS_PER_PACKET_L64 = 6; const int BLOCK_AZIMUTH_SIZE = 2; const int LASER_COUNT_L64 = 64; const int HS_LIDAR_L64_UNIT_SIZE = 3; const int BLOCK_SIZE_L64 = (HS_LIDAR_L64_UNIT_SIZE * LASER_COUNT_L64 + BLOCK_AZIMUTH_SIZE); const int ENGINE_VELOCITY_SIZE = 2; const int PACKET_SIZE_L64 = HEAD_SIZE + BLOCK_SIZE_L64 * BLOCKS_PER_PACKET_L64 + INFO_SIZE + UTC_TIME; const int PACKET_SIZE_L64_WITH_UDPSEQ = (PACKET_SIZE_L64 + UDP_SEQUENCE_SIZE); const int HESAI64_ONE_PACKET_POINTS = LASER_COUNT_L64 * BLOCKS_PER_PACKET_L64; const int HESAI64_MAX_PACKETS = 350; const int HESAI64_MIN_PACKETS = 150; const int ETHERNET_MTU = 1500; // gps const int GPS_PACKET_SIZE = 512; const int GPS_PACKET_FLAG_SIZE = 2; const int GPS_PACKET_YEAR_SIZE = 2; const int GPS_PACKET_MONTH_SIZE = 2; const int GPS_PACKET_DAY_SIZE = 2; const int GPS_PACKET_HOUR_SIZE = 2; const int GPS_PACKET_MINUTE_SIZE = 2; const int GPS_PACKET_SECOND_SIZE = 2; const int GPS_ITEM_NUM = 7; const double PI = 3.14159265358979323846; static const double pandar40p_elev_angle_map[] = { 6.96, 5.976, 4.988, 3.996, 2.999, 2.001, 1.667, 1.333, 1.001, 0.667, 0.333, 0, -0.334, -0.667, -1.001, -1.334, -1.667, -2.001, -2.331, -2.667, -3, -3.327, -3.663, -3.996, -4.321, -4.657, -4.986, -5.311, -5.647, -5.974, -6.957, -7.934, -8.908, -9.871, -10.826, -11.772, -12.705, -13.63, -14.543, -15.444}; static const double pandarGeneral_elev_angle_map[] = { 14.882, 11.032, 8.059, 5.057, 3.04, 2.028, 1.86, 1.688, 1.522, 1.351, 1.184, 1.013, 0.846, 0.675, 0.508, 0.337, 0.169, 0, -0.169, -0.337, -0.508, -0.675, -0.845, -1.013, -1.184, -1.351, -1.522, -1.688, -1.86, -2.028, -2.198, -2.365, -2.536, -2.7, -2.873, -3.04, -3.21, -3.375, -3.548, -3.712, -3.884, -4.05, -4.221, -4.385, -4.558, -4.72, -4.892, -5.057, -5.229, -5.391, -5.565, -5.726, -5.898, -6.061, -7.063, -8.059, -9.06, -9.885, -11.032, -12.006, -12.974, -13.93, -18.889, -24.897}; static const double pandar40p_horizatal_azimuth_offset_map[] = { 0.005, 0.006, 0.006, 0.006, -2.479, -2.479, 2.491, -4.953, -2.479, 2.492, -4.953, -2.479, 2.492, -4.953, 0.007, 2.491, -4.953, 0.006, 4.961, -2.479, 0.006, 4.96, -2.478, 0.006, 4.958, -2.478, 2.488, 4.956, -2.477, 2.487, 2.485, 2.483, 0.004, 0.004, 0.003, 0.003, -2.466, -2.463, -2.46, -2.457}; static const double pandarGeneral_horizatal_azimuth_offset_map[] = { -1.042, -1.042, -1.042, -1.042, -1.042, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, 1.042, 3.125, 5.208, -5.208, -3.125, -1.042, -1.042, -1.042, -1.042, -1.042, -1.042, -1.042, -1.042, -1.042, -1.042, -1.042}; } // namespace hesai } // namespace drivers } // namespace apollo #endif
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/conf/hesai40p.pb.txt
ip: "192.168.20.13" lidar_recv_port: 2368 gps_recv_port: 10110 start_angle: 0 pointcloud_channel: "/apollo/sensor/hesai40/PointCloud2" scan_channel: "/apollo/sensor/hesai40/Scan" time_zone: 8 frame_id: "hesai40" model: HESAI40P #is_online_calibration: false #calibration_file: "/apollo/hesai_calibration"
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/conf/hesai64.pb.txt
ip: "192.168.20.13" lidar_recv_port: 2368 gps_recv_port: 10110 start_angle: 0 pointcloud_channel: "/apollo/sensor/hesai64/PointCloud2" scan_channel: "/apollo/sensor/hesai64/Scan" time_zone: 8 frame_id: "hesai64" model: HESAI64 #is_online_calibration: false #calibration_file: "/apollo/hesai_calibration"
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/conf/hesai40p_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/hesai40/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar/hesai
apollo_public_repos/apollo/modules/drivers/lidar/hesai/conf/hesai64_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/hesai64/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/conf/lidar_config.pb.txt
brand: ROBOSENSE velodyne { frame_id: "velodyne128" scan_channel: "/apollo/sensor/lidar16/Scan" rpm: 600 model: VLP16 prefix_angle: 18000 firing_data_port: 2369 positioning_data_port: 8309 use_sensor_sync: false max_range: 100 min_range: 0.9 calibration_online: false calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/VLP16_calibration.yaml" organized: false convert_channel_name: "/apollo/sensor/lidar16/PointCloud2" mode: STRONGEST use_gps_time: true use_poll_sync: true is_main_frame: true } hesai { model: HESAI64 ip: "192.168.20.13" lidar_recv_port: 2368 gps_recv_port: 10110 start_angle: 0 pointcloud_channel: "/apollo/sensor/hesai64/PointCloud2" time_zone: 8 frame_id: "hesai64" scan_channel: "/apollo/sensor/hesai64/Scan" } robosense { model: "RS32" frame_id: "rslidar_32" ip: "192.168.1.200" msop_port: 6699 difop_port: 7788 echo_mode: 1 start_angle: 0 end_angle: 360 min_distance: 0 max_distance: 200 cut_angle: 0 pointcloud_channel: "/apollo/sensor/rs32/PointCloud2" scan_channel: "/apollo/sensor/rs32/Scan" use_lidar_clock: false }
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/README.md
## Velodyne velodyne driver runs as component, including: 1. data packet processing --> /driver 2. point cloud generation --> /convert 3. velodyne 16 fusion --> /fusion 4. compensation --> /compensator Compensation relies on `tf` to query the coordination transform, so gnss_driver is required to run the velodyne components. ### Output Channels 1. data packet channel: /apollo/sensor/lidar128/Scan type: apollo::drivers::velodyne::VelodyneScan proto: [modules/drivers/lidar/velodyne/proto/velodyne.proto](https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/lidar/velodyne/proto/velodyne.proto) 2. point cloud channel: /apollo/sensor/lidar128/PointCloud2 type: apollo::drivers::PointCloud proto: [modules/drivers/proto/pointcloud.proto]https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/proto/pointcloud.proto 3. compensation point cloud channel: /apollo/sensor/lidar128/compensator/PointCloud2 type: apollo::drivers::PointCloud proto: [modules/drivers/proto/pointcloud.proto]https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/proto/pointcloud.proto ### Coordination * world * novatel * velodyne128 ### Start **Please change the parameters in the launch file for cars when you start** ```bash #in docker cyber_launch start velodyne.launch ``` ### FAQ 1. "basetime is zero" The position pack is not valid, please check gps signal. 2. 'velodyne port 2368 poll() timeout' The network between the host and velodyne is having problem. Please use `sudo tcpdump -i eth0 udp port 2368` to check if velodyne packets are received. 3. 'cannot find transform ...' `Compensaton` relies on `tf`, please double check if `gnss_driver` has been started, and also use cyber_monitor check `/tf` channel output.
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/README_cn.md
## velodyne velodyne驱动是以component的形式实现的,包含了: 1. 数据读取打包 --> /driver 2. 生成点云 --> /convert 3. 点云融合 --> /fusion 4. 运动补偿 --> /compensator 4个处理组件,其中`运动补偿`需要依赖`tf`来进行坐标转换查询,因此需要和`gnss_driver`一起运行才能正常工作,点云融合主要将多个激光雷达数据融合成一张点云 ### Output channels 1. 数据包 channel: /apollo/sensor/lidar128/Scan type: apollo::drivers::velodyne::VelodyneScan proto: [modules/drivers/lidar/velodyne/proto/velodyne.proto](https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/lidar/velodyne/proto/velodyne.proto) 2. 原始点云 channel: /apollo/sensor/lidar128/PointCloud2 type: apollo::drivers::PointCloud proto: [modules/drivers/proto/pointcloud.proto]https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/proto/pointcloud.proto 3. 补偿点云 channel: /apollo/sensor/lidar128/compensator/PointCloud2 type: apollo::drivers::PointCloud proto: [modules/drivers/proto/pointcloud.proto]https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/proto/pointcloud.proto ### 坐标系 * world * novatel * velodyne128 ### 启动velodyne驱动 **请先修改并确认launch文件中的参数与实际车辆相对应** ```bash #in docker cd /apollo && cyber_launch start modules/drivers/lidar/velodyne/launch/velodyne.launch ``` ### 常见问题 1. "basetime is zero" position packet 不可用,检查gps接线或者将车开到有信号的地方 2. "velodyne port 2368 poll() timeout" 主机与velodyne网络不通,可用命令`sudo tcpdump -i eth0 udp port 2368`查看是否能收到velodyne数据包 3. "cannot find transform ..." `运动补偿`依赖`tf`,请检查`gnss_driver`是否已启动,同时可通过cyber_monitor工具查看 `/tf` channel 是否有消息输出
0
apollo_public_repos/apollo/modules/drivers/lidar
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/BUILD
load("//tools/install:install.bzl", "install") package(default_visibility = ["//visibility:public"]) install( name = "install", data_dest = "drivers/addition_data/lidar/velodyne", library_dest = "drivers/lib/lidar/velodyne", data = [ ":runtime_data", ], targets = [ "//modules/drivers/lidar/velodyne/compensator:libvelodyne_compensator_component.so", "//modules/drivers/lidar/velodyne/driver:libvelodyne_driver_component.so", "//modules/drivers/lidar/velodyne/fusion:libvelodyne_fusion_component.so", "//modules/drivers/lidar/velodyne/parser:libvelodyne_convert_component.so", ], ) filegroup( name = "runtime_data", srcs = glob([ "conf/*.txt", "conf/*.conf", "dag/*.dag", "launch/*.launch", "params/*.yaml", ]), )
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/fusion/pri_sec_fusion_component.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include <string> #include <vector> #include "Eigen/Eigen" // Eigen 3.3.7: #define ALIVE (0) // fastrtps: enum ChangeKind_t { ALIVE, ... }; #if defined(ALIVE) #undef ALIVE #endif #include "modules/drivers/lidar/proto/velodyne_config.pb.h" #include "modules/common_msgs/sensor_msgs/pointcloud.pb.h" #include "cyber/cyber.h" #include "modules/transform/buffer.h" namespace apollo { namespace drivers { namespace velodyne { using apollo::cyber::Component; using apollo::cyber::Reader; using apollo::cyber::Writer; using apollo::drivers::PointCloud; class PriSecFusionComponent : public Component<PointCloud> { public: bool Init() override; bool Proc(const std::shared_ptr<PointCloud>& point_cloud) override; private: bool Fusion(std::shared_ptr<PointCloud> target, std::shared_ptr<PointCloud> source); bool IsExpired(const std::shared_ptr<PointCloud>& target, const std::shared_ptr<PointCloud>& source); bool QueryPoseAffine(const std::string& target_frame_id, const std::string& source_frame_id, Eigen::Affine3d* pose); void AppendPointCloud(std::shared_ptr<PointCloud> point_cloud, std::shared_ptr<PointCloud> point_cloud_add, const Eigen::Affine3d& pose); FusionConfig conf_; apollo::transform::Buffer* buffer_ptr_ = nullptr; std::shared_ptr<Writer<PointCloud>> fusion_writer_; std::vector<std::shared_ptr<Reader<PointCloud>>> readers_; }; CYBER_REGISTER_COMPONENT(PriSecFusionComponent) } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/fusion/BUILD
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") load("//tools:cpplint.bzl", "cpplint") load("//tools/install:install.bzl", "install") package(default_visibility = ["//visibility:public"]) install( name = "install", library_dest = "drivers/lib/lidar/velodyne/fusion", targets = [ ":libvelodyne_fusion_component.so", ], ) cc_binary( name = "libvelodyne_fusion_component.so", linkshared = True, linkstatic = True, deps = [":fusion_component_lib"], ) cc_library( name = "fusion_component_lib", srcs = ["pri_sec_fusion_component.cc"], hdrs = ["pri_sec_fusion_component.h"], copts = ['-DMODULE_NAME=\\"velodyne\\"'], deps = [ "//cyber", "//modules/drivers/lidar/proto:velodyne_config_cc_proto", "//modules/common_msgs/sensor_msgs:pointcloud_cc_proto", "//modules/transform:buffer", "@eigen", ], alwayslink = True, ) cpplint()
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/fusion/pri_sec_fusion_component.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/velodyne/fusion/pri_sec_fusion_component.h" #include <memory> #include <thread> namespace apollo { namespace drivers { namespace velodyne { using apollo::cyber::Time; bool PriSecFusionComponent::Init() { if (!GetProtoConfig(&conf_)) { AWARN << "Load config failed, config file" << ConfigFilePath(); return false; } buffer_ptr_ = apollo::transform::Buffer::Instance(); fusion_writer_ = node_->CreateWriter<PointCloud>(conf_.fusion_channel()); for (const auto& channel : conf_.input_channel()) { auto reader = node_->CreateReader<PointCloud>(channel); readers_.emplace_back(reader); } return true; } bool PriSecFusionComponent::Proc( const std::shared_ptr<PointCloud>& point_cloud) { auto target = std::make_shared<PointCloud>(*point_cloud); auto fusion_readers = readers_; auto start_time = Time::Now().ToSecond(); while ((Time::Now().ToSecond() - start_time) < conf_.wait_time_s() && fusion_readers.size() > 0) { for (auto itr = fusion_readers.begin(); itr != fusion_readers.end();) { (*itr)->Observe(); if (!(*itr)->Empty()) { auto source = (*itr)->GetLatestObserved(); if (conf_.drop_expired_data() && IsExpired(target, source)) { ++itr; } else { Fusion(target, source); itr = fusion_readers.erase(itr); } } else { ++itr; } } std::this_thread::sleep_for(std::chrono::milliseconds(5)); } auto diff = Time::Now().ToNanosecond() - target->header().lidar_timestamp(); AINFO << "Pointcloud fusion diff: " << diff / 1000000 << "ms"; fusion_writer_->Write(target); return true; } bool PriSecFusionComponent::IsExpired( const std::shared_ptr<PointCloud>& target, const std::shared_ptr<PointCloud>& source) { auto diff = target->measurement_time() - source->measurement_time(); return diff * 1000 > conf_.max_interval_ms(); } bool PriSecFusionComponent::QueryPoseAffine(const std::string& target_frame_id, const std::string& source_frame_id, Eigen::Affine3d* pose) { std::string err_string; if (!buffer_ptr_->canTransform(target_frame_id, source_frame_id, cyber::Time(0), 0.02f, &err_string)) { AERROR << "Can not find transform. " << "target_id:" << target_frame_id << " frame_id:" << source_frame_id << " Error info: " << err_string; return false; } apollo::transform::TransformStamped stamped_transform; try { stamped_transform = buffer_ptr_->lookupTransform( target_frame_id, source_frame_id, cyber::Time(0)); } catch (tf2::TransformException& ex) { AERROR << ex.what(); return false; } *pose = Eigen::Translation3d(stamped_transform.transform().translation().x(), stamped_transform.transform().translation().y(), stamped_transform.transform().translation().z()) * Eigen::Quaterniond(stamped_transform.transform().rotation().qw(), stamped_transform.transform().rotation().qx(), stamped_transform.transform().rotation().qy(), stamped_transform.transform().rotation().qz()); return true; } void PriSecFusionComponent::AppendPointCloud( std::shared_ptr<PointCloud> point_cloud, std::shared_ptr<PointCloud> point_cloud_add, const Eigen::Affine3d& pose) { if (std::isnan(pose(0, 0))) { for (auto& point : point_cloud_add->point()) { PointXYZIT* point_new = point_cloud->add_point(); point_new->set_intensity(point.intensity()); point_new->set_timestamp(point.timestamp()); point_new->set_x(point.x()); point_new->set_y(point.y()); point_new->set_z(point.z()); } } else { for (auto& point : point_cloud_add->point()) { if (std::isnan(point.x())) { PointXYZIT* point_new = point_cloud->add_point(); point_new->set_intensity(point.intensity()); point_new->set_timestamp(point.timestamp()); point_new->set_x(point.x()); point_new->set_y(point.y()); point_new->set_z(point.z()); } else { PointXYZIT* point_new = point_cloud->add_point(); point_new->set_intensity(point.intensity()); point_new->set_timestamp(point.timestamp()); Eigen::Matrix<float, 3, 1> pt(point.x(), point.y(), point.z()); point_new->set_x(static_cast<float>( pose(0, 0) * pt.coeffRef(0) + pose(0, 1) * pt.coeffRef(1) + pose(0, 2) * pt.coeffRef(2) + pose(0, 3))); point_new->set_y(static_cast<float>( pose(1, 0) * pt.coeffRef(0) + pose(1, 1) * pt.coeffRef(1) + pose(1, 2) * pt.coeffRef(2) + pose(1, 3))); point_new->set_z(static_cast<float>( pose(2, 0) * pt.coeffRef(0) + pose(2, 1) * pt.coeffRef(1) + pose(2, 2) * pt.coeffRef(2) + pose(2, 3))); } } } int new_width = point_cloud->point_size() / point_cloud->height(); point_cloud->set_width(new_width); } bool PriSecFusionComponent::Fusion(std::shared_ptr<PointCloud> target, std::shared_ptr<PointCloud> source) { Eigen::Affine3d pose; if (QueryPoseAffine(target->header().frame_id(), source->header().frame_id(), &pose)) { AppendPointCloud(target, source, pose); return true; } return false; } } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/driver.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/velodyne/driver/driver.h" #include <cmath> #include <cstring> #include <ctime> #include <string> #include <thread> #include "cyber/cyber.h" #include "modules/common/util/message_util.h" namespace apollo { namespace drivers { namespace velodyne { uint64_t VelodyneDriver::sync_counter = 0; VelodyneDriver::~VelodyneDriver() { if (poll_thread_.joinable()) { poll_thread_.join(); } if (positioning_thread_.joinable()) { positioning_thread_.join(); } } bool VelodyneDriver::Init() { double frequency = (config_.rpm() / 60.0); // expected Hz rate // default number of packets for each scan is a single revolution // (fractions rounded up) config_.set_npackets(static_cast<int>(ceil(packet_rate_ / frequency))); AINFO << "publishing " << config_.npackets() << " packets per scan"; // open Velodyne input device input_.reset(new SocketInput()); writer_ = node_->CreateWriter<VelodyneScan>(config_.scan_channel()); positioning_input_.reset(new SocketInput()); input_->init(config_.firing_data_port()); positioning_input_->init(config_.positioning_data_port()); // raw data output topic positioning_thread_ = std::thread(&VelodyneDriver::PollPositioningPacket, this); poll_thread_ = std::thread(&VelodyneDriver::DevicePoll, this); return true; } void VelodyneDriver::SetBaseTimeFromNmeaTime(NMEATimePtr nmea_time, uint64_t* basetime) { struct tm time; std::memset(&time, 0, sizeof(tm)); time.tm_year = nmea_time->year + (2000 - 1900); time.tm_mon = nmea_time->mon - 1; time.tm_mday = nmea_time->day; time.tm_hour = nmea_time->hour; // set last gps time using gps socket packet last_gps_time_ = static_cast<uint32_t>((nmea_time->min * 60 + nmea_time->sec) * 1e6); AINFO << "Set base unix time : " << time.tm_year << "-" << time.tm_mon << "-" << time.tm_mday << " " << time.tm_hour << ":" << time.tm_min << ":" << time.tm_sec; uint64_t unix_base = static_cast<uint64_t>(timegm(&time)); *basetime = unix_base * static_cast<uint64_t>(1e6); } bool VelodyneDriver::SetBaseTime() { NMEATimePtr nmea_time(new NMEATime); while (true) { int rc = input_->get_positioning_data_packet(nmea_time); if (rc == 0) { break; // got a full packet } if (rc < 0) { return false; // end of file reached } } SetBaseTimeFromNmeaTime(nmea_time, &basetime_); input_->init(config_.firing_data_port()); return true; } /** poll the device * * @returns true unless end of file reached */ bool VelodyneDriver::Poll(const std::shared_ptr<VelodyneScan>& scan) { // Allocate a new shared pointer for zero-copy sharing with other nodelets. if (basetime_ == 0) { // waiting for positioning data std::this_thread::sleep_for(std::chrono::microseconds(100)); AWARN << "basetime is zero"; return false; } int poll_result = PollStandard(scan); if (poll_result == SOCKET_TIMEOUT || poll_result == RECEIVE_FAIL) { return false; // poll again } if (scan->firing_pkts().empty()) { AINFO << "Get an empty scan from port: " << config_.firing_data_port(); return false; } // publish message using time of last packet read ADEBUG << "Publishing a full Velodyne scan."; scan->mutable_header()->set_timestamp_sec(cyber::Time().Now().ToSecond()); scan->mutable_header()->set_frame_id(config_.frame_id()); scan->set_model(config_.model()); scan->set_mode(config_.mode()); // we use first packet gps time update gps base hour // in cloud nodelet, will update base time packet by packet uint32_t current_secs = *(reinterpret_cast<uint32_t*>( const_cast<char*>(scan->firing_pkts(0).data().data() + 1200))); UpdateGpsTopHour(current_secs); scan->set_basetime(basetime_); return true; } int VelodyneDriver::PollStandard(std::shared_ptr<VelodyneScan> scan) { // Since the velodyne delivers data at a very high rate, keep reading and // publishing scans as fast as possible. while ((config_.use_poll_sync() && ((config_.is_main_frame() && scan->firing_pkts_size() < config_.npackets()) || (!config_.is_main_frame() && sync_counter == last_count_))) || (!config_.use_poll_sync() && scan->firing_pkts_size() < config_.npackets())) { while (true) { // keep reading until full packet received VelodynePacket* packet = scan->add_firing_pkts(); int rc = input_->get_firing_data_packet(packet); if (rc == 0) { break; // got a full packet? } else if (rc < 0) { return rc; } } } if (config_.use_poll_sync()) { if (config_.is_main_frame()) { ++sync_counter; } else { last_count_ = sync_counter; } } return 0; } void VelodyneDriver::PollPositioningPacket(void) { while (!cyber::IsShutdown()) { NMEATimePtr nmea_time(new NMEATime); bool ret = true; if (config_.has_use_gps_time() && !config_.use_gps_time()) { time_t t = time(NULL); struct tm current_time; localtime_r(&t, &current_time); nmea_time->year = static_cast<uint16_t>(current_time.tm_year - 100); nmea_time->mon = static_cast<uint16_t>(current_time.tm_mon + 1); nmea_time->day = static_cast<uint16_t>(current_time.tm_mday); nmea_time->hour = static_cast<uint16_t>(current_time.tm_hour); nmea_time->min = static_cast<uint16_t>(current_time.tm_min); nmea_time->sec = static_cast<uint16_t>(current_time.tm_sec); AINFO << "Get NMEA Time from local time :" << "year:" << nmea_time->year << "mon:" << nmea_time->mon << "day:" << nmea_time->day << "hour:" << nmea_time->hour << "min:" << nmea_time->min << "sec:" << nmea_time->sec; } else { while (!cyber::IsShutdown()) { int rc = positioning_input_->get_positioning_data_packet(nmea_time); if (rc == 0) { break; // got a full packet } if (rc < 0) { ret = false; // end of file reached } } } if (basetime_ == 0 && ret) { SetBaseTimeFromNmeaTime(nmea_time, &basetime_); } else { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } } void VelodyneDriver::UpdateGpsTopHour(uint32_t current_time) { if (last_gps_time_ == 0) { last_gps_time_ = current_time; return; } if (last_gps_time_ > current_time) { if ((last_gps_time_ - current_time) > 3599000000) { basetime_ += static_cast<uint64_t>(3600 * 1e6); AINFO << "Base time plus 3600s. Model: " << config_.model() << std::fixed << ". current:" << current_time << ", last time:" << last_gps_time_; } else { AWARN << "Current stamp:" << std::fixed << current_time << " less than previous stamp:" << last_gps_time_ << ". GPS time stamp maybe incorrect!"; } } last_gps_time_ = current_time; } VelodyneDriver* VelodyneDriverFactory::CreateDriver( const std::shared_ptr<::apollo::cyber::Node>& node, const Config& config) { auto new_config = config; if (new_config.prefix_angle() > 35900 || new_config.prefix_angle() < 100) { AWARN << "invalid prefix angle, prefix_angle must be between 100 and 35900"; if (new_config.prefix_angle() > 35900) { new_config.set_prefix_angle(35900); } else if (new_config.prefix_angle() < 100) { new_config.set_prefix_angle(100); } } VelodyneDriver* driver = nullptr; switch (config.model()) { case HDL64E_S2: { driver = new Velodyne64Driver(node, config); driver->SetPacketRate(PACKET_RATE_HDL64E_S2); break; } case HDL64E_S3S: { driver = new Velodyne64Driver(node, config); driver->SetPacketRate(PACKET_RATE_HDL64E_S3S); break; } case HDL64E_S3D: { driver = new Velodyne64Driver(node, config); driver->SetPacketRate(PACKET_RATE_HDL64E_S3D); break; } case HDL32E: { driver = new VelodyneDriver(node, config); driver->SetPacketRate(PACKET_RATE_HDL32E); break; } case VLP32C: { driver = new VelodyneDriver(node, config); driver->SetPacketRate(PACKET_RATE_VLP32C); break; } case VLP16: { driver = new VelodyneDriver(node, config); driver->SetPacketRate(PACKET_RATE_VLP16); break; } case VLS128: { driver = new VelodyneDriver(node, config); driver->SetPacketRate(PACKET_RATE_VLS128); break; } default: AERROR << "invalid model, must be 64E_S2|64E_S3S" << "|64E_S3D|VLP16|HDL32E|VLS128"; break; } return driver; } void VelodyneDriver::DevicePoll() { while (!apollo::cyber::IsShutdown()) { // poll device until end of file std::shared_ptr<VelodyneScan> scan = std::make_shared<VelodyneScan>(); bool ret = Poll(scan); if (ret) { apollo::common::util::FillHeader("velodyne", scan.get()); writer_->Write(scan); } else { AWARN << "device poll failed"; } } } } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/velodyne_driver_component.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include <string> #include <thread> #include "modules/drivers/lidar/proto/velodyne.pb.h" #include "modules/drivers/lidar/proto/velodyne_config.pb.h" #include "cyber/cyber.h" #include "modules/drivers/lidar/velodyne/driver/driver.h" namespace apollo { namespace drivers { namespace velodyne { using apollo::cyber::Component; using apollo::cyber::Reader; using apollo::cyber::Writer; using apollo::drivers::velodyne::VelodyneScan; class VelodyneDriverComponent : public Component<> { public: ~VelodyneDriverComponent() {} bool Init() override; private: volatile bool runing_; ///< device thread is running uint32_t seq_ = 0; std::shared_ptr<VelodyneDriver> dvr_; ///< driver implementation class }; CYBER_REGISTER_COMPONENT(VelodyneDriverComponent) } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/input.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <unistd.h> #include <cstdio> #include <memory> #include "cyber/cyber.h" // #include "velodyne_msgs/VelodyneScanUnified.h" #include "modules/drivers/lidar/proto/velodyne.pb.h" namespace apollo { namespace drivers { namespace velodyne { static const size_t FIRING_DATA_PACKET_SIZE = 1206; static const size_t POSITIONING_DATA_PACKET_SIZE = 512; static const size_t ETHERNET_HEADER_SIZE = 42; static const int SOCKET_TIMEOUT = -2; static const int RECEIVE_FAIL = -3; struct NMEATime { uint16_t year; uint16_t mon; uint16_t day; uint16_t hour; uint16_t min; uint16_t sec; }; typedef std::shared_ptr<NMEATime> NMEATimePtr; /** @brief Pure virtual Velodyne input base class */ class Input { public: Input() {} virtual ~Input() {} /** @brief Read one Velodyne packet. * * @param pkt points to VelodynePacket message * * @returns 0 if successful, * -1 if end of file * > 0 if incomplete packet (is this possible?) */ virtual int get_firing_data_packet(VelodynePacket* pkt) = 0; virtual int get_positioning_data_packet(NMEATimePtr nmea_time) = 0; virtual void init() {} virtual void init(const int& port) {} protected: bool exract_nmea_time_from_packet(NMEATimePtr nmea_time, const uint8_t* bytes); }; } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/socket_input.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /* -*- mode: C++ -*- * * Copyright (C) 2007 Austin Robot Technology, Yaxin Liu, Patrick Beeson * Copyright (C) 2009, 2010 Austin Robot Technology, Jack O'Quin * Copyright (C) 2015, Jack O'Quin * * License: Modified BSD Software License Agreement * * $Id$ */ #include <arpa/inet.h> #include <fcntl.h> #include <poll.h> #include <sys/file.h> #include <sys/socket.h> #include <unistd.h> #include <cerrno> #include "modules/drivers/lidar/velodyne/driver/socket_input.h" namespace apollo { namespace drivers { namespace velodyne { //////////////////////////////////////////////////////////////////////// // InputSocket class implementation //////////////////////////////////////////////////////////////////////// /** @brief constructor * * @param private_nh private node handle for driver * @param udp_port UDP port number to connect */ SocketInput::SocketInput() : sockfd_(-1), port_(0) {} /** @brief destructor */ SocketInput::~SocketInput(void) { (void)close(sockfd_); } void SocketInput::init(const int &port) { if (sockfd_ != -1) { (void)close(sockfd_); } // connect to Velodyne UDP port AINFO << "Opening UDP socket: port " << uint16_t(port); port_ = port; sockfd_ = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd_ == -1) { AERROR << "Init socket failed, UDP port is " << port; return; } sockaddr_in my_addr; // my address information memset(&my_addr, 0, sizeof(my_addr)); // initialize to zeros my_addr.sin_family = AF_INET; // host byte order my_addr.sin_port = htons(uint16_t(port)); // short, in network byte order my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill in my IP // my_addr.sin_addr.s_addr = inet_addr("192.168.1.100"); if (bind(sockfd_, reinterpret_cast<sockaddr *>(&my_addr), sizeof(sockaddr)) == -1) { AERROR << "Socket bind failed! Port " << port_; return; } if (fcntl(sockfd_, F_SETFL, O_NONBLOCK | FASYNC) < 0) { AERROR << "non-block! Port " << port_; return; } AINFO << "Velodyne socket fd is " << sockfd_ << ", port " << port_; } /** @brief Get one velodyne packet. */ int SocketInput::get_firing_data_packet(VelodynePacket *pkt) { // double time1 = ros::Time::now().toSec(); double time1 = apollo::cyber::Time().Now().ToSecond(); while (true) { if (!input_available(POLL_TIMEOUT)) { return SOCKET_TIMEOUT; } // Receive packets that should now be available from the // socket using a blocking read. uint8_t bytes[FIRING_DATA_PACKET_SIZE]; ssize_t nbytes = recvfrom(sockfd_, bytes, FIRING_DATA_PACKET_SIZE, 0, nullptr, nullptr); if (nbytes < 0) { if (errno != EWOULDBLOCK) { AERROR << "recvfail from port " << port_; return RECEIVE_FAIL; } } if ((size_t)nbytes == FIRING_DATA_PACKET_SIZE) { // read successful, done now pkt->set_data(bytes, FIRING_DATA_PACKET_SIZE); break; } AERROR << "Incomplete Velodyne rising data packet read: " << nbytes << " bytes from port " << port_; } double time2 = apollo::cyber::Time().Now().ToSecond(); pkt->set_stamp(apollo::cyber::Time((time2 + time1) / 2.0).ToNanosecond()); return 0; } int SocketInput::get_positioning_data_packet(NMEATimePtr nmea_time) { while (true) { if (!input_available(POLL_TIMEOUT)) { return 1; } // Receive packets that should now be available from the // socket using a blocking read. // Last 234 bytes not use uint8_t bytes[POSITIONING_DATA_PACKET_SIZE]; ssize_t nbytes = recvfrom(sockfd_, bytes, POSITIONING_DATA_PACKET_SIZE, 0, nullptr, nullptr); if (nbytes < 0) { if (errno != EWOULDBLOCK) { AERROR << "recvfail from port " << port_; return 1; } } if ((size_t)nbytes == POSITIONING_DATA_PACKET_SIZE) { // read successful, exract nmea time if (exract_nmea_time_from_packet(nmea_time, bytes)) { break; } else { return 1; } } AINFO << "incomplete Velodyne packet read: " << nbytes << " bytes from port " << port_; } return 0; } bool SocketInput::input_available(int timeout) { struct pollfd fds[1]; fds[0].fd = sockfd_; fds[0].events = POLLIN; // Unfortunately, the Linux kernel recvfrom() implementation // uses a non-interruptible sleep() when waiting for data, // which would cause this method to hang if the device is not // providing data. We poll() the device first to make sure // the recvfrom() will not block. // // Note, however, that there is a known Linux kernel bug: // // Under Linux, select() may report a socket file descriptor // as "ready for reading", while nevertheless a subsequent // read blocks. This could for example happen when data has // arrived but upon examination has wrong checksum and is // discarded. There may be other circumstances in which a // file descriptor is spuriously reported as ready. Thus it // may be safer to use O_NONBLOCK on sockets that should not // block. // poll() until input available do { int retval = poll(fds, 1, POLL_TIMEOUT); if (retval < 0) { // poll() error? if (errno != EINTR) { AWARN << "Velodyne port " << port_ << "poll() error: " << strerror(errno); } return false; } if (retval == 0) { // poll() timeout? AWARN << "Velodyne port " << port_ << " poll() timeout"; return false; } if ((fds[0].revents & POLLERR) || (fds[0].revents & POLLHUP) || (fds[0].revents & POLLNVAL)) { // device error? AERROR << "Velodyne port " << port_ << "poll() reports Velodyne error"; return false; } } while ((fds[0].revents & POLLIN) == 0); return true; } } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/driver.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include <string> #include "modules/drivers/lidar/proto/config.pb.h" #include "modules/drivers/lidar/proto/velodyne.pb.h" #include "modules/drivers/lidar/proto/velodyne_config.pb.h" #include "modules/drivers/lidar/common/driver_factory/driver_base.h" #include "modules/drivers/lidar/velodyne/driver/socket_input.h" namespace apollo { namespace drivers { namespace velodyne { constexpr int BLOCKS_PER_PACKET = 12; constexpr int BLOCK_SIZE = 100; constexpr double PACKET_RATE_VLP16 = 754; constexpr double PACKET_RATE_HDL32E = 1808.0; constexpr double PACKET_RATE_HDL64E_S2 = 3472.17; constexpr double PACKET_RATE_HDL64E_S3S = 3472.17; constexpr double PACKET_RATE_HDL64E_S3D = 5789; constexpr double PACKET_RATE_VLS128 = 6250.0; constexpr double PACKET_RATE_VLP32C = 1507.0; class VelodyneDriver : public lidar::LidarDriver { public: VelodyneDriver() {} explicit VelodyneDriver(const Config &config) : config_(config) {} VelodyneDriver(const std::shared_ptr<cyber::Node> &node, const Config &config) : config_(config) { node_ = node; } virtual ~VelodyneDriver(); virtual bool Poll(const std::shared_ptr<VelodyneScan> &scan); bool Init() override; virtual void PollPositioningPacket(); void SetPacketRate(const double packet_rate) { packet_rate_ = packet_rate; } void DevicePoll(); protected: std::thread poll_thread_; Config config_; std::shared_ptr<apollo::cyber::Writer<VelodyneScan>> writer_; std::unique_ptr<Input> input_ = nullptr; std::unique_ptr<Input> positioning_input_ = nullptr; std::string topic_; double packet_rate_ = 0.0; uint64_t basetime_ = 0; uint32_t last_gps_time_ = 0; uint64_t last_count_ = 0; static uint64_t sync_counter; std::thread positioning_thread_; virtual int PollStandard(std::shared_ptr<VelodyneScan> scan); bool SetBaseTime(); void SetBaseTimeFromNmeaTime(NMEATimePtr nmea_time, uint64_t *basetime); void UpdateGpsTopHour(uint32_t current_time); }; class Velodyne64Driver : public VelodyneDriver { public: explicit Velodyne64Driver(const Config &config) : VelodyneDriver(config) {} Velodyne64Driver(const std::shared_ptr<cyber::Node> &node, const Config &config) { node_ = node; config_ = config; } ~Velodyne64Driver(); bool Init() override; bool Poll(const std::shared_ptr<VelodyneScan> &scan) override; void DevicePoll(); private: bool CheckAngle(const VelodynePacket &packet); int PollStandardSync(std::shared_ptr<VelodyneScan> scan); }; class VelodyneDriverFactory { public: static VelodyneDriver *CreateDriver( const std::shared_ptr<::apollo::cyber::Node> &node, const Config &config); }; } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/input.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/velodyne/driver/input.h" namespace apollo { namespace drivers { namespace velodyne { bool Input::exract_nmea_time_from_packet(NMEATimePtr nmea_time, const uint8_t* bytes) { unsigned int gprmc_index = 206; int field_count = 0; int time_field_index = 0; int validity_field_index = 0; int date_field_index = 0; while (++gprmc_index < POSITIONING_DATA_PACKET_SIZE - 6 && bytes[gprmc_index] != '*') { if (bytes[gprmc_index] == ',') { ++field_count; if (field_count == 1 && time_field_index == 0) { time_field_index = gprmc_index + 1; } else if (field_count == 2 && validity_field_index == 0) { validity_field_index = gprmc_index + 1; if (bytes[validity_field_index] == 'V') { AERROR << "NAV receiver warning, GPS info is invalid!"; return false; } } else if (field_count == 9 && date_field_index == 0) { date_field_index = gprmc_index + 1; break; } } } if (gprmc_index == POSITIONING_DATA_PACKET_SIZE - 6) { return false; } nmea_time->year = static_cast<uint16_t>((bytes[date_field_index + 4] - '0') * 10 + (bytes[date_field_index + 5] - '0')); nmea_time->mon = static_cast<uint16_t>((bytes[date_field_index + 2] - '0') * 10 + (bytes[date_field_index + 3] - '0')); nmea_time->day = static_cast<uint16_t>((bytes[date_field_index] - '0') * 10 + (bytes[date_field_index + 1] - '0')); nmea_time->hour = static_cast<uint16_t>((bytes[time_field_index] - '0') * 10 + (bytes[time_field_index + 1] - '0')); nmea_time->min = static_cast<uint16_t>((bytes[time_field_index + 2] - '0') * 10 + (bytes[time_field_index + 3] - '0')); nmea_time->sec = static_cast<uint16_t>((bytes[time_field_index + 4] - '0') * 10 + (bytes[time_field_index + 5] - '0')); if (nmea_time->year < 0 || nmea_time->year > 99 || nmea_time->mon > 12 || nmea_time->mon < 1 || nmea_time->day > 31 || nmea_time->day < 1 || nmea_time->hour > 23 || nmea_time->hour < 0 || nmea_time->min > 59 || nmea_time->min < 0 || nmea_time->sec > 59 || nmea_time->sec < 0) { AERROR << "Invalid GPS time: " << nmea_time->year << "-" << nmea_time->mon << "-" << nmea_time->day << " " << nmea_time->hour << ":" << nmea_time->min << ":" << nmea_time->sec << ", make sure have connected to GPS device"; return false; } return true; } } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/velodyne_driver_component.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/velodyne/driver/velodyne_driver_component.h" #include <memory> #include <string> #include <thread> #include "cyber/cyber.h" #include "modules/common/util/message_util.h" namespace apollo { namespace drivers { namespace velodyne { bool VelodyneDriverComponent::Init() { AINFO << "Velodyne driver component init"; Config velodyne_config; if (!GetProtoConfig(&velodyne_config)) { return false; } AINFO << "Velodyne config: " << velodyne_config.DebugString(); // start the driver std::shared_ptr<::apollo::cyber::Node> node = apollo::cyber::CreateNode("lidar_drivers"); VelodyneDriver *driver = VelodyneDriverFactory::CreateDriver(node, velodyne_config); if (driver == nullptr) { return false; } dvr_.reset(driver); dvr_->Init(); // spawn device poll thread runing_ = true; return true; } } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/driver64.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include <cmath> #include <ctime> #include <string> #include "modules/common/util/message_util.h" #include "modules/drivers/lidar/velodyne/driver/driver.h" // #include "ros/ros.h" namespace apollo { namespace drivers { namespace velodyne { Velodyne64Driver::~Velodyne64Driver() { if (poll_thread_.joinable()) { poll_thread_.join(); } } bool Velodyne64Driver::Init() { const double frequency = config_.rpm() / 60.0; // expected Hz rate // default number of packets for each scan is a single revolution // (fractions rounded up) config_.set_npackets(static_cast<int>(ceil(packet_rate_ / frequency))); AINFO << "publishing " << config_.npackets() << " packets per scan"; input_.reset(new SocketInput()); input_->init(config_.firing_data_port()); if (node_ == NULL) { AERROR << "node is NULL"; return false; } writer_ = node_->CreateWriter<VelodyneScan>(config_.scan_channel()); poll_thread_ = std::thread(&Velodyne64Driver::DevicePoll, this); return true; } /** poll the device * * @returns true unless end of file reached */ bool Velodyne64Driver::Poll(const std::shared_ptr<VelodyneScan>& scan) { // Allocate a new shared pointer for zero-copy sharing with other nodelets. int poll_result = config_.use_sensor_sync() ? PollStandardSync(scan) : PollStandard(scan); if (poll_result == SOCKET_TIMEOUT || poll_result == RECEIVE_FAIL) { return false; // poll again } if (scan->firing_pkts().empty()) { AINFO << "Get an empty scan from port: " << config_.firing_data_port(); return false; } // publish message using time of last packet read ADEBUG << "Publishing a full Velodyne scan."; scan->mutable_header()->set_timestamp_sec(cyber::Time().Now().ToSecond()); scan->mutable_header()->set_frame_id(config_.frame_id()); scan->set_model(config_.model()); scan->set_mode(config_.mode()); scan->set_basetime(basetime_); return true; } bool Velodyne64Driver::CheckAngle(const VelodynePacket& packet) { // check the angle in every packet // for each model of velodyne 64 the data struct is same , so we don't need to // check the lidar model const unsigned char* raw_ptr = (const unsigned char*)packet.data().c_str(); for (int i = 0; i < BLOCKS_PER_PACKET; ++i) { uint16_t angle = static_cast<uint16_t>(raw_ptr[i * BLOCK_SIZE + 3] * 256 + raw_ptr[i * BLOCK_SIZE + 2]); // for the velodyne64 angle resolution is 0.17~0.2 , so take the angle diff // at 0.3 degree should be a good choice // prefix_angle default = 18000 if (angle > config_.prefix_angle() && std::abs(angle - config_.prefix_angle()) < 30) { return true; } } return false; } int Velodyne64Driver::PollStandardSync(std::shared_ptr<VelodyneScan> scan) { // Since the velodyne delivers data at a very high rate, keep // reading and publishing scans as fast as possible. while (true) { while (true) { // keep reading until full packet received VelodynePacket* packet = scan->add_firing_pkts(); int rc = input_->get_firing_data_packet(packet); if (rc == 0) { // check the angle for every packet if a packet has an angle if (CheckAngle(*packet) && (scan->firing_pkts_size() > 0.5 * config_.npackets())) { return 0; } else { break; // got a full packet? } } if (rc < 0) { return rc; } } // if the only UDP packet lost then recv 1.5*config_.npackets packets at // most if (scan->firing_pkts_size() > 1.5 * config_.npackets()) { return 0; } } return 0; } void Velodyne64Driver::DevicePoll() { while (!apollo::cyber::IsShutdown()) { // poll device until end of file std::shared_ptr<VelodyneScan> scan = std::make_shared<VelodyneScan>(); bool ret = Poll(scan); if (ret) { apollo::common::util::FillHeader("velodyne", scan.get()); writer_->Write(scan); } else { AWARN << "device poll failed"; } } AERROR << "CompVelodyneDriver thread exit"; } } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/BUILD
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") load("//tools:cpplint.bzl", "cpplint") load("//tools/install:install.bzl", "install") package(default_visibility = ["//visibility:public"]) install( name = "install", library_dest = "drivers/lib/lidar/velodyne/driver", targets = [ ":libvelodyne_driver_component.so", ], ) cc_binary( name = "libvelodyne_driver_component.so", linkshared = True, linkstatic = True, deps = [":velodyne_driver_component_lib"], ) cc_library( name = "velodyne_driver_component_lib", srcs = ["velodyne_driver_component.cc"], hdrs = ["velodyne_driver_component.h"], copts = ['-DMODULE_NAME=\\"velodyne\\"'], deps = [ "//cyber", "//modules/common/util:util_tool", "//modules/drivers/lidar/velodyne/driver", ], alwayslink = True ) cc_library( name = "driver", srcs = [ "driver.cc", "driver64.cc", "input.cc", "socket_input.cc", ], hdrs = [ "driver.h", "input.h", "socket_input.h", ], copts = ['-DMODULE_NAME=\\"velodyne\\"'], deps = [ "//cyber", "//modules/common/util:util_tool", "//modules/drivers/lidar/common/driver_factory:driver_base", "//modules/drivers/lidar/proto:config_cc_proto", "//modules/drivers/lidar/proto:velodyne_config_cc_proto", ], ) cpplint()
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/driver/socket_input.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <unistd.h> #include <cstdio> #include "modules/drivers/lidar/velodyne/driver/input.h" namespace apollo { namespace drivers { namespace velodyne { using apollo::drivers::velodyne::VelodynePacket; // static int FIRING_DATA_PORT = 2368; // static int POSITIONING_DATA_PORT = 8308; static const int POLL_TIMEOUT = 1000; // one second (in msec) /** @brief Live Velodyne input from socket. */ class SocketInput : public Input { public: SocketInput(); virtual ~SocketInput(); void init(const int& port) override; int get_firing_data_packet(VelodynePacket* pkt); int get_positioning_data_packet(NMEATimePtr nmea_time); private: int sockfd_; int port_; bool input_available(int timeout); }; } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/launch/velodyne.launch
<cyber> <module> <name>velodyne</name> <dag_conf>/apollo/modules/drivers/lidar/velodyne/dag/velodyne.dag</dag_conf> <process_name>velodyne</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/launch/velodyne64_16.launch
<cyber> <module> <name>velodyne64</name> <dag_conf>/apollo/modules/drivers/lidar/velodyne/dag/velodyne_64_16.dag</dag_conf> <process_name>velodyne</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/launch/velodyne128.launch
<cyber> <module> <name>velodyne128</name> <dag_conf>/apollo/modules/drivers/lidar/velodyne/dag/velodyne128.dag</dag_conf> <process_name>velodyne</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/launch/velodyne16.launch
<cyber> <module> <name>velodyne16</name> <dag_conf>/apollo/modules/drivers/lidar/velodyne/dag/velodyne16.dag</dag_conf> <process_name>velodyne</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/dag/velodyne_64_16.dag
# Define all coms in DAG streaming. ################################################## # drivers # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/driver/libvelodyne_driver_component.so" # 64 components { class_name : "VelodyneDriverComponent" config { name : "velodyne_64_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_conf.pb.txt" } } # 16_front_up components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_front_up_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_conf.pb.txt" } } # 16_front_center components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_front_center_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt" } } # 16_rear_left components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_rear_left_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_left_conf.pb.txt" } } # 16_rear_right components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_rear_right_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_right_conf.pb.txt" } } } ################################################## # convert # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/parser/libvelodyne_convert_component.so" # 64 components { class_name : "VelodyneConvertComponent" config { name : "velodyne_64_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_conf.pb.txt" readers { channel: "/apollo/sensor/velodyne64/VelodyneScan" } } } # 16_front_up_center components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_front_up_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/front/up/Scan" } } } # 16_front_center components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_front_center_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/front/center/Scan" } } } # 16_rear_left components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_rear_left_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_left_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/rear/left/Scan" } } } # 16_rear_right components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_rear_right_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_right_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/rear/right/Scan" } } } } ################################################## # fusion # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/fusion/libvelodyne_fusion_component.so" components { class_name : "PriSecFusionComponent" config { name : "velodyne_fusion" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne_fusion_conf.pb.txt" readers {channel: "/apollo/sensor/lidar16/front/center/PointCloud2"} } } } ################################################## # compensation # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne16_fusion_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar16/fusion/PointCloud2"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne16_front_up_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar16/front/up/PointCloud2"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne64_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_compensator.pb.txt" readers {channel: "/apollo/sensor/velodyne64/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/dag/velodyne16.dag
# Define all coms in DAG streaming. module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/driver/libvelodyne_driver_component.so" components { class_name : "VelodyneDriverComponent" config { name : "velodyne_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt" } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/parser/libvelodyne_convert_component.so" components { class_name : "VelodyneConvertComponent" config { name : "velodyne_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt" readers {channel: "/apollo/sensor/lidar16/Scan"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar16/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/dag/velodyne.dag
# Define all coms in DAG streaming. ################################################## # drivers # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/driver/libvelodyne_driver_component.so" # 128 components { class_name : "VelodyneDriverComponent" config { name : "velodyne_128_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_conf.pb.txt" } } # 16_front_up components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_front_up_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_conf.pb.txt" } } # 16_front_center components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_front_center_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt" } } # 16_rear_left components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_rear_left_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_left_conf.pb.txt" } } # 16_rear_right components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_rear_right_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_right_conf.pb.txt" } } } ################################################## # convert # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/parser/libvelodyne_convert_component.so" # 128 components { class_name : "VelodyneConvertComponent" config { name : "velodyne_128_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_conf.pb.txt" readers { channel: "/apollo/sensor/lidar128/Scan" } } } # 16_front_up_center components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_front_up_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/front/up/Scan" } } } # 16_front_center components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_front_center_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/front/center/Scan" } } } # 16_rear_left components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_rear_left_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_left_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/rear/left/Scan" } } } # 16_rear_right components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_rear_right_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_right_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/rear/right/Scan" } } } } ################################################## # fusion # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/fusion/libvelodyne_fusion_component.so" components { class_name : "PriSecFusionComponent" config { name : "velodyne_fusion" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne_fusion_conf.pb.txt" readers {channel: "/apollo/sensor/lidar16/front/center/PointCloud2"} } } } ################################################## # compensation # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne16_fusion_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar16/fusion/PointCloud2"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne16_front_up_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar16/front/up/PointCloud2"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne128_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar128/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/dag/velodyne_calibration.dag
# Define all coms in DAG streaming. ################################################## # drivers # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/driver/libvelodyne_driver_component.so" # 128 components { class_name : "VelodyneDriverComponent" config { name : "velodyne_128_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_conf.pb.txt" } } # 16_up_center components { class_name : "VelodyneDriverComponent" config { name : "velodyne_16_up_center_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_up_center_conf.pb.txt" } } } ################################################## # convert # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/parser/libvelodyne_convert_component.so" # 128 components { class_name : "VelodyneConvertComponent" config { name : "velodyne_128_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_conf.pb.txt" readers { channel: "/apollo/sensor/lidar128/Scan" } } } # 16_up_center components { class_name : "VelodyneConvertComponent" config { name : "velodyne_16_rear_right_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_up_center_conf.pb.txt" readers { channel: "/apollo/sensor/lidar16/up/center/Scan" } } } } ################################################## # fusion # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/fusion/libvelodyne_fusion_component.so" components { class_name : "PriSecFusionComponent" config { name : "velodyne_fusion" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne_fusion_conf.pb.txt" readers {channel: "/apollo/sensor/lidar16/up/center/PointCloud2"} } } } ################################################## # compensation # ################################################## module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne16_fusion_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar16/fusion/PointCloud2"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne128_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar128/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/dag/velodyne64.dag
# Define all coms in DAG streaming. module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/driver/libvelodyne_driver_component.so" components { class_name : "VelodyneDriverComponent" config { name : "velodyne_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_conf.pb.txt" } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/parser/libvelodyne_convert_component.so" components { class_name : "VelodyneConvertComponent" config { name : "velodyne_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_conf.pb.txt" readers {channel: "/apollo/sensor/velodyne64/VelodyneScan"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_compensator.pb.txt" readers {channel: "/apollo/sensor/velodyne64/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/dag/velodyne128.dag
# Define all coms in DAG streaming. module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/driver/libvelodyne_driver_component.so" components { class_name : "VelodyneDriverComponent" config { name : "velodyne_driver" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_conf.pb.txt" } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/parser/libvelodyne_convert_component.so" components { class_name : "VelodyneConvertComponent" config { name : "velodyne_convert" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_conf.pb.txt" readers {channel: "/apollo/sensor/lidar128/Scan"} } } } module_config { module_library : "/apollo/bazel-bin/modules/drivers/lidar/velodyne/compensator/libvelodyne_compensator_component.so" components { class_name : "CompensatorComponent" config { name : "velodyne_compensator" config_file_path : "/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_fusion_compensator.pb.txt" readers {channel: "/apollo/sensor/lidar128/PointCloud2"} } } }
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/calibration.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /** * \file calibration.cc * \brief * * \author Piyush Khandelwal (piyushk@cs.utexas.edu) * Copyright (C) 2012, Austin Robot Technology, * The University of Texas at Austin * * License: Modified BSD License * * $ Id: 02/14/2012 11:36:36 AM piyushk $ */ #include "modules/drivers/lidar/velodyne/parser/calibration.h" #include <cmath> #include <fstream> #include <iostream> #include <limits> #include <string> #include <utility> #include "yaml-cpp/yaml.h" namespace YAML { // The >> operator disappeared in yaml-cpp 0.5, so this function is // added to provide support for code written under the yaml-cpp 0.3 API. template <typename T> void operator>>(const YAML::Node& node, T& i) { i = node.as<T>(); } } // namespace YAML namespace apollo { namespace drivers { namespace velodyne { const char* NUM_LASERS = "num_lasers"; const char* LASERS = "lasers"; const char* LASER_ID = "laser_id"; const char* ROT_CORRECTION = "rot_correction"; const char* VERT_CORRECTION = "vert_correction"; const char* DIST_CORRECTION = "dist_correction"; const char* TWO_PT_CORRECTION_AVAILABLE = "two_pt_correction_available"; const char* DIST_CORRECTION_X = "dist_correction_x"; const char* DIST_CORRECTION_Y = "dist_correction_y"; const char* VERT_OFFSET_CORRECTION = "vert_offset_correction"; const char* HORIZ_OFFSET_CORRECTION = "horiz_offset_correction"; const char* MAX_INTENSITY = "max_intensity"; const char* MIN_INTENSITY = "min_intensity"; const char* FOCAL_DISTANCE = "focal_distance"; const char* FOCAL_SLOPE = "focal_slope"; void operator>>(const YAML::Node& node, std::pair<int, LaserCorrection>& correction) { node[LASER_ID] >> correction.first; node[ROT_CORRECTION] >> correction.second.rot_correction; node[VERT_CORRECTION] >> correction.second.vert_correction; node[DIST_CORRECTION] >> correction.second.dist_correction; node[DIST_CORRECTION_X] >> correction.second.dist_correction_x; node[DIST_CORRECTION_Y] >> correction.second.dist_correction_y; node[VERT_OFFSET_CORRECTION] >> correction.second.vert_offset_correction; if (node[HORIZ_OFFSET_CORRECTION]) { node[HORIZ_OFFSET_CORRECTION] >> correction.second.horiz_offset_correction; } else { correction.second.horiz_offset_correction = 0.0; } if (node[MAX_INTENSITY]) { node[MAX_INTENSITY] >> correction.second.max_intensity; } else { correction.second.max_intensity = 255; } if (node[MIN_INTENSITY]) { node[MIN_INTENSITY] >> correction.second.min_intensity; } else { correction.second.min_intensity = 0; } node[FOCAL_DISTANCE] >> correction.second.focal_distance; node[FOCAL_SLOPE] >> correction.second.focal_slope; // Calculate cached values correction.second.cos_rot_correction = cosf(correction.second.rot_correction); correction.second.sin_rot_correction = sinf(correction.second.rot_correction); correction.second.cos_vert_correction = cosf(correction.second.vert_correction); correction.second.sin_vert_correction = sinf(correction.second.vert_correction); correction.second.focal_offset = 256.0f * static_cast<float>(std::pow( 1 - correction.second.focal_distance / 13100.0f, 2)); correction.second.laser_ring = 0; // clear initially (set later) } void operator>>(const YAML::Node& node, Calibration& calibration) { int num_lasers = 0; node[NUM_LASERS] >> num_lasers; const YAML::Node& lasers = node[LASERS]; calibration.laser_corrections_.clear(); calibration.num_lasers_ = num_lasers; if (static_cast<int>(lasers.size()) != num_lasers) { std::cerr << "num_lasers didn't match"; return; } for (int i = 0; i < num_lasers; i++) { std::pair<int, LaserCorrection> correction; lasers[i] >> correction; calibration.laser_corrections_.insert(correction); } // For each laser ring, find the next-smallest vertical angle. // // This implementation is simple, but not efficient. That is OK, // since it only runs while starting up. double next_angle = -std::numeric_limits<double>::infinity(); for (int ring = 0; ring < num_lasers; ++ring) { // find minimum remaining vertical offset correction double min_seen = std::numeric_limits<double>::infinity(); int next_index = num_lasers; for (int j = 0; j < num_lasers; ++j) { double angle = calibration.laser_corrections_[j].vert_correction; if (next_angle < angle && angle < min_seen) { min_seen = angle; next_index = j; } } if (next_index < num_lasers) { // anything found in this ring? // store this ring number with its corresponding laser number calibration.laser_corrections_[next_index].laser_ring = ring; next_angle = min_seen; } } } YAML::Emitter& operator<<(YAML::Emitter& out, const std::pair<int, LaserCorrection>& correction) { out << YAML::BeginMap; out << YAML::Key << LASER_ID << YAML::Value << correction.first; out << YAML::Key << ROT_CORRECTION << YAML::Value << correction.second.rot_correction; out << YAML::Key << VERT_CORRECTION << YAML::Value << correction.second.vert_correction; out << YAML::Key << DIST_CORRECTION << YAML::Value << correction.second.dist_correction; out << YAML::Key << DIST_CORRECTION_X << YAML::Value << correction.second.dist_correction_x; out << YAML::Key << DIST_CORRECTION_Y << YAML::Value << correction.second.dist_correction_y; out << YAML::Key << VERT_OFFSET_CORRECTION << YAML::Value << correction.second.vert_offset_correction; out << YAML::Key << HORIZ_OFFSET_CORRECTION << YAML::Value << correction.second.horiz_offset_correction; out << YAML::Key << MAX_INTENSITY << YAML::Value << correction.second.max_intensity; out << YAML::Key << MIN_INTENSITY << YAML::Value << correction.second.min_intensity; out << YAML::Key << FOCAL_DISTANCE << YAML::Value << correction.second.focal_distance; out << YAML::Key << FOCAL_SLOPE << YAML::Value << correction.second.focal_slope; out << YAML::EndMap; return out; } YAML::Emitter& operator<<(YAML::Emitter& out, const Calibration& calibration) { out << YAML::BeginMap; out << YAML::Key << NUM_LASERS << YAML::Value << calibration.laser_corrections_.size(); out << YAML::Key << LASERS << YAML::Value << YAML::BeginSeq; for (std::map<int, LaserCorrection>::const_iterator it = calibration.laser_corrections_.begin(); it != calibration.laser_corrections_.end(); ++it) { out << *it; } out << YAML::EndSeq; out << YAML::EndMap; return out; } void Calibration::read(const std::string& calibration_file) { std::ifstream fin(calibration_file.c_str()); if (!fin.is_open()) { initialized_ = false; return; } initialized_ = true; try { YAML::Node doc; fin.close(); doc = YAML::LoadFile(calibration_file); doc >> *this; } catch (YAML::Exception& e) { std::cerr << "YAML Exception: " << e.what() << std::endl; initialized_ = false; } fin.close(); } void Calibration::write(const std::string& calibration_file) { std::ofstream fout(calibration_file.c_str()); YAML::Emitter out; out << *this; fout << out.c_str(); fout.close(); } } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/const_variables.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <iostream> namespace apollo { namespace drivers { namespace velodyne { /** * @brief Order array for re-ordering point cloud. * Refer to Velodyne official manual */ const int ORDER_16[16] = {0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15}; const int ORDER_HDL32E[32] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}; const int ORDER_64[64] = {38, 39, 42, 43, 32, 33, 36, 37, 40, 41, 46, 47, 50, 51, 54, 55, 44, 45, 48, 49, 52, 53, 58, 59, 62, 63, 34, 35, 56, 57, 60, 61, 6, 7, 10, 11, 0, 1, 4, 5, 8, 9, 14, 15, 18, 19, 22, 23, 12, 13, 16, 17, 20, 21, 26, 27, 30, 31, 2, 3, 24, 25, 28, 29}; // micro second const float INNER_TIME_64[12][32] = { {419.30f, 418.57f, 417.84f, 417.12f, 416.39f, 415.66f, 414.93f, 414.20f, 413.48f, 412.75f, 412.02f, 411.29f, 410.56f, 409.84f, 409.11f, 408.38f, 407.65f, 406.92f, 406.20f, 405.47f, 404.74f, 404.01f, 403.28f, 402.56f, 401.83f, 401.10f, 400.37f, 399.64f, 398.92f, 398.19f, 397.46f, 396.73f}, {419.30f, 418.57f, 417.84f, 417.12f, 416.39f, 415.66f, 414.93f, 414.20f, 413.48f, 412.75f, 412.02f, 411.29f, 410.56f, 409.84f, 409.11f, 408.38f, 407.65f, 406.92f, 406.20f, 405.47f, 404.74f, 404.01f, 403.28f, 402.56f, 401.83f, 401.10f, 400.37f, 399.64f, 398.92f, 398.19f, 397.46f, 396.73f}, {396.00f, 395.28f, 394.55f, 393.82f, 393.09f, 392.36f, 391.64f, 390.91f, 390.18f, 389.45f, 388.72f, 388.00f, 387.27f, 386.54f, 385.81f, 385.08f, 384.36f, 383.63f, 382.90f, 382.17f, 381.44f, 380.72f, 379.99f, 379.26f, 378.53f, 377.80f, 377.08f, 376.35f, 375.62f, 374.89f, 374.16f, 373.44f}, {396.00f, 395.28f, 394.55f, 393.82f, 393.09f, 392.36f, 391.64f, 390.91f, 390.18f, 389.45f, 388.72f, 388.00f, 387.27f, 386.54f, 385.81f, 385.08f, 384.36f, 383.63f, 382.90f, 382.17f, 381.44f, 380.72f, 379.99f, 379.26f, 378.53f, 377.80f, 377.08f, 376.35f, 375.62f, 374.89f, 374.16f, 373.44f}, {372.71f, 371.98f, 371.25f, 370.52f, 369.80f, 369.07f, 368.34f, 367.61f, 366.88f, 366.16f, 365.43f, 364.70f, 363.97f, 363.24f, 362.52f, 361.79f, 361.06f, 360.33f, 359.60f, 358.88f, 358.15f, 357.42f, 356.69f, 355.96f, 355.24f, 354.51f, 353.78f, 353.05f, 352.32f, 351.60f, 350.87f, 350.14f}, {372.71f, 371.98f, 371.25f, 370.52f, 369.80f, 369.07f, 368.34f, 367.61f, 366.88f, 366.16f, 365.43f, 364.70f, 363.97f, 363.24f, 362.52f, 361.79f, 361.06f, 360.33f, 359.60f, 358.88f, 358.15f, 357.42f, 356.69f, 355.96f, 355.24f, 354.51f, 353.78f, 353.05f, 352.32f, 351.60f, 350.87f, 350.14f}, {349.41f, 348.68f, 347.96f, 347.23f, 346.50f, 345.77f, 345.04f, 344.32f, 343.59f, 342.86f, 342.13f, 341.40f, 340.68f, 339.95f, 339.22f, 338.49f, 337.76f, 337.04f, 336.31f, 335.58f, 334.85f, 334.12f, 333.40f, 332.67f, 331.94f, 331.21f, 330.48f, 329.76f, 329.03f, 328.30f, 327.57f, 326.84f}, {349.41f, 348.68f, 347.96f, 347.23f, 346.50f, 345.77f, 345.04f, 344.32f, 343.59f, 342.86f, 342.13f, 341.40f, 340.68f, 339.95f, 339.22f, 338.49f, 337.76f, 337.04f, 336.31f, 335.58f, 334.85f, 334.12f, 333.40f, 332.67f, 331.94f, 331.21f, 330.48f, 329.76f, 329.03f, 328.30f, 327.57f, 326.84f}, {326.12f, 325.39f, 324.66f, 323.93f, 323.20f, 322.48f, 321.75f, 321.02f, 320.29f, 319.56f, 318.84f, 318.11f, 317.38f, 316.65f, 315.92f, 315.20f, 314.47f, 313.74f, 313.01f, 312.28f, 311.56f, 310.83f, 310.10f, 309.37f, 308.64f, 307.92f, 307.19f, 306.46f, 305.73f, 305.00f, 304.28f, 303.55f}, {326.12f, 325.39f, 324.66f, 323.93f, 323.20f, 322.48f, 321.75f, 321.02f, 320.29f, 319.56f, 318.84f, 318.11f, 317.38f, 316.65f, 315.92f, 315.20f, 314.47f, 313.74f, 313.01f, 312.28f, 311.56f, 310.83f, 310.10f, 309.37f, 308.64f, 307.92f, 307.19f, 306.46f, 305.73f, 305.00f, 304.28f, 303.55f}, {302.82f, 302.09f, 301.36f, 300.64f, 299.91f, 299.18f, 298.45f, 297.72f, 297.00f, 296.27f, 295.54f, 294.81f, 294.08f, 293.36f, 292.63f, 291.90f, 291.17f, 290.44f, 289.72f, 288.99f, 288.26f, 287.53f, 286.80f, 286.08f, 285.35f, 284.62f, 283.89f, 283.16f, 282.44f, 281.71f, 280.98f, 280.25f}, {302.82f, 302.09f, 301.36f, 300.64f, 299.91f, 299.18f, 298.45f, 297.72f, 297.00f, 296.27f, 295.54f, 294.81f, 294.08f, 293.36f, 292.63f, 291.90f, 291.17f, 290.44f, 289.72f, 288.99f, 288.26f, 287.53f, 286.80f, 286.08f, 285.35f, 284.62f, 283.89f, 283.16f, 282.44f, 281.71f, 280.98f, 280.25f}}; const float INNER_TIME_64E_S3[12][32] = { {172.8f, 171.5f, 170.3f, 169.1f, 165.6f, 164.3f, 163.1f, 161.9f, 158.4f, 157.1f, 155.9f, 154.7f, 151.2f, 149.9f, 148.7f, 147.5f, 144.0f, 142.7f, 141.5f, 140.3f, 136.8f, 135.5f, 134.3f, 133.1f, 129.6f, 128.3f, 127.1f, 125.9f, 122.4f, 121.1f, 119.9f, 118.7f}, {172.8f, 171.5f, 170.3f, 169.1f, 165.6f, 164.3f, 163.1f, 161.9f, 158.4f, 157.1f, 155.9f, 154.7f, 151.2f, 149.9f, 148.7f, 147.5f, 144.0f, 142.7f, 141.5f, 140.3f, 136.8f, 135.5f, 134.3f, 133.1f, 129.6f, 128.3f, 127.1f, 125.9f, 122.4f, 121.1f, 119.9f, 118.7f}, {172.8f, 171.5f, 170.3f, 169.1f, 165.6f, 164.3f, 163.1f, 161.9f, 158.4f, 157.1f, 155.9f, 154.7f, 151.2f, 149.9f, 148.7f, 147.5f, 144.0f, 142.7f, 141.5f, 140.3f, 136.8f, 135.5f, 134.3f, 133.1f, 129.6f, 128.3f, 127.1f, 125.9f, 122.4f, 121.1f, 119.9f, 118.7f}, {172.8f, 171.5f, 170.3f, 169.1f, 165.6f, 164.3f, 163.1f, 161.9f, 158.4f, 157.1f, 155.9f, 154.7f, 151.2f, 149.9f, 148.7f, 147.5f, 144.0f, 142.7f, 141.5f, 140.3f, 136.8f, 135.5f, 134.3f, 133.1f, 129.6f, 128.3f, 127.1f, 125.9f, 122.4f, 121.1f, 119.9f, 118.7f}, {115.2f, 113.9f, 112.7f, 111.5f, 108.0f, 106.7f, 105.5f, 104.3f, 100.8f, 99.5f, 98.3f, 97.1f, 93.6f, 92.3f, 91.1f, 89.9f, 86.4f, 85.1f, 83.9f, 82.7f, 79.2f, 77.9f, 76.7f, 75.5f, 72.0f, 70.7f, 69.5f, 68.3f, 64.8f, 63.5f, 62.3f, 61.1f}, {115.2f, 113.9f, 112.7f, 111.5f, 108.0f, 106.7f, 105.5f, 104.3f, 100.8f, 99.5f, 98.3f, 97.1f, 93.6f, 92.3f, 91.1f, 89.9f, 86.4f, 85.1f, 83.9f, 82.7f, 79.2f, 77.9f, 76.7f, 75.5f, 72.0f, 70.7f, 69.5f, 68.3f, 64.8f, 63.5f, 62.3f, 61.1f}, {115.2f, 113.9f, 112.7f, 111.5f, 108.0f, 106.7f, 105.5f, 104.3f, 100.8f, 99.5f, 98.3f, 97.1f, 93.6f, 92.3f, 91.1f, 89.9f, 86.4f, 85.1f, 83.9f, 82.7f, 79.2f, 77.9f, 76.7f, 75.5f, 72.0f, 70.7f, 69.5f, 68.3f, 64.8f, 63.5f, 62.3f, 61.1f}, {115.2f, 113.9f, 112.7f, 111.5f, 108.0f, 106.7f, 105.5f, 104.3f, 100.8f, 99.5f, 98.3f, 97.1f, 93.6f, 92.3f, 91.1f, 89.9f, 86.4f, 85.1f, 83.9f, 82.7f, 79.2f, 77.9f, 76.7f, 75.5f, 72.0f, 70.7f, 69.5f, 68.3f, 64.8f, 63.5f, 62.3f, 61.1f}, {57.6f, 56.3f, 55.1f, 53.9f, 50.4f, 49.1f, 47.9f, 46.7f, 43.2f, 41.9f, 40.7f, 39.5f, 36.0f, 34.7f, 33.5f, 32.3f, 28.8f, 27.5f, 26.3f, 25.1f, 21.6f, 20.3f, 19.1f, 17.9f, 14.4f, 13.1f, 11.9f, 10.7f, 7.2f, 5.9f, 4.7f, 3.5f}, {57.6f, 56.3f, 55.1f, 53.9f, 50.4f, 49.1f, 47.9f, 46.7f, 43.2f, 41.9f, 40.7f, 39.5f, 36.0f, 34.7f, 33.5f, 32.3f, 28.8f, 27.5f, 26.3f, 25.1f, 21.6f, 20.3f, 19.1f, 17.9f, 14.4f, 13.1f, 11.9f, 10.7f, 7.2f, 5.9f, 4.7f, 3.5f}, {57.6f, 56.3f, 55.1f, 53.9f, 50.4f, 49.1f, 47.9f, 46.7f, 43.2f, 41.9f, 40.7f, 39.5f, 36.0f, 34.7f, 33.5f, 32.3f, 28.8f, 27.5f, 26.3f, 25.1f, 21.6f, 20.3f, 19.1f, 17.9f, 14.4f, 13.1f, 11.9f, 10.7f, 7.2f, 5.9f, 4.7f, 3.5f}, {57.6f, 56.3f, 55.1f, 53.9f, 50.4f, 49.1f, 47.9f, 46.7f, 43.2f, 41.9f, 40.7f, 39.5f, 36.0f, 34.7f, 33.5f, 32.3f, 28.8f, 27.5f, 26.3f, 25.1f, 21.6f, 20.3f, 19.1f, 17.9f, 14.4f, 13.1f, 11.9f, 10.7f, 7.2f, 5.9f, 4.7f, 3.5f}}; // micro second const float INNER_TIME_HDL32E[12][32] = { {543.0f, 541.0f, 540.0f, 539.0f, 538.0f, 537.0f, 536.0f, 535.0f, 533.0f, 532.0f, 531.0f, 530.0f, 529.0f, 528.0f, 526.0f, 525.0f, 524.0f, 523.0f, 522.0f, 521.0f, 520.0f, 518.0f, 517.0f, 516.0f, 515.0f, 514.0f, 513.0f, 511.0f, 510.0f, 509.0f, 508.0f, 507.0f}, {497.0f, 495.0f, 494.0f, 493.0f, 492.0f, 491.0f, 490.0f, 488.0f, 487.0f, 486.0f, 485.0f, 484.0f, 483.0f, 482.0f, 480.0f, 479.0f, 478.0f, 477.0f, 476.0f, 475.0f, 473.0f, 472.0f, 471.0f, 470.0f, 469.0f, 468.0f, 467.0f, 465.0f, 464.0f, 463.0f, 462.0f, 461.0f}, {450.0f, 449.0f, 448.0f, 447.0f, 446.0f, 445.0f, 444.0f, 442.0f, 441.0f, 440.0f, 439.0f, 438.0f, 437.0f, 435.0f, 434.0f, 433.0f, 432.0f, 431.0f, 430.0f, 429.0f, 427.0f, 426.0f, 425.0f, 424.0f, 423.0f, 422.0f, 420.0f, 419.0f, 418.0f, 417.0f, 416.0f, 415.0f}, {404.0f, 403.0f, 402.0f, 401.0f, 400.0f, 399.0f, 397.0f, 396.0f, 395.0f, 394.0f, 393.0f, 392.0f, 391.0f, 389.0f, 388.0f, 387.0f, 386.0f, 385.0f, 384.0f, 382.0f, 381.0f, 380.0f, 379.0f, 378.0f, 377.0f, 376.0f, 374.0f, 373.0f, 372.0f, 371.0f, 370.0f, 369.0f}, {358.0f, 357.0f, 356.0f, 355.0f, 354.0f, 353.0f, 351.0f, 350.0f, 349.0f, 348.0f, 347.0f, 346.0f, 344.0f, 343.0f, 342.0f, 341.0f, 340.0f, 339.0f, 338.0f, 336.0f, 335.0f, 334.0f, 333.0f, 332.0f, 331.0f, 329.0f, 328.0f, 327.0f, 326.0f, 325.0f, 324.0f, 323.0f}, {312.0f, 311.0f, 310.0f, 309.0f, 308.0f, 306.0f, 305.0f, 304.0f, 303.0f, 302.0f, 301.0f, 300.0f, 298.0f, 297.0f, 296.0f, 295.0f, 294.0f, 293.0f, 291.0f, 290.0f, 289.0f, 288.0f, 287.0f, 286.0f, 285.0f, 283.0f, 282.0f, 281.0f, 280.0f, 279.0f, 278.0f, 276.0f}, {266.0f, 265.0f, 264.0f, 263.0f, 262.0f, 260.0f, 259.0f, 258.0f, 257.0f, 256.0f, 255.0f, 253.0f, 252.0f, 251.0f, 250.0f, 249.0f, 248.0f, 247.0f, 245.0f, 244.0f, 243.0f, 242.0f, 241.0f, 240.0f, 238.0f, 237.0f, 236.0f, 235.0f, 234.0f, 233.0f, 232.0f, 230.0f}, {220.0f, 219.0f, 218.0f, 217.0f, 215.0f, 214.0f, 213.0f, 212.0f, 211.0f, 210.0f, 209.0f, 207.0f, 206.0f, 205.0f, 204.0f, 203.0f, 202.0f, 200.0f, 199.0f, 198.0f, 197.0f, 196.0f, 195.0f, 194.0f, 192.0f, 191.0f, 190.0f, 189.0f, 188.0f, 187.0f, 185.0f, 184.0f}, {174.0f, 173.0f, 172.0f, 170.0f, 169.0f, 168.0f, 167.0f, 166.0f, 165.0f, 164.0f, 162.0f, 161.0f, 160.0f, 159.0f, 158.0f, 157.0f, 156.0f, 154.0f, 153.0f, 152.0f, 151.0f, 150.0f, 149.0f, 147.0f, 146.0f, 145.0f, 144.0f, 143.0f, 142.0f, 141.0f, 139.0f, 138.0f}, {128.0f, 127.0f, 126.0f, 124.0f, 123.0f, 122.0f, 121.0f, 120.0f, 119.0f, 118.0f, 116.0f, 115.0f, 114.0f, 113.0f, 112.0f, 111.0f, 109.0f, 108.0f, 107.0f, 106.0f, 105.0f, 104.0f, 103.0f, 101.0f, 100.0f, 99.0f, 98.0f, 97.0f, 96.0f, 94.0f, 93.0f, 92.0f}, {82.0f, 81.0f, 79.0f, 78.0f, 77.0f, 76.0f, 75.0f, 74.0f, 73.0f, 71.0f, 70.0f, 69.0f, 68.0f, 67.0f, 66.0f, 65.0f, 63.0f, 62.0f, 61.0f, 60.0f, 59.0f, 58.0f, 56.0f, 55.0f, 54.0f, 53.0f, 52.0f, 51.0f, 50.0f, 48.0f, 47.0f, 46.0f}, {36.0f, 35.0f, 33.0f, 32.0f, 31.0f, 30.0f, 29.0f, 28.0f, 26.0f, 25.0f, 24.0f, 23.0f, 22.0f, 21.0f, 20.0f, 18.0f, 17.0f, 16.0f, 15.0f, 14.0f, 13.0f, 12.0f, 10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 3.0f, 2.0f, 1.0f, 0.0f}}; const float INNER_TIME_16[12][32] = { {-0.0f, -2.3f, -4.61f, -6.91f, -9.22f, -11.52f, -13.82f, -16.13f, -18.43f, -20.74f, -23.04f, -25.34f, -27.65f, -29.95f, -32.26f, -34.56f, -55.3f, -57.6f, -59.9f, -62.21f, -64.51f, -66.82f, -69.12f, -71.42f, -73.73f, -76.03f, -78.34f, -80.64f, -82.94f, -85.25f, -87.55f, -89.86f}, {-110.59f, -112.9f, -115.2f, -117.5f, -119.81f, -122.11f, -124.42f, -126.72f, -129.02f, -131.33f, -133.63f, -135.94f, -138.24f, -140.54f, -142.85f, -145.15f, -165.89f, -168.19f, -170.5f, -172.8f, -175.1f, -177.41f, -179.71f, -182.02f, -184.32f, -186.62f, -188.93f, -191.23f, -193.54f, -195.84f, -198.14f, -200.45f}, {-221.18f, -223.49f, -225.79f, -228.1f, -230.4f, -232.7f, -235.01f, -237.31f, -239.62f, -241.92f, -244.22f, -246.53f, -248.83f, -251.14f, -253.44f, -255.74f, -276.48f, -278.78f, -281.09f, -283.39f, -285.7f, -288.0f, -290.3f, -292.61f, -294.91f, -297.22f, -299.52f, -301.82f, -304.13f, -306.43f, -308.74f, -311.04f}, {-331.78f, -334.08f, -336.38f, -338.69f, -340.99f, -343.3f, -345.6f, -347.9f, -350.21f, -352.51f, -354.82f, -357.12f, -359.42f, -361.73f, -364.03f, -366.34f, -387.07f, -389.38f, -391.68f, -393.98f, -396.29f, -398.59f, -400.9f, -403.2f, -405.5f, -407.81f, -410.11f, -412.42f, -414.72f, -417.02f, -419.33f, -421.63f}, {-442.37f, -444.67f, -446.98f, -449.28f, -451.58f, -453.89f, -456.19f, -458.5f, -460.8f, -463.1f, -465.41f, -467.71f, -470.02f, -472.32f, -474.62f, -476.93f, -497.66f, -499.97f, -502.27f, -504.58f, -506.88f, -509.18f, -511.49f, -513.79f, -516.1f, -518.4f, -520.7f, -523.01f, -525.31f, -527.62f, -529.92f, -532.22f}, {-552.96f, -555.26f, -557.57f, -559.87f, -562.18f, -564.48f, -566.78f, -569.09f, -571.39f, -573.7f, -576.0f, -578.3f, -580.61f, -582.91f, -585.22f, -587.52f, -608.26f, -610.56f, -612.86f, -615.17f, -617.47f, -619.78f, -622.08f, -624.38f, -626.69f, -628.99f, -631.3f, -633.6f, -635.9f, -638.21f, -640.51f, -642.82f}, {-663.55f, -665.86f, -668.16f, -670.46f, -672.77f, -675.07f, -677.38f, -679.68f, -681.98f, -684.29f, -686.59f, -688.9f, -691.2f, -693.5f, -695.81f, -698.11f, -718.85f, -721.15f, -723.46f, -725.76f, -728.06f, -730.37f, -732.67f, -734.98f, -737.28f, -739.58f, -741.89f, -744.19f, -746.5f, -748.8f, -751.1f, -753.41f}, {-774.14f, -776.45f, -778.75f, -781.06f, -783.36f, -785.66f, -787.97f, -790.27f, -792.58f, -794.88f, -797.18f, -799.49f, -801.79f, -804.1f, -806.4f, -808.7f, -829.44f, -831.74f, -834.05f, -836.35f, -838.66f, -840.96f, -843.26f, -845.57f, -847.87f, -850.18f, -852.48f, -854.78f, -857.09f, -859.39f, -861.7f, -864.0f}, {-884.74f, -887.04f, -889.34f, -891.65f, -893.95f, -896.26f, -898.56f, -900.86f, -903.17f, -905.47f, -907.78f, -910.08f, -912.38f, -914.69f, -916.99f, -919.3f, -940.03f, -942.34f, -944.64f, -946.94f, -949.25f, -951.55f, -953.86f, -956.16f, -958.46f, -960.77f, -963.07f, -965.38f, -967.68f, -969.98f, -972.29f, -974.59f}, {-995.33f, -997.63f, -999.94f, -1002.24f, -1004.54f, -1006.85f, -1009.15f, -1011.46f, -1013.76f, -1016.06f, -1018.37f, -1020.67f, -1022.98f, -1025.28f, -1027.58f, -1029.89f, -1050.62f, -1052.93f, -1055.23f, -1057.54f, -1059.84f, -1062.14f, -1064.45f, -1066.75f, -1069.06f, -1071.36f, -1073.66f, -1075.97f, -1078.27f, -1080.58f, -1082.88f, -1085.18f}, {-1105.92f, -1108.22f, -1110.53f, -1112.83f, -1115.14f, -1117.44f, -1119.74f, -1122.05f, -1124.35f, -1126.66f, -1128.96f, -1131.26f, -1133.57f, -1135.87f, -1138.18f, -1140.48f, -1161.22f, -1163.52f, -1165.82f, -1168.13f, -1170.43f, -1172.74f, -1175.04f, -1177.34f, -1179.65f, -1181.95f, -1184.26f, -1186.56f, -1188.86f, -1191.17f, -1193.47f, -1195.78f}, {-1216.51f, -1218.82f, -1221.12f, -1223.42f, -1225.73f, -1228.03f, -1230.34f, -1232.64f, -1234.94f, -1237.25f, -1239.55f, -1241.86f, -1244.16f, -1246.46f, -1248.77f, -1251.07f, -1271.81f, -1274.11f, -1276.42f, -1278.72f, -1281.02f, -1283.33f, -1285.63f, -1287.94f, -1290.24f, -1292.54f, -1294.85f, -1297.15f, -1299.46f, -1301.76f, -1304.06f, -1306.37f}}; const float INNER_TIME_128[12][32] = { {-8.7f, -8.7f, -8.7f, -8.7f, -8.7f, -8.7f, -8.7f, -8.7f, -6.0f, -6.0f, -6.0f, -6.0f, -6.0f, -6.0f, -6.0f, -6.0f, -3.4f, -3.4f, -3.4f, -3.4f, -3.4f, -3.4f, -3.4f, -3.4f, -0.7f, -0.7f, -0.7f, -0.7f, -0.7f, -0.7f, -0.7f, -0.7f}, {2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 4.6f, 4.6f, 4.6f, 4.6f, 4.6f, 4.6f, 4.6f, 4.6f, 7.3f, 7.3f, 7.3f, 7.3f, 7.3f, 7.3f, 7.3f, 7.3f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f}, {15.3f, 15.3f, 15.3f, 15.3f, 15.3f, 15.3f, 15.3f, 15.3f, 18.0f, 18.0f, 18.0f, 18.0f, 18.0f, 18.0f, 18.0f, 18.0f, 20.6f, 20.6f, 20.6f, 20.6f, 20.6f, 20.6f, 20.6f, 20.6f, 23.3f, 23.3f, 23.3f, 23.3f, 23.3f, 23.3f, 23.3f, 23.3f}, {25.9f, 25.9f, 25.9f, 25.9f, 25.9f, 25.9f, 25.9f, 25.9f, 28.6f, 28.6f, 28.6f, 28.6f, 28.6f, 28.6f, 28.6f, 28.6f, 31.3f, 31.3f, 31.3f, 31.3f, 31.3f, 31.3f, 31.3f, 31.3f, 33.9f, 33.9f, 33.9f, 33.9f, 33.9f, 33.9f, 33.9f, 33.9f}, {44.6f, 44.6f, 44.6f, 44.6f, 44.6f, 44.6f, 44.6f, 44.6f, 47.3f, 47.3f, 47.3f, 47.3f, 47.3f, 47.3f, 47.3f, 47.3f, 49.9f, 49.9f, 49.9f, 49.9f, 49.9f, 49.9f, 49.9f, 49.9f, 52.6f, 52.6f, 52.6f, 52.6f, 52.6f, 52.6f, 52.6f, 52.6f}, {55.3f, 55.3f, 55.3f, 55.3f, 55.3f, 55.3f, 55.3f, 55.3f, 57.9f, 57.9f, 57.9f, 57.9f, 57.9f, 57.9f, 57.9f, 57.9f, 60.6f, 60.6f, 60.6f, 60.6f, 60.6f, 60.6f, 60.6f, 60.6f, 63.3f, 63.3f, 63.3f, 63.3f, 63.3f, 63.3f, 63.3f, 63.3f}, {68.6f, 68.6f, 68.6f, 68.6f, 68.6f, 68.6f, 68.6f, 68.6f, 71.3f, 71.3f, 71.3f, 71.3f, 71.3f, 71.3f, 71.3f, 71.3f, 73.9f, 73.9f, 73.9f, 73.9f, 73.9f, 73.9f, 73.9f, 73.9f, 76.6f, 76.6f, 76.6f, 76.6f, 76.6f, 76.6f, 76.6f, 76.6f}, {79.2f, 79.2f, 79.2f, 79.2f, 79.2f, 79.2f, 79.2f, 79.2f, 81.9f, 81.9f, 81.9f, 81.9f, 81.9f, 81.9f, 81.9f, 81.9f, 84.6f, 84.9f, 84.9f, 84.9f, 84.9f, 84.9f, 84.9f, 84.9f, 87.2f, 87.2f, 87.2f, 87.2f, 87.2f, 87.2f, 87.2f, 87.2f}, {97.9f, 97.9f, 97.9f, 97.9f, 97.9f, 97.9f, 97.9f, 97.9f, 100.6f, 100.6f, 100.6f, 100.6f, 100.6f, 100.6f, 100.6f, 100.6f, 103.2f, 103.2f, 103.2f, 103.2f, 103.2f, 103.2f, 103.2f, 103.2f, 105.9f, 105.9f, 105.9f, 105.9f, 105.9f, 105.9f, 105.9f, 105.9f}, {108.6f, 108.6f, 108.6f, 108.6f, 108.6f, 108.6f, 108.6f, 108.6f, 111.2f, 111.2f, 111.2f, 111.2f, 111.2f, 111.2f, 111.2f, 111.2f, 113.9f, 113.9f, 113.9f, 113.9f, 113.9f, 113.9f, 113.9f, 113.9f, 116.6f, 116.6f, 116.6f, 116.6f, 116.6f, 116.6f, 116.6f, 116.6f}, {121.9f, 121.9f, 121.9f, 121.9f, 121.9f, 121.9f, 121.9f, 121.9f, 124.6f, 124.6f, 124.6f, 124.6f, 124.6f, 124.6f, 124.6f, 124.6f, 127.2f, 127.2f, 127.2f, 127.2f, 127.2f, 127.2f, 127.2f, 127.2f, 129.9f, 129.9f, 129.9f, 129.9f, 129.9f, 129.9f, 129.9f, 129.9f}, {132.5f, 132.5f, 132.5f, 132.5f, 132.5f, 132.5f, 132.5f, 132.5f, 135.2f, 135.2f, 135.2f, 135.2f, 135.2f, 135.2f, 135.2f, 135.2f, 137.9f, 137.9f, 137.9f, 137.9f, 137.9f, 137.9f, 137.9f, 137.9f, 140.5f, 140.5f, 140.5f, 140.5f, 140.5f, 140.5f, 140.5f, 140.5f}}; const float INNER_TIME_VLP32C[12][32] = { {0.000f, 0.000f, 2.304f, 2.304f, 4.608f, 4.608f, 6.912f, 6.912f, 9.216f, 9.216f, 11.520f, 11.520f, 13.824f, 13.824f, 16.128f, 16.128f, 18.432f, 18.432f, 20.736f, 20.736f, 23.040f, 23.040f, 25.344f, 25.344f, 27.648f, 27.648f, 29.952f, 29.952f, 32.256f, 32.256f, 34.560f, 34.560f}, {0.000f, 0.000f, 2.304f, 2.304f, 4.608f, 4.608f, 6.912f, 6.912f, 9.216f, 9.216f, 11.520f, 11.520f, 13.824f, 13.824f, 16.128f, 16.128f, 18.432f, 18.432f, 20.736f, 20.736f, 23.040f, 23.040f, 25.344f, 25.344f, 27.648f, 27.648f, 29.952f, 29.952f, 32.256f, 32.256f, 34.560f, 34.560f}, {55.296f, 55.296f, 57.600f, 57.600f, 59.904f, 59.904f, 62.208f, 62.208f, 64.512f, 64.512f, 66.816f, 66.816f, 69.120f, 69.120f, 71.424f, 71.424f, 73.728f, 73.728f, 76.032f, 76.032f, 78.336f, 78.336f, 80.640f, 80.640f, 82.944f, 82.944f, 85.248f, 85.248f, 87.552f, 87.552f, 89.856f, 89.856f}, {55.296f, 55.296f, 57.600f, 57.600f, 59.904f, 59.904f, 62.208f, 62.208f, 64.512f, 64.512f, 66.816f, 66.816f, 69.120f, 69.120f, 71.424f, 71.424f, 73.728f, 73.728f, 76.032f, 76.032f, 78.336f, 78.336f, 80.640f, 80.640f, 82.944f, 82.944f, 85.248f, 85.248f, 87.552f, 87.552f, 89.856f, 89.856f}, {110.592f, 110.592f, 112.896f, 112.896f, 115.200f, 115.200f, 117.504f, 117.504f, 119.808f, 119.808f, 122.112f, 122.112f, 124.416f, 124.416f, 126.720f, 126.720f, 129.024f, 129.024f, 131.328f, 131.328f, 133.632f, 133.632f, 135.936f, 135.936f, 138.240f, 138.240f, 140.544f, 140.544f, 142.848f, 142.848f, 145.152f, 145.152f}, {110.592f, 110.592f, 112.896f, 112.896f, 115.200f, 115.200f, 117.504f, 117.504f, 119.808f, 119.808f, 122.112f, 122.112f, 124.416f, 124.416f, 126.720f, 126.720f, 129.024f, 129.024f, 131.328f, 131.328f, 133.632f, 133.632f, 135.936f, 135.936f, 138.240f, 138.240f, 140.544f, 140.544f, 142.848f, 142.848f, 145.152f, 145.152f}, {165.888f, 165.888f, 168.192f, 168.192f, 170.496f, 170.496f, 172.800f, 172.800f, 175.104f, 175.104f, 177.408f, 177.408f, 179.712f, 179.712f, 182.016f, 182.016f, 184.320f, 184.320f, 186.624f, 186.624f, 188.928f, 188.928f, 191.232f, 191.232f, 193.536f, 193.536f, 195.840f, 195.840f, 198.144f, 198.144f, 200.448f, 200.448f}, {165.888f, 165.888f, 168.192f, 168.192f, 170.496f, 170.496f, 172.800f, 172.800f, 175.104f, 175.104f, 177.408f, 177.408f, 179.712f, 179.712f, 182.016f, 182.016f, 184.320f, 184.320f, 186.624f, 186.624f, 188.928f, 188.928f, 191.232f, 191.232f, 193.536f, 193.536f, 195.840f, 195.840f, 198.144f, 198.144f, 200.448f, 200.448f}, {221.184f, 221.184f, 223.488f, 223.488f, 225.792f, 225.792f, 228.096f, 228.096f, 230.400f, 230.400f, 232.704f, 232.704f, 235.008f, 235.008f, 237.312f, 237.312f, 239.616f, 239.616f, 241.920f, 241.920f, 244.224f, 244.224f, 246.528f, 246.528f, 248.832f, 248.832f, 251.136f, 251.136f, 253.440f, 253.440f, 255.744f, 255.744f}, {221.184f, 221.184f, 223.488f, 223.488f, 225.792f, 225.792f, 228.096f, 228.096f, 230.400f, 230.400f, 232.704f, 232.704f, 235.008f, 235.008f, 237.312f, 237.312f, 239.616f, 239.616f, 241.920f, 241.920f, 244.224f, 244.224f, 246.528f, 246.528f, 248.832f, 248.832f, 251.136f, 251.136f, 253.440f, 253.440f, 255.744f, 255.744f}, {276.480f, 276.480f, 278.784f, 278.784f, 281.088f, 281.088f, 283.392f, 283.392f, 285.696f, 285.696f, 288.000f, 288.000f, 290.304f, 290.304f, 292.608f, 292.608f, 294.912f, 294.912f, 297.216f, 297.216f, 299.520f, 299.520f, 301.824f, 301.824f, 304.128f, 304.128f, 306.432f, 306.432f, 308.736f, 308.736f, 311.040f, 311.040f}, {276.480f, 276.480f, 278.784f, 278.784f, 281.088f, 281.088f, 283.392f, 283.392f, 285.696f, 285.696f, 288.000f, 288.000f, 290.304f, 290.304f, 292.608f, 292.608f, 294.912f, 294.912f, 297.216f, 297.216f, 299.520f, 299.520f, 301.824f, 301.824f, 304.128f, 304.128f, 306.432f, 306.432f, 308.736f, 308.736f, 311.040f, 311.040f}}; } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/calibration.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /** * \file calibration.h * * \author Piyush Khandelwal (piyushk@cs.utexas.edu) * Copyright (C) 2012, Austin Robot Technology, University of Texas at Austin * * License: Modified BSD License * * $ Id: 02/14/2012 11:25:34 AM piyushk $ */ #pragma once #include <map> #include <string> namespace apollo { namespace drivers { namespace velodyne { /** \brief correction values for a single laser * * Correction values for a single laser (as provided by db.xml from velodyne) * Includes parameters for Velodyne HDL-64E S2.1 calibration. * http://velodynelidar.com/lidar/products/manual/63-HDL64E%20S2%20Manual_Rev%20D_2011_web.pdf **/ struct LaserCorrection { /** parameters in db.xml */ float rot_correction; float vert_correction; float dist_correction; float dist_correction_x; float dist_correction_y; float vert_offset_correction; float horiz_offset_correction; int max_intensity; int min_intensity; float focal_distance; float focal_slope; float focal_offset; /** cached values calculated when the calibration file is read */ float cos_rot_correction; ///< cached cosine of rot_correction float sin_rot_correction; ///< cached sine of rot_correction float cos_vert_correction; ///< cached cosine of vert_correction float sin_vert_correction; ///< cached sine of vert_correction int laser_ring; ///< ring number for this laser }; /** \brief Calibration class storing entire configuration for the Velodyne */ class Calibration { public: std::map<int, LaserCorrection> laser_corrections_; int num_lasers_; bool initialized_; public: Calibration() : initialized_(false) {} explicit Calibration(const std::string& calibration_file) { read(calibration_file); } void read(const std::string& calibration_file); void write(const std::string& calibration_file); }; } // namespace velodyne } // namespace drivers } // namespace apollo
0
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne128_parser.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/drivers/lidar/velodyne/parser/velodyne_parser.h" namespace apollo { namespace drivers { namespace velodyne { Velodyne128Parser::Velodyne128Parser(const Config& config) : VelodyneParser(config), previous_packet_stamp_(0), gps_base_usec_(0) { inner_time_ = &velodyne::INNER_TIME_128; need_two_pt_correction_ = false; } void Velodyne128Parser::GeneratePointcloud( const std::shared_ptr<VelodyneScan>& scan_msg, std::shared_ptr<PointCloud> out_msg) { // allocate a point cloud with same time and frame ID as raw data out_msg->mutable_header()->set_frame_id(scan_msg->header().frame_id()); out_msg->mutable_header()->set_timestamp_sec(cyber::Time().Now().ToSecond()); out_msg->set_height(1); // us gps_base_usec_ = scan_msg->basetime(); for (int i = 0; i < scan_msg->firing_pkts_size(); ++i) { Unpack(scan_msg->firing_pkts(i), out_msg); last_time_stamp_ = out_msg->measurement_time(); } size_t size = out_msg->point_size(); if (size == 0) { // we discard this pointcloud if empty AERROR << "All points is NAN!Please check velodyne:" << config_.model(); return; } else { const auto timestamp = out_msg->point(static_cast<int>(size) - 1).timestamp(); out_msg->set_measurement_time(static_cast<double>(timestamp) / 1e9); out_msg->mutable_header()->set_lidar_timestamp(timestamp); } out_msg->set_width(out_msg->point_size()); } uint64_t Velodyne128Parser::GetTimestamp(double base_time, float time_offset, uint16_t block_id) { (void)block_id; double t = base_time + time_offset; uint64_t timestamp = GetGpsStamp(t, &previous_packet_stamp_, &gps_base_usec_); return timestamp; } void Velodyne128Parser::Order(std::shared_ptr<PointCloud> cloud) { (void)cloud; } void Velodyne128Parser::Unpack(const VelodynePacket& pkt, std::shared_ptr<PointCloud> pc) { float azimuth_diff, azimuth_corrected_f; float last_azimuth_diff = 0.0f; uint16_t azimuth = 0; uint16_t azimuth_next = 0; uint16_t azimuth_corrected = 0; const RawPacket* raw = (const RawPacket*)pkt.data().c_str(); double basetime = raw->gps_timestamp; for (int block = 0; block < BLOCKS_PER_PACKET; block++) { // Calculate difference between current and next block's azimuth angle. if (block == 0) { azimuth = raw->blocks[block].rotation; } else { azimuth = azimuth_next; } if (block < (BLOCKS_PER_PACKET - 1)) { azimuth_next = raw->blocks[block + 1].rotation; azimuth_diff = static_cast<float>((36000 + azimuth_next - azimuth) % 36000); last_azimuth_diff = azimuth_diff; } else { azimuth_diff = last_azimuth_diff; } /*condition added to avoid calculating points which are not in the interesting defined area (min_angle < area < max_angle)*/ for (int j = 0, k = 0; j < SCANS_PER_BLOCK; j++, k += RAW_SCAN_SIZE) { uint8_t group = static_cast<uint8_t>(block % 4); uint8_t chan_id = static_cast<uint8_t>(j + group * 32); uint8_t firing_order = chan_id / 8; firing_order = 0; LaserCorrection& corrections = calibration_.laser_corrections_[chan_id]; // distance extraction // union two_bytes tmp; union RawDistance raw_distance; raw_distance.bytes[0] = raw->blocks[block].data[k]; raw_distance.bytes[1] = raw->blocks[block].data[k + 1]; float real_distance = raw_distance.raw_distance * VSL128_DISTANCE_RESOLUTION; float distance = real_distance + corrections.dist_correction; uint64_t timestamp = static_cast<uint64_t>(GetTimestamp( basetime, (*inner_time_)[block][j], static_cast<uint16_t>(block))); if (!is_scan_valid(azimuth, distance)) { // todo organized if (config_.organized()) { apollo::drivers::PointXYZIT* point_new = pc->add_point(); point_new->set_x(nan); point_new->set_y(nan); point_new->set_z(nan); point_new->set_timestamp(timestamp); point_new->set_intensity(0); } continue; } // if (pointInRange(distance)) { int intensity = static_cast<int>(raw->blocks[block].data[k + 2]); /** correct for the laser rotation as a function of timing during the * firings **/ azimuth_corrected_f = azimuth + (azimuth_diff * (firing_order * CHANNEL_TDURATION) / SEQ_TDURATION); azimuth_corrected = (static_cast<uint16_t>(round(azimuth_corrected_f))) % 36000; // add new point PointXYZIT* point_new = pc->add_point(); // compute time , time offset is zero point_new->set_timestamp(timestamp); ComputeCoords(real_distance, corrections, azimuth_corrected, point_new); intensity = IntensityCompensate(corrections, raw_distance.raw_distance, intensity); point_new->set_intensity(intensity); } // } } } int Velodyne128Parser::IntensityCompensate(const LaserCorrection& corrections, const uint16_t raw_distance, int intensity) { float focal_offset = 256 * (1 - corrections.focal_distance / 13100) * (1 - corrections.focal_distance / 13100); float focal_slope = corrections.focal_slope; intensity += static_cast<int>( focal_slope * static_cast<float>(std::abs( focal_offset - 256.0f * (1.0f - static_cast<float>(raw_distance) / 65535.0f) * (1.0f - static_cast<float>(raw_distance) / 65535.0f)))); if (intensity < corrections.min_intensity) { intensity = corrections.min_intensity; } if (intensity > corrections.max_intensity) { intensity = corrections.max_intensity; } return intensity; } } // namespace velodyne } // namespace drivers } // namespace apollo
0