jMAVSim 进行 SITL 仿真

jMAVSim是一个简单的多旋翼/四旋翼仿真软件,它可以允许你在仿真环境中飞行运行着 PX4 的 旋翼 无人机。 它很容易设置,可以用来测试您的工具是否可以起飞、飞行、降落、并对各种故障条件 (例如 gps 故障) 做出适当的反应。

支持机型:

  • 四旋翼

本问主要演示如何设置 jMAVSim 以连接到 SITL 版本的 PX4 。

jMAVSim can also be used for HITL Simulation (as shown here).

Installation

jMAVSim setup is included in our standard build instructions (for macOS, Ubuntu Linux, Windows).

Simulation Environment

Software in the Loop Simulation runs the complete system on the host machine and simulates the autopilot. It connects via local network to the simulator. The setup looks like this:

Mermaid graph: SITL Simulator

Running SITL

After ensuring that the simulation prerequisites are installed on the system, just launch: The convenience make target will compile the POSIX host build and run the simulation.

make px4_sitl_default jmavsim

This will bring up the PX4 shell:

[init] shell id: 140735313310464
[init] task name: px4

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

Ready to fly.


pxh>

It will also bring up a window showing a 3D view of the jMAVSim simulator:

jMAVSim 3d View

Taking it to the Sky

The system will start printing status information. You will be able to start flying once you have a position lock (shortly after the console displays the message: EKF commencing GPS fusion).

To takeoff enter the following into the console:

pxh> commander takeoff

You can use QGroundControl to fly a mission or to connect to a joystick.

Usage/Configuration Options

指定起飞位置

The default takeoff location in can be overridden using the environment variables: PX4_HOME_LAT, PX4_HOME_LON, and PX4_HOME_ALT.

For example, to set the latitude, longitude and altitude:

export PX4_HOME_LAT=28.452386
export PX4_HOME_LON=-13.867138
export PX4_HOME_ALT=28.5
make px4_sitl_default jmavsim

更改仿真的时间流速

The simulation speed can be increased or decreased with respect to realtime using the environment variable PX4_SIM_SPEED_FACTOR.

export PX4_SIM_SPEED_FACTOR=2
make px4_sitl_default jmavsim

For more information see: Simulation > Run Simulation Faster than Realtime.

使用游戏手柄

Joystick and thumb-joystick support are supported through QGroundControl (setup instructions here).

模拟一个 Wifi 无人机

There is a special target to simulate a drone connected via Wifi on the local network:

make broadcast jmavsim

The simulator broadcasts its address on the local network as a real drone would do.

分别启动 JMAVSim 和 PX4

You can start JMAVSim and PX4 separately:

./Tools/jmavsim_run.sh -l
make px4_sitl none

This allows a faster testing cycle (restarting jMAVSim takes significantly more time).

无航向模式

To start jMAVSim without the GUI, set the env variable HEADLESS=1 as shown:

HEADLESS=1 make px4_sitl jmavsim

Multi-Vehicle Simulation

JMAVSim can be used for multi-vehicle simulation: Multi-Vehicle Sim with JMAVSim.

Extending and Customizing

To extend or customize the simulation interface, edit the files in the Tools/jMAVSim folder. The code can be accessed through thejMAVSim repository on Github.

编译系统会强制检查所有依赖项的子模块正确无误,其中就包括了模拟器。 但是,它不会直接覆盖你对目录中文件所做的更改, 当提交这些更改时你需要在 固件 库中重新为子模块注册新的哈希值。 为此,,使用 git add Tools/jMAVSim 并提交你的更改。 这就会更新仿真器中 GIT 哈希值。

Interfacing to ROS

The simulation can be interfaced to ROS the same way as onboard a real vehicle.

Important Files

  • The startup scripts are discussed in System Startup.
  • 已仿真的根文件系统 ("/" 目录) 是在编译文件里面生成的: build/px4_sitl_default/tmp/rootfs

Troubleshooting

java.long.NoClassDefFoundError

If you see an error similar to the one below, it's likely that you're using a Java version later than 8:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/vecmath/Tuple3d
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:374)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: javax.vecmath.Tuple3d
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:566)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 3 more
Exception in thread "main" java.lang.NoClassDefFoundError: javax/vecmath/Tuple3d
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:374)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: javax.vecmath.Tuple3d
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:566)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)

For more info check this GitHub issue.

The solution is to install the Java 8, as shown in the following sections.

Ubuntu:

sudo apt install openjdk-8-jdk
sudo update-alternatives --config java # 选择Java 8 的指令
rm -rf Tools/jMAVSim/out

Mac系统:

We recommend to install OpenJDK 8 from AdoptOpenJDK using brew:

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8
brew install ant
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
rm -rf Tools/jMAVSim/out

Alternatively you could download Oracle Java 8 and install it manually.

An illegal reflective access operation has occured

If you see an error similar to the one below, it's likely that you're using a Java version later than 8:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by javax.media.j3d.JoglPipeline (rsrc:j3dcore.jar) to method sun.awt.AppContext.getAppContext()
WARNING: Please consider reporting this to the maintainers of javax.media.j3d.JoglPipeline
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Inconsistency detected by ld.so: dl-lookup.c: 112: check_match: Assertion version->filename == NULL || ! _dl_name_match_p (version->filename, map)' failed!

Follow the steps above to make sure Java 8 is installed and selected.

java.awt.AWTError: Assistive Technology not found: org.GNOME.Accessibility.AtkWrapper

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.awt.AWTError: Assistive Technology not found: org.GNOME.Accessibility.AtkWrapper
at java.awt.Toolkit.loadAssistiveTechnologies(Toolkit.java:807)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:886)
at java.awt.Window.getToolkit(Window.java:1358)
at java.awt.Window.init(Window.java:506)
at java.awt.Window.(Window.java:537)
at java.awt.Frame.(Frame.java:420)
at java.awt.Frame.(Frame.java:385)
at javax.swing.JFrame.(JFrame.java:189)
at me.drton.jmavsim.Visualizer3D.(Visualizer3D.java:104)
at me.drton.jmavsim.Simulator.(Simulator.java:157)
at me.drton.jmavsim.Simulator.main(Simulator.java:678)

If you see this error, try this workaround:

Edit the accessibility.properties file:

sudo gedit /etc/java-8-openjdk/accessibility.properties

and comment out the line indicated below:

#assistive_technologies=org.GNOME.Acessibility.AtkWrapper

For more info check this GitHub issue. The fix was found in askubuntu.com.

results matching ""

    No results matching ""