软件在环仿真

  • 软件在环 (Software-in-loop, SIL) 仿真是将源码进行编译并运行在电脑主机端,为系统功能或控制策略的开发和测试提供实用的虚拟仿真环境,同时也省去了购买硬件的成本。

    FMT 的 SIL 环境是基于 QEMU 构建的。通过QEMU模拟的硬件平台(vexpress-a9)来让 FMT 运行在主机端,因为QEMU是跨平台的,所以基于QEMU实现的SIL可以运行在Windows,Linux和MacOS等。

    如果没有安装过QEMU,需要先下载QEMU,可以去官网进行下载。下载安装完成之后,进入FMT-Firmware/target/qemu/qemu-vexpress-a9目录,然后编译固件

    jiachi@jc-laptop:~/src/FMT-Autopilot/FMT-Firmware/target/qemu/qemu-vexpress-a9$ scons -j4
    scons: Reading SConscript files ...
    b''
    scons: done reading SConscript files.
    scons: Building targets ...
    scons: building associated VariantDir targets: build
    CC build/board/board.o
    CC build/drivers/drv_sdio.o
    ......
    CC build/kernel/components/libc/compilers/newlib/stdio.o
    CC build/kernel/components/libc/compilers/newlib/syscalls.o
    LINK build/fmt_fmu.elf
    arm-none-eabi-objcopy -O binary build/fmt_fmu.elf build/fmt_fmu.bin
    arm-none-eabi-size build/fmt_fmu.elf
     text	   data	    bss	    dec	    hex	filename
    1139824	  28980	 143256	1312060	 14053c	build/fmt_fmu.elf
    scons: done building targets.
    
  • 编译完成后,首先打开QGC地面站,然后再运行qemu.sh(Windows平台则运行qemu.bat),如下所示

    jiachi@jc-laptop:~/src/FMT-Autopilot/FMT-Firmware/target/qemu/qemu-vexpress-a9$ ./qemu.sh 
    WARNING: Image format was not specified for 'sd.bin' and probing guessed raw.
           Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
           Specify the 'raw' format explicitly to remove the restrictions.
    pulseaudio: set_sink_input_volume() failed
    pulseaudio: Reason: Invalid argument
    pulseaudio: set_sink_input_mute() failed
    pulseaudio: Reason: Invalid argument
    [I/SDIO] SD card capacity 65536 KB.
    [I/SDIO] switching card to high speed failed!
    can not load /sys/sih_param.xml, use default parameter value.
    TOML: fail to open file: /sys/sysconfig.toml
    
       _____                               __ 
      / __(_)_____ _  ___ ___ _  ___ ___  / /_
     / _// / __/  ' \/ _ `/  ' \/ -_) _ \/ __/
    /_/ /_/_/ /_/_/_/\_,_/_/_/_/\__/_//_/\__/ 
    Firmware..................FMT FW v0.3.0-rc
    Kernel....................RT-Thread v4.0.3
    RAM................................8192 KB
    Target....................QEMU vexpress-a9
    Vehicle.........................Quadcopter
    INS Model..................Base INS v0.2.1
    FMS Model..................Base FMS v0.3.2
    Control Model.......Base Controller v0.2.1
    Plant Model.............Multicopter v0.2.1
    Task Initialize:
    local.................................OK
    comm..................................OK
    logger................................OK
    status................................OK
    vehicle...............................OK
    [1074] I/StatusTask: SIH Simulation
    Hello FMT!
    

    提示:

    对于Windows平台,在第一次通过QEMU启动FMT时,文件系统可能没有正常格式化,可以在控制台输入`mkfs sd0`指令来对文件系统进行格式化。
  • 这时切到地面站,地面站应该也已经正常连接上飞控。恭喜,到这一步基于QEMU的SIL仿真已经运行起来了。