Skip to content

Commit 75f9b09

Browse files
committed
salvage: keep NED odom when ENU enabled (credit @nikola-j #4631)
Publish converted ENU on a separate topic so odom_local_ned stays NED.
1 parent d109f0d commit 75f9b09

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

ros2/src/airsim_ros_pkgs/include/airsim_ros_wrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class AirsimROSWrapper
138138

139139
/// All things ROS
140140
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odom_local_pub_;
141+
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odom_local_enu_pub_;
141142
rclcpp::Publisher<sensor_msgs::msg::NavSatFix>::SharedPtr global_gps_pub_;
142143
rclcpp::Publisher<airsim_interfaces::msg::Environment>::SharedPtr env_pub_;
143144
airsim_interfaces::msg::Environment env_msg_;
@@ -255,6 +256,7 @@ class AirsimROSWrapper
255256
msr::airlib::Quaternionr get_airlib_quat(const geometry_msgs::msg::Quaternion& geometry_msgs_quat) const;
256257
msr::airlib::Quaternionr get_airlib_quat(const tf2::Quaternion& tf2_quat) const;
257258
nav_msgs::msg::Odometry get_odom_msg_from_kinematic_state(const msr::airlib::Kinematics::State& kinematics_estimated) const;
259+
nav_msgs::msg::Odometry convert_odom_to_enu(const nav_msgs::msg::Odometry original_odom_msg) const;
258260
nav_msgs::msg::Odometry get_odom_msg_from_multirotor_state(const msr::airlib::MultirotorState& drone_state) const;
259261
nav_msgs::msg::Odometry get_odom_msg_from_car_state(const msr::airlib::CarApiBase::CarState& car_state) const;
260262
airsim_interfaces::msg::CarState get_roscarstate_msg_from_car_state(const msr::airlib::CarApiBase::CarState& car_state) const;

ros2/src/airsim_ros_pkgs/src/airsim_ros_wrapper.cpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ void AirsimROSWrapper::create_ros_pubs_from_settings_json()
153153

154154
const std::string topic_prefix = "~/" + curr_vehicle_name;
155155
vehicle_ros->odom_local_pub_ = nh_->create_publisher<nav_msgs::msg::Odometry>(topic_prefix + "/" + odom_frame_id_, 10);
156+
if (isENU_)
157+
vehicle_ros->odom_local_enu_pub_ = nh_->create_publisher<nav_msgs::msg::Odometry>(topic_prefix + "/" + ENU_ODOM_FRAME_ID, 10);
156158

157159
vehicle_ros->env_pub_ = nh_->create_publisher<airsim_interfaces::msg::Environment>(topic_prefix + "/environment", 10);
158160

@@ -603,6 +605,8 @@ nav_msgs::msg::Odometry AirsimROSWrapper::get_odom_msg_from_kinematic_state(cons
603605
{
604606
nav_msgs::msg::Odometry odom_msg;
605607

608+
odom_msg.header.frame_id = AIRSIM_FRAME_ID;
609+
606610
odom_msg.pose.pose.position.x = kinematics_estimated.pose.position.x();
607611
odom_msg.pose.pose.position.y = kinematics_estimated.pose.position.y();
608612
odom_msg.pose.pose.position.z = kinematics_estimated.pose.position.z();
@@ -618,16 +622,40 @@ nav_msgs::msg::Odometry AirsimROSWrapper::get_odom_msg_from_kinematic_state(cons
618622
odom_msg.twist.twist.angular.y = kinematics_estimated.twist.angular.y();
619623
odom_msg.twist.twist.angular.z = kinematics_estimated.twist.angular.z();
620624

621-
if (isENU_) {
622-
std::swap(odom_msg.pose.pose.position.x, odom_msg.pose.pose.position.y);
623-
odom_msg.pose.pose.position.z = -odom_msg.pose.pose.position.z;
624-
std::swap(odom_msg.pose.pose.orientation.x, odom_msg.pose.pose.orientation.y);
625-
odom_msg.pose.pose.orientation.z = -odom_msg.pose.pose.orientation.z;
626-
std::swap(odom_msg.twist.twist.linear.x, odom_msg.twist.twist.linear.y);
627-
odom_msg.twist.twist.linear.z = -odom_msg.twist.twist.linear.z;
628-
std::swap(odom_msg.twist.twist.angular.x, odom_msg.twist.twist.angular.y);
629-
odom_msg.twist.twist.angular.z = -odom_msg.twist.twist.angular.z;
630-
}
625+
return odom_msg;
626+
}
627+
628+
nav_msgs::msg::Odometry AirsimROSWrapper::convert_odom_to_enu(const nav_msgs::msg::Odometry original_odom_msg) const
629+
{
630+
nav_msgs::msg::Odometry odom_msg;
631+
632+
odom_msg.header.stamp = original_odom_msg.header.stamp;
633+
odom_msg.header.frame_id = "world_enu";
634+
635+
odom_msg.pose.pose.position.x = original_odom_msg.pose.pose.position.x;
636+
odom_msg.pose.pose.position.y = original_odom_msg.pose.pose.position.y;
637+
odom_msg.pose.pose.position.z = original_odom_msg.pose.pose.position.z;
638+
639+
odom_msg.pose.pose.orientation.x = original_odom_msg.pose.pose.orientation.x;
640+
odom_msg.pose.pose.orientation.y = original_odom_msg.pose.pose.orientation.y;
641+
odom_msg.pose.pose.orientation.z = original_odom_msg.pose.pose.orientation.z;
642+
odom_msg.pose.pose.orientation.w = original_odom_msg.pose.pose.orientation.w;
643+
644+
odom_msg.twist.twist.linear.x = original_odom_msg.twist.twist.linear.x;
645+
odom_msg.twist.twist.linear.y = original_odom_msg.twist.twist.linear.y;
646+
odom_msg.twist.twist.linear.z = original_odom_msg.twist.twist.linear.z;
647+
odom_msg.twist.twist.angular.x = original_odom_msg.twist.twist.angular.x;
648+
odom_msg.twist.twist.angular.y = original_odom_msg.twist.twist.angular.y;
649+
odom_msg.twist.twist.angular.z = original_odom_msg.twist.twist.angular.z;
650+
651+
std::swap(odom_msg.pose.pose.position.x, odom_msg.pose.pose.position.y);
652+
odom_msg.pose.pose.position.z = -odom_msg.pose.pose.position.z;
653+
std::swap(odom_msg.pose.pose.orientation.x, odom_msg.pose.pose.orientation.y);
654+
odom_msg.pose.pose.orientation.z = -odom_msg.pose.pose.orientation.z;
655+
std::swap(odom_msg.twist.twist.linear.x, odom_msg.twist.twist.linear.y);
656+
odom_msg.twist.twist.linear.z = -odom_msg.twist.twist.linear.z;
657+
std::swap(odom_msg.twist.twist.angular.x, odom_msg.twist.twist.angular.y);
658+
odom_msg.twist.twist.angular.z = -odom_msg.twist.twist.angular.z;
631659

632660
return odom_msg;
633661
}
@@ -1026,6 +1054,9 @@ void AirsimROSWrapper::publish_vehicle_state()
10261054

10271055
// odom and transforms
10281056
vehicle_ros->odom_local_pub_->publish(vehicle_ros->curr_odom_);
1057+
if (isENU_)
1058+
vehicle_ros->odom_local_enu_pub_->publish(convert_odom_to_enu(vehicle_ros->curr_odom_));
1059+
10291060
publish_odom_tf(vehicle_ros->curr_odom_);
10301061

10311062
// ground truth GPS position from sim/HITL

0 commit comments

Comments
 (0)