28
28
#include < pcl/sample_consensus/model_types.h>
29
29
#include < pcl/segmentation/sac_segmentation.h>
30
30
31
+ #include < cmath>
32
+
31
33
namespace yabloc ::ground_server
32
34
{
33
35
GroundServer::GroundServer (const rclcpp::NodeOptions & options)
34
36
: Node(" ground_server" , options),
35
37
force_zero_tilt_ (declare_parameter<bool >(" force_zero_tilt" )),
36
- R( declare_parameter<int >(" R" )),
37
- K( declare_parameter<int >(" K" ))
38
+ R_( static_cast < float >( declare_parameter<int >(" R" ) )),
39
+ K_( static_cast < int >( declare_parameter<int >(" K" ) ))
38
40
{
39
41
using std::placeholders::_1;
40
42
using std::placeholders::_2;
@@ -147,8 +149,8 @@ float GroundServer::estimate_height_simply(const geometry_msgs::msg::Point & poi
147
149
{
148
150
// NOTE: Sometimes it might give not-accurate height
149
151
constexpr float sq_radius = 3.0 * 3.0 ;
150
- const float x = point.x ;
151
- const float y = point.y ;
152
+ const auto x = static_cast < float >( point.x ) ;
153
+ const auto y = static_cast < float >( point.y ) ;
152
154
153
155
float height = std::numeric_limits<float >::infinity ();
154
156
for (const auto & p : cloud_->points ) {
@@ -186,12 +188,12 @@ std::vector<int> GroundServer::estimate_inliers_by_ransac(const std::vector<int>
186
188
GroundServer::GroundPlane GroundServer::estimate_ground (const Point & point)
187
189
{
188
190
// Because height_filter_ is always initialized, getValue does not return nullopt
189
- const float predicted_z = height_filter_.getValue ().value ();
190
- const pcl::PointXYZ xyz (point.x , point.y , predicted_z);
191
+ const float predicted_z = static_cast < float >( height_filter_.getValue ().value () );
192
+ const pcl::PointXYZ xyz (static_cast < float >( point.x ), static_cast < float >( point.y ) , predicted_z);
191
193
192
194
std::vector<int > raw_indices;
193
195
std::vector<float > distances;
194
- kdtree_->nearestKSearch (xyz, K , raw_indices, distances);
196
+ kdtree_->nearestKSearch (xyz, K_ , raw_indices, distances);
195
197
196
198
std::vector<int > indices = estimate_inliers_by_ransac (raw_indices);
197
199
@@ -206,7 +208,7 @@ GroundServer::GroundPlane GroundServer::estimate_ground(const Point & point)
206
208
207
209
// NOTE: I forgot why I don't use coefficients computed by SACSegmentation
208
210
Eigen::Vector4f plane_parameter;
209
- float curvature;
211
+ float curvature = NAN ;
210
212
pcl::solvePlaneParameters (covariance, centroid, plane_parameter, curvature);
211
213
Eigen::Vector3f normal = plane_parameter.topRows (3 ).normalized ();
212
214
@@ -229,15 +231,16 @@ GroundServer::GroundPlane GroundServer::estimate_ground(const Point & point)
229
231
const Eigen::Vector3f filt_normal = normal_filter_.update (normal );
230
232
231
233
GroundPlane plane;
232
- plane.xyz = Eigen::Vector3f (point.x , point.y , predicted_z);
234
+ plane.xyz =
235
+ Eigen::Vector3f (static_cast <float >(point.x ), static_cast <float >(point.y ), predicted_z);
233
236
plane.normal = filt_normal;
234
237
235
238
// Compute z value by intersection of estimated plane and orthogonal line
236
239
{
237
240
Eigen::Vector3f center = centroid.topRows (3 );
238
241
float inner = center.dot (plane.normal );
239
- float px_nx = point.x * plane.normal .x ();
240
- float py_ny = point.y * plane.normal .y ();
242
+ float px_nx = static_cast < float >( point.x ) * plane.normal .x ();
243
+ float py_ny = static_cast < float >( point.y ) * plane.normal .y ();
241
244
plane.xyz .z () = (inner - px_nx - py_ny) / plane.normal .z ();
242
245
}
243
246
0 commit comments