18#include "modules/perception/radar4d_detection/proto/preprocessor_config.pb.h"
29const float RadarPreprocessor::kPointInfThreshold = 1e3;
30int RadarPreprocessor::current_idx_ = 0;
31std::unordered_map<int, int> RadarPreprocessor::local2global_;
35 std::string config_file =
46 const std::shared_ptr<apollo::drivers::OculiiPointCloud const>& message,
49 if (frame ==
nullptr) {
52 if (frame->
cloud ==
nullptr) {
53 frame->
cloud = base::RadarPointFCloudPool::Instance().Get();
56 frame->
world_cloud = base::RadarPointDCloudPool::Instance().Get();
59 frame->
cloud->set_timestamp(message->measurement_time());
60 if (message->point_size() > 0) {
61 frame->
cloud->reserve(message->point_size());
63 for (
int i = 0; i < message->point_size(); ++i) {
67 message->raw_pointclouds(i);
69 if (filter_naninf_points_) {
70 if (std::isnan(pt.
x()) || std::isnan(pt.
y()) || std::isnan(pt.
z())) {
73 if (fabs(pt.
x()) > kPointInfThreshold ||
74 fabs(pt.
y()) > kPointInfThreshold ||
75 fabs(pt.
z()) > kPointInfThreshold) {
80 if (filter_high_z_points_ && pt.
z() > z_threshold_) {
87 point.
rcs =
static_cast<float>(pt.
intensity() + rcs_offset_);
91 point.
comp_vel = CalCompensatedVelocity(point, options);
92 frame->
cloud->push_back(point);
100bool RadarPreprocessor::TransformCloud(
103 if (local_cloud ==
nullptr) {
106 world_cloud->clear();
107 world_cloud->reserve(local_cloud->size());
108 for (
size_t i = 0; i < local_cloud->size(); ++i) {
109 auto& pt = local_cloud->at(i);
110 Eigen::Vector3d trans_point(pt.x, pt.y, pt.z);
111 trans_point = pose * trans_point;
113 world_point.x = trans_point(0);
114 world_point.y = trans_point(1);
115 world_point.z = trans_point(2);
116 world_point.rcs = pt.rcs;
117 world_point.velocity = pt.velocity;
118 world_point.comp_vel = pt.comp_vel;
119 world_cloud->push_back(world_point);
124float RadarPreprocessor::CalCompensatedVelocity(
126 const PreprocessorOptions& options) {
128 const Eigen::Matrix4d& radar2world = *(options.radar2world_pose);
129 Eigen::Matrix3d radar2world_rotate = radar2world.block<3, 3>(0, 0);
130 Eigen::Vector3d radar_speed =
131 static_cast<Eigen::Matrix<double, 3, 1, 0, 3, 1>
>(
132 radar2world_rotate.inverse() *
133 options.car_linear_speed.cast<
double>());
136 Eigen::Vector3f local_loc(point.x, point.y, point.z);
137 float azimuth = std::atan2(local_loc[1], local_loc[0]);
138 float xy_temp = std::sqrt(local_loc[0] * local_loc[0]
139 + local_loc[1] * local_loc[1]);
140 float elevation = std::atan2(local_loc[2], xy_temp);
144 float compensated_v = point.velocity +
145 radar_speed[0] * std::cos(azimuth) +
146 radar_speed[1] * std::sin(azimuth) +
147 radar_speed[2] * std::sin(elevation);
148 return compensated_v;
bool Init(const PreprocessorInitOptions &options) override
Init RadarPreprocessor config
bool Preprocess(const std::shared_ptr< apollo::drivers::OculiiPointCloud const > &message, const PreprocessorOptions &options, RadarFrame *frame) override
Process radar point cloud.
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
std::shared_ptr< RadarPointFCloud > RadarPointFCloudPtr
std::shared_ptr< RadarPointDCloud > RadarPointDCloudPtr
RadarPoint< double > RadarPointD
RadarPoint< float > RadarPointF
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
#define PERCEPTION_REGISTER_PREPROCESSOR(name)
optional double rcs_offset
std::shared_ptr< base::AttributeRadarPointCloud< base::RadarPointD > > world_cloud
Eigen::Affine3d radar2world_pose
std::shared_ptr< base::AttributeRadarPointCloud< base::RadarPointF > > cloud