在订阅者节点中使用传感器消息时元素类型错误? [关闭]

问题描述 投票:0回答:1

使用 sensor_msgs 的节点。在头文件中包含 sensor_msg,同时声明了 IMU 传感器消息。问题在声明中

error: ‘using element_type = const struct sensor_msgs::msg::Imu_<std::allocator<void> >’ {aka ‘const struct sensor_msgs::msg::Imu_<std::allocator<void> >’} has no member named ‘imu’
  199 |   imu_qat.w() = imu_msg->imu.orientation.w;

传感器信息转换为特征四元数时发生错误

      // convert imu message to eigen quaternion
      Eigen::Quaternionf imu_qat;
      Imu imu;
      imu_qat.w() = imu_msg->imu.orientation.w;
      imu_qat.x() = imu_msg->imu.orientation.x;
      imu_qat.y() = imu_msg->imu.orientation.y;
      imu_qat.z() = imu_msg->imu.orientation.z;
      ....

#include <sensor_msgs/msg/imu.hpp>
在头文件中添加。

ros imu
1个回答
2
投票

报错说IMU报文不包含

imu
字段。 看看API然后你也会看到不存在这样的成员。

相反,

sensor_msgs::msg::Imu
直接暴露
orientation
,所以你需要做的是例如:

static void imu_callback(const sensor_msgs::msg::Imu::SharedPtr msg) {
  RCLCPP_INFO(
      rclcpp::get_logger("rclcpp"), "Got IMU msg with WXYZ: [%f, %f, %f, %f]",
      msg->orientation.w, msg->orientation.x, msg->orientation.y,
      msg->orientation.z);
}
© www.soinside.com 2019 - 2024. All rights reserved.