闫刚 px4 v1.8.0 SITL在环仿真

资源

linux_build_px4_posix.md
闫刚 px4仿真架构

编译

切换到1.8.0版本,编译posix_sitl_test,生成px4可执行文件

1. git check tag_v1.8.0
2. make posix_sitl_test
3. build/posix_sitl_test  

分析px4可执行文件中编译了那些模块

通过px4的elf分析代码中有那些模块,同时知道了main的入口,readelf -s xxx表示读取可执行文件的代码段

yangang@yangang-ubuntu:~/work/px4_proj/Firmware/build/posix_sitl_test$ readelf -s px4 |grep -n "main.cpp"
1465:    44: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS replay_main.cpp
1474:    53: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS main.cpp
1573:   152: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS land_detector_main.cpp
1584:   163: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS navigator_main.cpp
1585:   164: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS ekf2_main.cpp
1588:   167: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS wind_estimator_main.cpp
1594:   173: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS mc_att_control_main.cpp
1640:   219: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS MS5525_main.cpp
1644:   223: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS SDP3X_main.cpp
1770:   349: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS controllib_test_main.cpp
1782:   361: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS mc_pos_control_main.cpp
1786:   365: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS uORB_tests_main.cpp
1836:   415: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS hello_main.cpp
1838:   417: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS hrt_test_main.cpp
1840:   419: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS muorb_test_main.cpp
1842:   421: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS vcdevtest_main.cpp
1886:   465: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS mavlink_main.cpp
2007:   586: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS vtol_att_control_main.cpp
2098:   677: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS main.cpp

启动px4,看到了需要我们制定启动脚

"startup_config"是需要指定的启动脚本文件

yangang@yangang-ubuntu:~/work/px4_proj/Firmware/build/posix_sitl_test$ ./px4 
ERROR [Unknown] Error expected 1 or 2 position arguments, got 0
./px4 [-d] [data_directory] startup_config [-h]
   -d            - Optional flag to run the app in daemon mode and does not listen for user input.
                   This is needed if px4 is intended to be run as a upstart job on linux
<data_directory> - directory where ROMFS and posix-configs are located (if not given, CWD is used)
<startup_config> - config file for starting/stopping px4 modules
   -h            - help/usage information
Restoring terminal

我们先用px4的shell/iris的脚本, 发现已经正常跑了起来

yangang@yangang-ubuntu:~/work/px4_proj/Firmware/build/posix_sitl_test$ ./px4  ../../posix-configs/SITL/init/shell/iris
commands file: ../../posix-configs/SITL/init/shell/iris
58 WARNING: setRealtimeSched failed (not run as root?)

______  __   __    ___ 
| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

px4 starting.

pxh> 

启动qgroundstation

yangang@yangang-ubuntu:~/work/github_proj/fight$ ./QGroundControl.AppImage 

在px4中启动mavlink,连接飞控, 发现飞机已经连接上了

pxh> mavlink start -r 800000 -u 14556 -m config
INFO  [mavlink] mode: Config, data rate: 800000 B/s on udp port 14556 remote port 14550
pxh> mavlink boot_complete
INFO  [mavlink] MAVLink only on localhost (set param MAV_BROADCAST = 1 to enable network)
pxh> INFO  [mavlink] partner IP: 127.0.0.1

查看px4占用的线程有那些

yangang@yangang-ubuntu:/proc$ ps -ef |grep "px4"
yangang  30631 22252  0 18:32 pts/1    00:00:01 ./px4 ../../posix-configs/SITL/init/shell/iris
yangang@yangang-ubuntu:/proc/30631$ ls
yangang@yangang-ubuntu:/proc/30631$ cd task/
yangang@yangang-ubuntu:/proc/30631/task$ ls
30631  30632  30634  30636  30638  30640  31297  31298
yangang@yangang-ubuntu:/proc/30631/task$ ps -T -p 30631
  PID  SPID TTY          TIME CMD
30631 30631 pts/1    00:00:00 px4
30631 30632 pts/1    00:00:00 DFWorker
30631 30634 pts/1    00:00:00 hpwork
30631 30636 pts/1    00:00:00 lpwork
30631 30638 pts/1    00:00:00 wkr_hrt
30631 30640 pts/1    00:00:00 dataman
30631 31297 pts/1    00:00:01 mavlink_if0
30631 31298 pts/1    00:00:00 mavlink_rcv_if0

posix px4启动

mavlink start -r 800000 -u 14556 -m config

编译sitl,连接jmavsim

安装jmavsim的依赖

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo apt-get install ant openjdk-8-jdk openjdk-8-jre

切换到vv1.11.0-beta1最近版本

git checkout v1.11.0-beta1

jmavsim启动失败!!!!!!

$ make px4_sitl jmavsim
···
com.jogamp.opengl.GLException: X11GLXDrawableFactory - Could not initialize shared resources for X11GraphicsDevice[type .x11, connection :0, unitID 0, handle 0x0, owner false, ResourceToolkitLock[obj 0x117719aa, isOwner false, <451c54bf, 767aa9a5>[count 0, qsz 0, owner ]]]
at jogamp.opengl.x11.glx.X11GLXDrawableFactory S h a r e d R e s o u r c e I m p l e m e n t a t i o n . c r e a t e S h a r e d R e s o u r c e ( X 11 G L X D r a w a b l e F a c t o r y . j a v a : 326 ) a t j o g a m p . o p e n g l . S h a r e d R e s o u r c e R u n n e r . r u n ( S h a r e d R e s o u r c e R u n n e r . j a v a : 297 ) a t j a v a . l a n g . T h r e a d . r u n ( T h r e a d . j a v a : 748 ) C a u s e d b y : j a v a . l a n g . N u l l P o i n t e r E x c e p t i o n a t j o g a m p . o p e n g l . G L C o n t e x t I m p l . m a k e C u r r e n t ( G L C o n t e x t I m p l . j a v a : 688 ) a t j o g a m p . o p e n g l . G L C o n t e x t I m p l . m a k e C u r r e n t ( G L C o n t e x t I m p l . j a v a : 580 ) a t j o g a m p . o p e n g l . x 11. g l x . X 11 G L X D r a w a b l e F a c t o r y SharedResourceImplementation.createSharedResource(X11GLXDrawableFactory.java:326) at jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:297) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NullPointerException at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:688) at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:580) at jogamp.opengl.x11.glx.X11GLXDrawableFactory SharedResourceImplementation.createSharedResource(X11GLXDrawableFactory.java:326)atjogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:297)atjava.lang.Thread.run(Thread.java:748)Causedby:java.lang.NullPointerExceptionatjogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:688)atjogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:580)atjogamp.opengl.x11.glx.X11GLXDrawableFactorySharedResourceImplementation.createSharedResource(X11GLXDrawableFactory.java:297)
… 2 more
com.jogamp.opengl.GLException: J3D-Renderer-1: createImpl ARB n/a but required, profile > GL2 requested (OpenGL >= 3.1). Requested: GLProfile[GL3bc/GL3bc.hw], current: 3.0 (Compat profile, compat[ES2], FBO, hardware) - 3.0 Mesa 18.0.5
at jogamp.opengl.x11.glx.X11GLXContext.createImpl(X11GLXContext.java:418)
at jogamp.opengl.GLContextImpl.makeCurrentWithinLock(GLContextImpl.java:759)
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:642)
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:580)
at javax.media.j3d.JoglPipeline Q u e r y C a n v a s . d o Q u e r y ( J o g l P i p e l i n e . j a v a : 8615 ) a t j a v a x . m e d i a . j 3 d . J o g l P i p e l i n e QueryCanvas.doQuery(JoglPipeline.java:8615) at javax.media.j3d.JoglPipeline QueryCanvas.doQuery(JoglPipeline.java:8615)atjavax.media.j3d.JoglPipelineQueryCanvas.access$100(JoglPipeline.java:8566)
at javax.media.j3d.JoglPipeline.createQueryContext(JoglPipeline.java:6562)
at javax.media.j3d.Canvas3D.createQueryContext(Canvas3D.java:4609)
at javax.media.j3d.Canvas3D.createQueryContext(Canvas3D.java:3606)
at javax.media.j3d.Renderer.doWork(Renderer.java:461)
···
修改方法:
在.bashrc中添加以下内容

export SVGA_VGPU10=0

启动sitl_run的命令分析如下

./Tools/sitl_run.sh /home/yangang/work/Firmware/build/px4_sitl_default/bin/px4 none jmavsim none /home/yangang/work/Firmware /home/yangang/work/Firmware/build/px4_sitl_default

/Tools/sitl_run.sh /home/yangang/work/Firmware/build/px4_sitl_default/bin/px4  none  jmavsim  none  /home/yangang/work/Firmware /home/yangang/work/Firmware/build/px4_sitl_default
SITL ARGS
sitl_bin: /home/yangang/work/Firmware/build/px4_sitl_default/bin/px4
debugger: none
program: jmavsim
model: none
src_path: /home/yangang/work/Firmware
build_path: /home/yangang/work/Firmware/build/px4_sitl_default
empty model, setting iris as default
SITL COMMAND: "/home/yangang/work/Firmware/build/px4_sitl_default/bin/px4" "/home/yangang/work/Firmware"/ROMFS/px4fmu_common -s etc/init.d-posix/rcS -t "/home/yangang/work/Firmware"/test_data
INFO  [px4] Creating symlink /home/yangang/work/Firmware/ROMFS/px4fmu_common -> /home/yangang/work/Firmware/build/px4_sitl_default/tmp/rootfs/etc

______  __   __    ___ 
| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

px4 starting.

INFO  [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
INFO  [param] selected parameter default file eeprom/parameters_10016
[param] Loaded: eeprom/parameters_10016
INFO  [dataman] Unknown restart, data manager file './dataman' size is 11798680 bytes
INFO  [simulator] Waiting for simulator to connect on TCP port 4560
Buildfile: /home/yangang/work/Firmware/Tools/jMAVSim/build.xml

make_dirs:

compile:

create_run_jar:

copy_res:

BUILD SUCCESSFUL
Total time: 0 seconds
Options parsed, starting Sim.
Starting GUI...
3D [dev] 1.6.0-pre12-daily-experimental daily

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at me.drton.jmavsim.Visualizer3D.getVectorToTargetObject(Visualizer3D.java:695)
	at me.drton.jmavsim.Visualizer3D.setDynZoomDistance(Visualizer3D.java:623)
	at me.drton.jmavsim.Visualizer3D$KeyboardHandler.keyReleased(Visualizer3D.java:1160)
	at java.awt.Component.pro

建议: 直接使用sitl_run,否则会出现一些问题
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值