您的位置:首页 > 其它

jMAVSim半硬件仿真(HITL)

2016-07-19 12:31 1526 查看
jMAVSim半硬件仿真(HITL)

jMAVSim,玩四轴的朋友会知道这是一款模拟器,用来模拟飞行器的各种旋转动作。官网也有对jMAVSim做了解释:

jMAVSim is a simple and lightweight multirotor simulator. It connects directly to the hardware-in-the-loop (HITL, via serial) or software-in-the-loop (SITL, via UDP) instance of the autopilot.

大体意思是jMAVSim是一个简单的轻量级多转子模拟器。它直接连接到硬件(HITL,通过串行)或软件(SITL,通过UDP)自动驾驶仪的实例。

下面介绍一下jMAVSim半硬件仿真的实际操作方法,也可以直接访问官方网站:http://www.pixhawk.com/dev/hil/jmavsim

1.获取jMAVSim文件

获取jMAVSim文件是直接从git服务器上克隆的,执行指令(环境是Ubuntu14):

$ git clone https://github.com/PX4/jMAVSim.git[/code]运行jMAVSim需要添加相关依赖 
$ sudo apt-get install ant openjdk-7-jdk openjdk-7-jre
在这里有些同学会遇到一些问题,安装不上,主要是Java版本降级的原因,后续介绍。。。

mac系统执行指令:

brew install ant


2.工程建立和运行

运行jMAVSim需要初始Git仓库

~/Documents$ cd jMAVSim/
~/Documents/jMAVSim$ git submodule init
~/Documents/jMAVSim$ git submodule update


运行
~/jMAVSim$ ant
Buildfile: /jMAVSim/build.xml

make_dirs:

compile:

jmavsim:

all:

BUILD SUCCESSFUL
Total time: 0 seconds


3.半硬件仿真(HITL,Hardware in
the Loop)

官方也给出了相关的仿真步骤,经常动手的同学知道,官网的例子运行的好好地,为什么到了我的系统上就不行了呢?

官网给出的步骤:

Hardware
in the Loop (HITL)

Here is an example for quadrotor X.

1.Configure PX4 autopilot for HIL setup using either of these methods:

a.Using QGroundControl: Connect to board, click Setup, click Airframe, check the box in the Simulation selection (last one in list) and pick the type of HIL setup you want from the drop-down. Apply and Restart, Reconnect.

b.By hand: Set parameter SYS_AUTOSTART = 1001, save parameters and reboot.

2.Run jMAVSim in HITL mode. Change the serial port to the port of Pixhawk and make sure to have QGroundControl NOT connected to serial.

java -Djava.ext.dirs= -cp lib/*:out/production/jmavsim.jar me.drton.jmavsim.Simulator -serial /dev/tty.usbmodem1 921600 -qgc
3.The console will display mavlink text messages from the autopilot.

4.To connect QGroundControl to this system: Select the default UDP link from the “connect” button in the top right corner and connect it.

5.Ready to fly!

大致翻译一下:

以四轴为例

1,使用a,b中任何一个方法配置PX4自动驾驶

a.使用QGC:链接板子,点击设置,选择飞机框架,勾选选择模拟器(最后一个)并选择HIL类型(每次选择飞机类型都要校准传感器,个人觉得比较烦。问题1:选择模拟模式的时候,遥控器遥控飞机的时候,飞机实物电机会不会不转,而在模拟环境中转?待考证。。。),应用重启,重新连接。



b.手动:设置SYS_AUTOSTART参数为1001,保存重启。



2.在HIL模式下运行jMAVSim,将串口改为Pixhawk串口,并且确保QGC没有连接到串口。(问题2:还不知道硬件怎么接?)

打开终端输入指令:

~/jMAVSim$ java -Djava.ext.dirs= -cp lib/*:out/production/jmavsim.jar me.drton.jmavsim.Simulator -serial /dev/tty.usbmodem1 921600 -qgc
Options parsed, starting Sim.
Starting GUI...
3D [dev] 1.6.0-pre12-daily-experimental daily

ERROR: Failed to open MAV port: jssc.SerialPortException: Port name - /dev/tty.usbmodem1; Method name - openPort(); Exception type - Port not found.
^CShutting down...
但是报错了,提示打不开MAV端口,原因是没有端口权限。。。端口权限我也是第一次听说,感觉自己好low

下面打开端口权限执行指令:

$ sudo chmod 777 /dev/ttyACM0
(输入打开端口权限指令的时候,端口一定要介入,不然会显示找不到文件)

再次输入指令,但是要做修改:

~/Documents/jMAVSim$ java -Djava.ext.dirs= -cp lib/*:out/production/jmavsim.jar me.drton.jmavsim.Simulator -serial /dev/ttyACM0 921600 -qgc
Options parsed, starting Sim.
Starting GUI...
3D [dev] 1.6.0-pre12-daily-experimental daily

Init MAVLink
MSG: [inav] GPS signal found
MSG: [inav] init ref: 47.3977420, 8.5455940, 488.0000
MSG: [inav] GPS timeout
MSG: [inav] GPS signal found
jMAVSim成功打开了!

后面利用无线通信模块将四轴跟电脑Win系统里面的QGC相连接,打开安全开关就可以用力遥控器遥控飞机了,QGC可以查看飞机的路径,速度,高度等信息;jMAVSim可以查看飞机的具体动作,方向等信息。







后面解答一下那两个问题吧!

问题1:我没采用选择模拟类型的方法,我感觉那样比较繁琐,每次还要校准,我选择改变参数的方法,遥控器控制的时候,实体飞机是不动的,只有飞控板在工作。

问题2:连接方式,飞控板通过USB线连接虚拟机中的linux,然后再利用无线模块将飞控板与Win系统中的QGC相连,最后打开安全开关,就可以控制飞机了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息