Skip to content

Commit 3ff9684

Browse files
committed
fix(ros2): keep vehicle prefix on camera optical frames
Remove the double-assign that stripped vehicle_name from static optical TF child frames, and align CameraInfo / image header frame_ids with the namespaced TF tree for multi-vehicle setups.
1 parent d109f0d commit 3ff9684

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

ros2/src/airsim_ros_pkgs/include/airsim_ros_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class AirsimROSWrapper
232232
void publish_odom_tf(const nav_msgs::msg::Odometry& odom_msg);
233233

234234
/// camera helper methods
235-
sensor_msgs::msg::CameraInfo generate_cam_info(const std::string& camera_name, const CameraSetting& camera_setting, const CaptureSetting& capture_setting) const;
235+
sensor_msgs::msg::CameraInfo generate_cam_info(const std::string& frame_id, const CameraSetting& camera_setting, const CaptureSetting& capture_setting) const;
236236

237237
std::shared_ptr<sensor_msgs::msg::Image> get_img_msg_from_response(const ImageResponse& img_response, const rclcpp::Time curr_ros_time, const std::string frame_id);
238238
std::shared_ptr<sensor_msgs::msg::Image> get_depth_img_msg_from_response(const ImageResponse& img_response, const rclcpp::Time curr_ros_time, const std::string frame_id);

ros2/src/airsim_ros_pkgs/src/airsim_ros_wrapper.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void AirsimROSWrapper::create_ros_pubs_from_settings_json()
216216
const std::string camera_topic = topic_prefix + "/" + curr_camera_name + "/" + image_type_int_to_string_map_.at(capture_setting.image_type);
217217
image_pub_vec_.push_back(image_transporter.advertise(camera_topic, 1));
218218
cam_info_pub_vec_.push_back(nh_->create_publisher<sensor_msgs::msg::CameraInfo>(camera_topic + "/camera_info", 10));
219-
camera_info_msg_vec_.push_back(generate_cam_info(curr_camera_name, camera_setting, capture_setting));
219+
camera_info_msg_vec_.push_back(generate_cam_info(curr_vehicle_name + "/" + curr_camera_name + "_optical", camera_setting, capture_setting));
220220
}
221221
}
222222
// push back pair (vector of image captures, current vehicle name)
@@ -1210,8 +1210,8 @@ void AirsimROSWrapper::append_static_camera_tf(VehicleROS* vehicle_ros, const st
12101210
}
12111211

12121212
geometry_msgs::msg::TransformStamped static_cam_tf_optical_msg = static_cam_tf_body_msg;
1213+
// Keep vehicle namespace so multi-robot TF trees match body frames.
12131214
static_cam_tf_optical_msg.child_frame_id = vehicle_ros->vehicle_name_ + "/" + camera_name + "_optical/static";
1214-
static_cam_tf_optical_msg.child_frame_id = camera_name + "_optical/static";
12151215
static_cam_tf_optical_msg.transform = get_camera_optical_tf_from_body_tf(static_cam_tf_body_msg.transform);
12161216

12171217
vehicle_ros->static_tf_msg_vec_.emplace_back(static_cam_tf_body_msg);
@@ -1295,13 +1295,13 @@ std::shared_ptr<sensor_msgs::msg::Image> AirsimROSWrapper::get_depth_img_msg_fro
12951295
}
12961296

12971297
// todo have a special stereo pair mode and get projection matrix by calculating offset wrt drone body frame?
1298-
sensor_msgs::msg::CameraInfo AirsimROSWrapper::generate_cam_info(const std::string& camera_name,
1298+
sensor_msgs::msg::CameraInfo AirsimROSWrapper::generate_cam_info(const std::string& frame_id,
12991299
const CameraSetting& camera_setting,
13001300
const CaptureSetting& capture_setting) const
13011301
{
13021302
unused(camera_setting);
13031303
sensor_msgs::msg::CameraInfo cam_info_msg;
1304-
cam_info_msg.header.frame_id = camera_name + "_optical";
1304+
cam_info_msg.header.frame_id = frame_id;
13051305
cam_info_msg.height = capture_setting.height;
13061306
cam_info_msg.width = capture_setting.width;
13071307
float f_x = (capture_setting.width / 2.0) / tan(math_common::deg2rad(capture_setting.fov_degrees / 2.0));
@@ -1335,13 +1335,13 @@ void AirsimROSWrapper::process_and_publish_img_response(const std::vector<ImageR
13351335
if (curr_img_response.pixels_as_float) {
13361336
image_pub_vec_[img_response_idx_internal].publish(get_depth_img_msg_from_response(curr_img_response,
13371337
curr_ros_time,
1338-
curr_img_response.camera_name + "_optical"));
1338+
vehicle_name + "/" + curr_img_response.camera_name + "_optical"));
13391339
}
13401340
// Scene / Segmentation / SurfaceNormals / Infrared
13411341
else {
13421342
image_pub_vec_[img_response_idx_internal].publish(get_img_msg_from_response(curr_img_response,
13431343
curr_ros_time,
1344-
curr_img_response.camera_name + "_optical"));
1344+
vehicle_name + "/" + curr_img_response.camera_name + "_optical"));
13451345
}
13461346
img_response_idx_internal++;
13471347
}

0 commit comments

Comments
 (0)