-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support occupancy grid cells #3032
Changes from all commits
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 |
---|---|---|
|
@@ -568,6 +568,10 @@ void BaseRealSenseNode::frame_callback(rs2::frame frame) | |
{ | ||
publishPointCloud(f.as<rs2::points>(), t, frameset); | ||
} | ||
else if(stream_type == RS2_STREAM_OCCUPANCY) | ||
{ | ||
publishOccupancyFrame(f, t); | ||
} | ||
else | ||
{ | ||
if (stream_type == RS2_STREAM_DEPTH) | ||
|
@@ -610,14 +614,21 @@ void BaseRealSenseNode::frame_callback(rs2::frame frame) | |
rs2_stream_to_string(stream_type), stream_index, frame.get_frame_number(), frame_time, t.nanoseconds()); | ||
|
||
stream_index_pair sip{stream_type,stream_index}; | ||
if (frame.is<rs2::depth_frame>()) | ||
if(stream_type == RS2_STREAM_OCCUPANCY) | ||
{ | ||
if (_clipping_distance > 0) | ||
publishOccupancyFrame(frame, t); | ||
} | ||
else | ||
{ | ||
if (frame.is<rs2::depth_frame>()) | ||
{ | ||
clip_depth(frame, _clipping_distance); | ||
if (_clipping_distance > 0) | ||
{ | ||
clip_depth(frame, _clipping_distance); | ||
} | ||
} | ||
publishFrame(frame, t, sip, _images, _info_publishers, _image_publishers); | ||
} | ||
publishFrame(frame, t, sip, _images, _info_publishers, _image_publishers); | ||
} | ||
else if (frame.is<rs2::labeled_points>()) | ||
{ | ||
|
@@ -828,7 +839,51 @@ bool BaseRealSenseNode::shouldPublishCameraInfo(const stream_index_pair& sip) | |
return (stream != RS2_STREAM_SAFETY && stream != RS2_STREAM_OCCUPANCY && stream != RS2_STREAM_LABELED_POINT_CLOUD); | ||
} | ||
|
||
void BaseRealSenseNode::publishLabeledPointCloud(rs2::labeled_points lpc, const rclcpp::Time& t){ | ||
void BaseRealSenseNode::publishOccupancyFrame(rs2::frame f, const rclcpp::Time& t) | ||
{ | ||
if(!_occupancy_publisher || 0 == _occupancy_publisher->get_subscription_count()) | ||
return; | ||
|
||
ROS_DEBUG("Publishing Occupancy GridCells Frame"); | ||
|
||
// get frame bytes and frame metadata relevant info | ||
auto frame_as_uint8_arr = (uint8_t*)f.get_data(); | ||
auto cols = static_cast<int>(f.get_frame_metadata(RS2_FRAME_METADATA_OCCUPANCY_GRID_COLUMNS)); // grid cells width | ||
auto rows = static_cast<int>(f.get_frame_metadata(RS2_FRAME_METADATA_OCCUPANCY_GRID_ROWS)); // grid cells height | ||
auto cell_size = static_cast<float>(f.get_frame_metadata(RS2_FRAME_METADATA_OCCUPANCY_CELL_SIZE) / 100.0f); // convert to meters | ||
|
||
// create GridCells msg and start filling it | ||
nav_msgs::msg::GridCells msg; | ||
msg.header.stamp = t; | ||
msg.header.frame_id = FRAME_ID(OCCUPANCY); | ||
msg.cell_width = cell_size; | ||
msg.cell_height = cell_size; | ||
|
||
for (auto i = 0; i < cols * rows; ++i) | ||
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. Does this means rows and columns represent the cells and not the bytes? 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. rows = grid cell height, cols = grid cell width |
||
{ | ||
// AICV algo is packing each 8 cells into one byte. Each byte include 8 bits <--> 8 cells | ||
// The rightest bit (LSB) inside the packed byte from AICV algo represnts the closest cell we want to work with in the grid. | ||
// e.g. Original Occupancy Cells: 0 0 1 1 0 0 1 0 ---> AICV packing algo ---> 01001100 (not the opposite order) | ||
// In this if we check if current cell is occupied. | ||
// Note that we start working from the most left bit, aka, the farest point of the grid. | ||
if ((frame_as_uint8_arr[i / 8U] & (1U << i % 8)) != 0) | ||
{ | ||
// Find x,y,z positions of current index | ||
// Remember, in ROS CS: (X: Forward, Y: Left, Z: Up) | ||
geometry_msgs::msg::Point p3d; | ||
uint32_t row = (i / cols); | ||
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. raw is calculates from cols? |
||
uint32_t col = (i % cols); | ||
p3d.x = (cell_size * static_cast<float>(rows)) - cell_size * (static_cast<float>(row) + 0.5f); | ||
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. I would expect x axis will use columns and not rows, can you explain this line? 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. |
||
p3d.y = (cell_size * static_cast<float>(cols)) / 2 - cell_size * (static_cast<float>(col) + 0.5f); | ||
p3d.z = 0; | ||
msg.cells.push_back(p3d); | ||
} | ||
} | ||
_occupancy_publisher->publish(msg); | ||
} | ||
|
||
void BaseRealSenseNode::publishLabeledPointCloud(rs2::labeled_points lpc, const rclcpp::Time& t) | ||
{ | ||
if(!_labeled_pointcloud_publisher || 0 == _labeled_pointcloud_publisher->get_subscription_count()) | ||
return; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamerKhshiboun, just thinking out loud for future enhancement. Maybe it makes sense to parallelize this operation by using SSSE3 or GPU acceleration. your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it worth checking if we can accelerate this.
If so, we can do this in a separated task.
Thanks for the advice !