-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Create iterator for custom height field in pointcloud. #5586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
5860a27
7e6ccc9
ca49b05
11f04c7
869b5a9
1cdbc05
b2fbb06
5636fc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -106,8 +106,27 @@ bool PointCloud::getData( | |||||
sensor_msgs::PointCloud2ConstIterator<float> iter_y(*data_, "y"); | ||||||
sensor_msgs::PointCloud2ConstIterator<float> iter_z(*data_, "z"); | ||||||
|
||||||
bool height_present{false}; | ||||||
for(const auto & field : data_->fields) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if(field.name == "height") { | ||||||
greganderson-vermeer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
height_present = true; | ||||||
} | ||||||
} | ||||||
|
||||||
// Reference height field | ||||||
std::string height_field{""}; | ||||||
if(use_global_height_ && height_present) { | ||||||
height_field = "height"; | ||||||
} else if(use_global_height_) { | ||||||
greganderson-vermeer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
throw std::runtime_error{"'use_global_height' parameter true but height field not in cloud"}; | ||||||
greganderson-vermeer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
} else { | ||||||
// If height field not present fill iterator with z field | ||||||
height_field = "z"; | ||||||
} | ||||||
sensor_msgs::PointCloud2ConstIterator<float> iter_height(*data_, height_field); | ||||||
|
||||||
// Refill data array with PointCloud points in base frame | ||||||
for (; iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z) { | ||||||
for (; iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z, ++iter_height) { | ||||||
// Transform point coordinates from source frame -> to base frame | ||||||
tf2::Vector3 p_v3_s(*iter_x, *iter_y, *iter_z); | ||||||
|
||||||
|
@@ -120,8 +139,14 @@ bool PointCloud::getData( | |||||
tf2::Vector3 p_v3_b = tf_transform * p_v3_s; | ||||||
|
||||||
// Refill data array | ||||||
if (p_v3_b.z() >= min_height_ && p_v3_b.z() <= max_height_) { | ||||||
data.push_back({p_v3_b.x(), p_v3_b.y()}); | ||||||
if(use_global_height_) { | ||||||
greganderson-vermeer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
if (*iter_height >= min_height_ && *iter_height <= max_height_) { | ||||||
data.push_back({p_v3_b.x(), p_v3_b.y()}); | ||||||
} | ||||||
} else { | ||||||
if (*iter_z >= min_height_ && *iter_z <= max_height_) { | ||||||
data.push_back({p_v3_b.x(), p_v3_b.y()}); | ||||||
} | ||||||
|
||||||
} | ||||||
} | ||||||
return true; | ||||||
|
@@ -148,6 +173,9 @@ void PointCloud::getParameters(std::string & source_topic) | |||||
nav2::declare_parameter_if_not_declared( | ||||||
node, source_name_ + ".transport_type", rclcpp::ParameterValue(std::string("raw"))); | ||||||
transport_type_ = node->get_parameter(source_name_ + ".transport_type").as_string(); | ||||||
nav2::declare_parameter_if_not_declared( | ||||||
node, source_name_ + ".use_global_height", rclcpp::ParameterValue(false)); | ||||||
use_global_height_ = node->get_parameter(source_name_ + ".use_global_height").as_bool(); | ||||||
} | ||||||
|
||||||
void PointCloud::dataCallback(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) | ||||||
|
@@ -178,6 +206,8 @@ PointCloud::dynamicParametersCallback( | |||||
} else if (param_type == rcl_interfaces::msg::ParameterType::PARAMETER_BOOL) { | ||||||
if (param_name == source_name_ + "." + "enabled") { | ||||||
enabled_ = parameter.as_bool(); | ||||||
} else if (param_name == source_name_ + "." + "use_global_height") { | ||||||
use_global_height_ = parameter.as_bool(); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.