AirSim (六) ---理解篇: Airsim中的IMU数据信息

目录

  • 1 理解好IMU的输出数据
  • 2 AirSim中如何生成IMU数据
  • 3 AirSim中如何读取IMU数据
  • 4. IMU的数据 in AirSim and ROS IMU Message

1 理解好IMU的输出数据

IMU输出的数据中的线速度和线加速度,是在世界坐标系下,即NED北-东-下坐标系。

  1. IMU加速度计测量加速度不包含重力加速度
  2. 如果IMU自由落体运动,不考虑噪声加速度计的读数是0。
  3. 如果IMU静止在地面上,IMU读数是-9.8m/s2
  4. 如果IMU悬浮在空间,IMU读数是-9.8m/s2
    关于IMU加速度读数不包含重力加速度的理解:issues#4303; 以及IMU原理;和IMU传感器。
    来自引用文献{issues#4303]的解释:可以这样认为,IMU的内部运行可以理解为一个盒子,里面有一个质量悬浮在两个弹簧之间,质量的位置对应了IMU的输出。当这个盒子(IMU)坐在一张桌子上,作用力会推/拉在其内部的质量弹簧 :因为质量会引起重力加速度,但是盒子是静止的,这是由于盒子受到桌面的法向/接触力。这就像质量将推/拉弹簧向下(+z方向),而同时由于存在一个向上的作用力引起的加速度 (因为惯性),整个盒子加速度为0,但是IMU读起来都是向上(-Z方向)的。
    对于自由落下的盒子,质量将受到重力朝向中心位置,这里没有推/拉弹簧:现在质量和盒子都被重力同样加速,一个与另一个在受力上没有不同),IMU最终读到的是0加速度,反映它如何不再受地面法向力/接触力的影响。本质上,因为IMU的读数取决于盒子和里面的质量之间的力的差异,所以重力只能根据作用在盒子上的法向/接触力来测量(方向相反,大小相同)。

2 AirSim中如何生成IMU数据

AirSim中,IMU的读数输出对应两个坐标系:

  1. 机体坐标系: 采用FLU坐标系,主要是角速度和角加速度;
  2. 世界坐标系:采用NED坐标系,主要是其他的读数,包括线速度和加速度。

AirSim通过程序来生成IMU数据,原理是获取vehicle状态和环境重力状态来计算,代码为:IMU数据生成程序。


void updateOutput()
{
    Output output; //IMU生成的数据
    // 第一步:获得vehicle的真值数据
    const GroundTruth& ground_truth = getGroundTruth(); //得到无人机真值,包括*.kinematics动力学数据
    // 第二步:获得角速度
    output.angular_velocity = ground_truth.kinematics->twist.angular;//将无人机的角速度赋值给output.angular_velocity,FLU坐标系下
    // 第三步:获得加速度
output.linear_acceleration = ground_truth.kinematics->accelerations.linear - ground_truth.environment->getState().gravity;//生成IMU加速度数据(世界坐标系NED),IMU加速度不含重力加速度
    // 第四步:获得位姿
output.orientation = ground_truth.kinematics->pose.orientation;// 得到无人机在世界系下的姿态
    // 第五步:坐标转换??
//acceleration is in world frame so transform to body frame
output.linear_acceleration = VectorMath::transformToBodyFrame(output.linear_acceleration, 
ground_truth.kinematics->pose.orientation, true);// 将加速度转换为体坐标系下,这里使用表明Rwb后直接作为IMU数据,而没有Rbi,表明imu系与body系为同一系
    // 第六步:add noise
        addNoise(output.linear_acceleration, output.angular_velocity);
        // TODO: Add noise in orientation?
        
    // 第七步:增加时间戳
        output.time_stamp = clock()->nowNanos(); // 真实cpu时间??

        setOutput(output);

关于坐标变换函数的代码,在AirSim/AirLib/include/common/VectorMath.hpp中展示的代码如下:

 static Vector3T transformToBodyFrame(const Vector3T& v_world, const QuaternionT& q_world, bool assume_unit_quat = true)
        {
            return rotateVectorReverse(v_world, q_world, assume_unit_quat);
        }

        static Vector3T transformToBodyFrame(const Vector3T& v_world, const Pose& body_world, bool assume_unit_quat = true)
        {
            //translate
            Vector3T translated = v_world - body_world.position;
            //rotate
            return transformToBodyFrame(translated, body_world.orientation, assume_unit_quat);
        }

        static Pose transformToBodyFrame(const Pose& pose_world, const Pose& body_world, bool assume_unit_quat = true)
        {
            //translate
            Vector3T translated = pose_world.position - body_world.position;
            //rotate vector
            Vector3T v_body = transformToBodyFrame(translated, body_world.orientation, assume_unit_quat);
            //rotate orientation
            QuaternionT q_body = rotateQuaternionReverse(pose_world.orientation, body_world.orientation, assume_unit_quat);

            return Pose(v_body, q_body);
        }

3 AirSim中如何读取IMU数据

源自: Sensor APIs: IMU

可以跳转到hello_drone.py或hello_drone.cpp参考demo代码。
或者查看下面的完整API函数:
读取IMU数据函数原型:

msr::airlib::ImuBase::Output getImuData(const std::string& imu_name = "", const std::string& vehicle_name = "");

读取IMU数据的函数:

        // IMU API: AirSim/AirLib/include/api/VehicleApiBase.hpp
        virtual const ImuBase::Output& getImuData(const std::string& imu_name) const
        {
            auto* imu = static_cast<const ImuBase*>(findSensorByName(imu_name, SensorBase::SensorType::Imu));
            if (imu == nullptr)
                throw VehicleControllerException(Utils::stringf("No IMU with name %s exist on vehicle", imu_name.c_str()));

            return imu->getOutput();
        }

读取IMU数据调用:

imu_data = client.getImuData(imu_name = "", vehicle_name = "")

相关数据源码:Output

//源码:AirSim/AirLib/include/sensors/imu/ImuBase.hpp
class ImuBase : public SensorBase
    {
   ...

    public: //types
        struct Output
        { //structure is same as ROS IMU message  与ROS IMU message一致
            EIGEN_MAKE_ALIGNED_OPERATOR_NEW
            TTimePoint time_stamp;
            Quaternionr orientation;
            Vector3r angular_velocity;
            Vector3r linear_acceleration;
        };
        ...

4. IMU的数据 in AirSim and ROS IMU Message

ROS IMU中关于IMU的信息:点击我。
AirSim (六) ---理解篇: Airsim中的IMU数据信息_第1张图片
其中,Quaternion四元数的解释:点击我
AirSim (六) ---理解篇: Airsim中的IMU数据信息_第2张图片

你可能感兴趣的:(AirSim,ubuntu,python,自动驾驶)