Skip to content

Commit 7faab8f

Browse files
committed
Fix the imu_info frame_id bug and initialize the quaternion's w value to 1.0
1 parent 9888fd3 commit 7faab8f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

orbbec_camera/src/ob_camera_node.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,26 +2304,34 @@ void OBCameraNode::onNewIMUFrameSyncOutputCallback(const std::shared_ptr<ob::Fra
23042304
auto imu_msg = sensor_msgs::msg::Imu();
23052305
setDefaultIMUMessage(imu_msg);
23062306

2307-
imu_msg.header.frame_id = imu_optical_frame_id_;
2307+
imu_msg.header.frame_id = optical_frame_id_[GYRO];
23082308
auto frame_timestamp = getFrameTimestampUs(accelframe);
23092309
auto timestamp = fromUsToROSTime(frame_timestamp);
23102310
imu_msg.header.stamp = timestamp;
2311-
auto gyro_frame = gryoframe->as<ob::GyroFrame>();
2311+
23122312
auto gyro_info = createIMUInfo(GYRO);
23132313
gyro_info.header = imu_msg.header;
2314-
gyro_info.header.frame_id = imu_optical_frame_id_;
23152314
imu_info_publishers_[GYRO]->publish(gyro_info);
2315+
2316+
auto accel_info = createIMUInfo(ACCEL);
2317+
imu_msg.header.frame_id = optical_frame_id_[ACCEL];
2318+
accel_info.header = imu_msg.header;
2319+
imu_info_publishers_[ACCEL]->publish(accel_info);
2320+
2321+
imu_msg.header.frame_id = imu_optical_frame_id_;
2322+
2323+
auto gyro_frame = gryoframe->as<ob::GyroFrame>();
23162324
auto gyroData = gyro_frame->getValue();
23172325
imu_msg.angular_velocity.x = gyroData.x - gyro_info.bias[0];
23182326
imu_msg.angular_velocity.y = gyroData.y - gyro_info.bias[1];
23192327
imu_msg.angular_velocity.z = gyroData.z - gyro_info.bias[2];
2328+
23202329
auto accel_frame = accelframe->as<ob::AccelFrame>();
23212330
auto accelData = accel_frame->getValue();
2322-
auto accel_info = createIMUInfo(ACCEL);
23232331
imu_msg.linear_acceleration.x = accelData.x - accel_info.bias[0];
23242332
imu_msg.linear_acceleration.y = accelData.y - accel_info.bias[1];
23252333
imu_msg.linear_acceleration.z = accelData.z - accel_info.bias[2];
2326-
imu_info_publishers_[ACCEL]->publish(accel_info);
2334+
23272335
imu_gyro_accel_publisher_->publish(imu_msg);
23282336
}
23292337

@@ -2345,14 +2353,15 @@ void OBCameraNode::onNewIMUFrameCallback(const std::shared_ptr<ob::Frame> &frame
23452353
}
23462354
auto imu_msg = sensor_msgs::msg::Imu();
23472355
setDefaultIMUMessage(imu_msg);
2356+
23482357
imu_msg.header.frame_id = optical_frame_id_[stream_index];
23492358
auto timestamp = fromUsToROSTime(frame->getTimeStampUs());
2350-
23512359
imu_msg.header.stamp = timestamp;
2360+
23522361
auto imu_info = createIMUInfo(stream_index);
23532362
imu_info.header = imu_msg.header;
2354-
imu_info.header.frame_id = imu_optical_frame_id_;
23552363
imu_info_publishers_[stream_index]->publish(imu_info);
2364+
23562365
if (frame->getType() == OB_FRAME_GYRO) {
23572366
auto gyro_frame = frame->as<ob::GyroFrame>();
23582367
auto data = gyro_frame->getValue();
@@ -2377,7 +2386,7 @@ void OBCameraNode::setDefaultIMUMessage(sensor_msgs::msg::Imu &imu_msg) {
23772386
imu_msg.orientation.x = 0.0;
23782387
imu_msg.orientation.y = 0.0;
23792388
imu_msg.orientation.z = 0.0;
2380-
imu_msg.orientation.w = 0.0;
2389+
imu_msg.orientation.w = 1.0;
23812390

23822391
imu_msg.orientation_covariance = {-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
23832392
imu_msg.linear_acceleration_covariance = {
@@ -2761,7 +2770,7 @@ orbbec_camera_msgs::msg::IMUInfo OBCameraNode::createIMUInfo(
27612770
orbbec_camera_msgs::msg::IMUInfo imu_info;
27622771
imu_info.header.frame_id = optical_frame_id_[stream_index];
27632772
imu_info.header.stamp = node_->now();
2764-
auto imu_profile = stream_profile_[stream_index];
2773+
27652774
if (stream_index == GYRO) {
27662775
auto gyro_profile = stream_profile_[stream_index]->as<ob::GyroStreamProfile>();
27672776
auto gyro_intrinsics = gyro_profile->getIntrinsic();

0 commit comments

Comments
 (0)