-
Notifications
You must be signed in to change notification settings - Fork 444
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
Reading and Writing Scans to and fro from An OSF or PCAP file (for non-ROS users) #611
Comments
Hi hirenpatel1207 You can try doing something like this for recording in pcap: #include <iostream>
#include <fstream>
#include "ouster/client.h"
#include "ouster/os_pcap.h"
void WriteToFile(const std::string& filename, const std::string& data) {
std::ofstream file(filename);
file << data;
file.close();
}
int main() {
const std::string sensor_hostname = "<sensor hostname>";
const std::string pcap_file_name = "my_pcap_file.pcap";
const std::string metadata_file_name = "my_pcap_file.json";
auto client_handle = ouster::sensor::init_client(sensor_hostname, 7502, 7503);
if (!client_handle) {
std::cerr << "Failed to connect" << std::endl;
}
std::cout << "Gathering metadata..." << std::endl;
auto metadata = ouster::sensor::get_metadata(*client_handle, 10);
std::cout << " done." << std::endl;
ouster::sensor::sensor_info sensor_info(metadata);
ouster::sensor::packet_format packet_format = ouster::sensor::get_format(sensor_info);
auto lidar_packet = ouster::sensor::LidarPacket(packet_format.lidar_packet_size);
auto imu_packet = ouster::sensor::ImuPacket(packet_format.imu_packet_size);
std::cout << "Recording ... " << std::endl;
WriteToFile(metadata_file_name, sensor_info.to_json_string());
auto record_handle = ouster::sensor_utils::record_initialize(pcap_file_name, 1500);
while(true) {
ouster::sensor::client_state st = ouster::sensor::poll_client(*client_handle);
if (st & ouster::sensor::LIDAR_DATA) {
if (!ouster::sensor::read_lidar_packet(*client_handle, lidar_packet)) {
std::cerr << "failed to read lidar packet" << std::endl;
break;
}
ouster::sensor_utils::record_packet(
*record_handle,
"192.168.0.1",
"192.168.0.1",
7502, 7502,
lidar_packet.buf.data(), lidar_packet.buf.size(),
lidar_packet.host_timestamp);
}
if (st & ouster::sensor::IMU_DATA) {
if (!ouster::sensor::read_imu_packet(*client_handle, imu_packet)) {
std::cerr << "failed to read imu packet" << std::endl;
break;
}
ouster::sensor_utils::record_packet(
*record_handle,
"192.168.0.1",
"192.168.0.1",
7503, 7503,
imu_packet.buf.data(), imu_packet.buf.size(),
imu_packet.host_timestamp);
}
}
ouster::sensor_utils::record_uninitialize(*record_handle);
}
And then, for reading: #include "ouster/os_pcap.h"
#include "ouster/lidar_scan.h"
int main() {
const std::string pcap_file = "my_pcap_file.pcap";
const std::string json_file = "my_pcap_file.json";
auto metadata = ouster::sensor::metadata_from_json(json_file);
ouster::sensor::Packet packet(packet_format.lidar_packet_size);
ouster::sensor_utils::packet_info packet_info;
auto width = metadata.format.columns_per_frame;
auto height = metadata.format.pixels_per_column;
ouster::LidarScan lidar_scan = ouster::LidarScan(width, height, metadata.format.udp_profile_lidar);
ouster::ScanBatcher scan_batcher(metadata.format.columns_per_frame, packet_format);
auto pcap_handle = ouster::sensor_utils::replay_initialize(pcap_file);
while (ouster::sensor_utils::next_packet_info(*pcap_handle, packet_info)) {
auto packet_size = ouster::sensor_utils::read_packet(*pcap_handle, packet.buf.data(), packet.buf.size());
if (packet_size == packet_format.lidar_packet_size) {
const auto &lidar_packet = static_cast<ouster::sensor::LidarPacket &>(packet);
if (scan_batcher(lidar_packet, lidar_scan)) {
// do something with lidar scan here
}
}
}
}
I hope that helps |
Thanks @diego-guridi for the example, I was able to record some PCAP files. |
The return value for poll_client is a bitmask rather than an enum, so 6 would mean there is both IMU and Lidar data available (4 + 2). |
Hi, The above code samples work well. |
Hi @hirenpatel1207, you can check out the representations_example.cpp that shows how you can get a cartesian point cloud from a LidarScan and how to work with "fields" from the LidarScan to get data like reflectivity. With that you should be able to create PCL type objects or directly write PCD files. I hope this helps! |
@hirenpatel1207 checkout the example in the ouster-ros-extras repo https://github.com/ouster-lidar/ouster-ros-extras/blob/ros2/scripts/ros2_range_2_points_xyz.py this isn't directly what you are asking but you can easily combine the python examples to obtain the range field from LidarScan then apply that geenrates a PointCloud object from the ouster-ros-extras |
Here is a complete example:
Something around these lines! Hope this helps! |
Thank you all for pointing to the right sources. In the ouster-ros, the timestamp field is nano-secs since the scan start.
|
this is the absolute time, you need to do another thing to note is that you don't want to use |
The documentation has no examples on how to store lidar scans in PCAP file. Also it has no documentation on how to write to a OSFfile.
Describe the solution you'd like
For non-ROS applications an example on how to efficiently write lidar data to storage (in PCAP format) and then read it .
Describe alternatives you've considered
The application is Windows only so using ROS driver is not feasible. Also the Ouster Studio has option to store PCAP files, but that is not open source.
Maybe a example can be formed using that project.
Targeted Platform (please complete the following information only if applicable, otherwise dot N/A):
The text was updated successfully, but these errors were encountered: