33 const double standard_g = 9.80665;
35 const uint8_t* buf = p.buf.data();
42 m.header.frame_id = frame;
49 m.linear_acceleration.x =
imu_la_x(buf) * standard_g;
50 m.linear_acceleration.y =
imu_la_y(buf) * standard_g;
51 m.linear_acceleration.z =
imu_la_z(buf) * standard_g;
53 m.angular_velocity.x =
imu_av_x(buf) * M_PI / 180.0;
54 m.angular_velocity.y =
imu_av_y(buf) * M_PI / 180.0;
55 m.angular_velocity.z =
imu_av_z(buf) * M_PI / 180.0;
57 for (
int i = 0; i < 9; i++) {
58 m.orientation_covariance[i] = -1;
59 m.angular_velocity_covariance[i] = 0;
60 m.linear_acceleration_covariance[i] = 0;
62 for (
int i = 0; i < 9; i += 4) {
63 m.linear_acceleration_covariance[i] = 0.01;
64 m.angular_velocity_covariance[i] = 6e-4;
71 const std::string& frame) {
72 sensor_msgs::PointCloud2 msg;
78 if (_pointcloud_mode ==
"XYZ") {
82 }
else if (_pointcloud_mode ==
"XYZI") {
86 }
else if (_pointcloud_mode ==
"XYZIR") {
90 }
else if (_pointcloud_mode ==
"XYZIF") {
94 }
else if (_pointcloud_mode ==
"XYZIRF") {
98 }
else if (_pointcloud_mode ==
"XYZIFN") {
102 }
else if (_pointcloud_mode ==
"XYZIRFN") {
110 msg.header.frame_id = frame;
121 auto tte = trig_table[ind];
122 const uint8_t* px_buf =
nth_px(ind, col_buf);
123 float r =
px_range(px_buf) / 1000.0;
124 float h_angle = tte.beam_azimuth_angles + h_angle_0;
130 point.x = -r * tte.cos_beam_altitude_angles * cosf(h_angle);
131 point.y = r * tte.cos_beam_altitude_angles * sinf(h_angle);
132 point.z = r * tte.sin_beam_altitude_angles;
139 const uint8_t* buf = pm.buf.data();
140 for (
int icol = 0; icol < columns_per_buffer; icol++) {
141 const uint8_t* col_buf =
nth_col(icol, buf);
142 float ts = (
col_timestamp(col_buf) - scan_start_ts.count()) /
143 (
float)scan_duration.count();
145 for (
int ipx = 0; ipx < pixels_per_column; ipx++) {
154 const std::function<
void(
const PacketMsg& pm)>& lidar_handler,
155 const std::function<
void(
const PacketMsg& pm)>& imu_handler) {
163 ROS_ERROR(
"spin: poll_client returned error");
168 lidar_handler(lidar_packet);
172 imu_handler(imu_packet);
179 return ns((ts.count() / scan_dur.count()) * scan_dur.count());
183 ns scan_dur,
const std::function<
void(
ns,
const CloudOS1&)>& f) {
184 auto cloud = std::make_shared<OS1::CloudOS1>();
185 auto scan_ts =
ns(-1L);
187 return [=](
const PacketMsg& pm)
mutable {
189 if (scan_ts.count() == -1L)
194 auto batch_dur = packet_ts - scan_ts;
195 if (batch_dur >= scan_dur || batch_dur <
ns(0)) {
209 _pointcloud_mode = mode_xyzir;
216 for (
auto p : in.points) {
220 out.points.push_back(q);
228 for (
auto p : in.points) {
232 q.intensity = p.intensity;
233 out.points.push_back(q);
244 for (
auto p : in.points) {
248 q.
intensity = ((float)p.intensity/65535.0)*255.0;
249 q.
ring = pixels_per_column - p.ring;
250 out.points.push_back(q);
261 for (
auto p : in.points) {
267 out.points.push_back(q);
278 for (
auto p : in.points) {
283 q.
ring = pixels_per_column - p.ring;
285 out.points.push_back(q);
296 for (
auto p : in.points) {
303 out.points.push_back(q);
314 for (
auto p : in.points) {
319 q.
ring = pixels_per_column - p.ring;
322 out.points.push_back(q);
pcl::PointCloud< PointXYZIF > CloudOS1XYZIF
float imu_la_x(const uint8_t *imu_buf)
float imu_av_y(const uint8_t *imu_buf)
static ns nearest_scan_dur(ns scan_dur, ns ts)
bool read_imu_packet(const ouster::OS1::client &cli, PacketMsg &pm)
float col_h_angle(const uint8_t *col_buf)
const size_t imu_packet_bytes
pcl::PointCloud< PointXYZIRFN > CloudOS1XYZIRFN
uint16_t px_noise_photons(const uint8_t *px_buf)
uint64_t imu_gyro_ts(const uint8_t *imu_buf)
pcl::PointCloud< PointOS1 > CloudOS1
void convert2XYZIRF(const CloudOS1 &in, CloudOS1XYZIRF &out)
void convert2XYZIFN(const CloudOS1 &in, CloudOS1XYZIFN &out)
void convert2XYZ(const CloudOS1 &in, CloudOS1XYZ &out)
uint64_t col_timestamp(const uint8_t *col_buf)
void set_point_mode(std::string mode_xyzir)
float imu_la_y(const uint8_t *imu_buf)
ouster_driver::PacketMsg PacketMsg
pcl::PointCloud< pcl::PointXYZI > CloudOS1XYZI
void convert2XYZIR(const CloudOS1 &in, CloudOS1XYZIR &out)
ns timestamp_of_imu_packet(const PacketMsg &pm)
const uint8_t * nth_col(int n, const uint8_t *udp_buf)
ns timestamp_of_lidar_packet(const PacketMsg &pm)
void spin(const ouster::OS1::client &cli, const std::function< void(const PacketMsg &pm)> &lidar_handler, const std::function< void(const PacketMsg &pm)> &imu_handler)
uint16_t px_reflectivity(const uint8_t *px_buf)
std::function< void(const PacketMsg &)> batch_packets(ns scan_dur, const std::function< void(ns, const CloudOS1 &)> &f)
std::chrono::nanoseconds ns
pcl::PointCloud< PointXYZIR > CloudOS1XYZIR
float imu_av_x(const uint8_t *imu_buf)
void convert2XYZIF(const CloudOS1 &in, CloudOS1XYZIF &out)
const size_t lidar_packet_bytes
float intensity
laser intensity reading
void convert2XYZI(const CloudOS1 &in, CloudOS1XYZI &out)
static std::string _pointcloud_mode
const uint8_t * nth_px(int n, const uint8_t *col_buf)
sensor_msgs::Imu packet_to_imu_msg(const PacketMsg &pm, const std::string &frame="os1_imu")
client_state poll_client(const client &cli)
bool read_lidar_packet(const ouster::OS1::client &cli, PacketMsg &pm)
pcl::PointCloud< pcl::PointXYZ > CloudOS1XYZ
uint16_t ring
laser ring number
pcl::PointCloud< PointXYZIFN > CloudOS1XYZIFN
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
float imu_la_z(const uint8_t *imu_buf)
void add_packet_to_cloud(ns scan_start_ts, ns scan_duration, const PacketMsg &pm, CloudOS1 &cloud)
uint32_t px_range(const uint8_t *px_buf)
ROSCPP_DECL void spinOnce()
void convert2XYZIRFN(const CloudOS1 &in, CloudOS1XYZIRFN &out)
float imu_av_z(const uint8_t *imu_buf)
pcl::PointCloud< PointXYZIRF > CloudOS1XYZIRF
sensor_msgs::PointCloud2 cloud_to_cloud_msg(const CloudOS1 &cloud, ns timestamp, const std::string &frame="os1")
uint16_t px_signal_photons(const uint8_t *px_buf)
static PointOS1 nth_point(int ind, const uint8_t *col_buf)