第一章 ArduSub SITL Ubuntu环境搭建
作者:张玉梅 zhangym@pcl.ac.cn
1.1.安装过程
第一步:
http://ardupilot.org/dev/docs/building-setup-linux.html#building-setup-linux
Setting up the Build Environment (Linux/Ubuntu)
如果已经有git了。可以忽略页面中git相关的步骤。
- git clone https://github.com/ArduPilot/ardupilot
- cd ardupilot
- git submodule update --init --recursive
Tools/environment_install/install-prereqs-ubuntu.sh -y
(安装耗时很长,需要权限, 可能报错,报错再根据提示或根据经验进行修正)
. ~/.profile
找到你的路径,根据你的路径修改环境变量,例如:
export PATH=$PATH:$HOME/ardupilot/Tools/autotest
export PATH=/usr/lib/ccache:$PATH
安装交叉编译工具
cd TARGET_DIR
tar -xjvf gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2
export PATH=$PATH:TARGET_DIR/gcc-arm-none-eabi-4_9-2015q3/bin
sudo apt-get install ccache
cd /usr/lib/ccache
sudo ln -s /usr/bin/ccache arm-none-eabi-g++
sudo ln -s /usr/bin/ccache arm-none-eabi-gcc
第二步:
http://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html
启动SITL
$ sim_vehicle.py -v ArduSub
当显示
.....
APM: EKF2 IMU0 is using GPS
APM: EKF2 IMU1 is using GPS
Flight battery 100 percent
就成功了。
按ctrl+C。再启动sim_vehicle.py
ardupilot/Tools/autotest$ sim_vehicle.py -L RATBeach --out=udp:0.0.0.0:14550 --map –console -v ArduSub
第三步,安装运行mavros相关软件包
http://ardupilot.org/dev/docs/ros-install.html#installing-mavros
$sudo apt-get install ros-kinetic-mavros*
修改apm.launch
http://ardupilot.org/dev/docs/ros-sitl.html
<launch>
<!-- vim: set ft=xml noet : -->
<!-- example launch script for ArduPilot based FCU's
<arg name="fcu_url" default="/dev/ttyACM0:57600" />
-->
<arg name="fcu_url" default="udp://127.0.0.1:14550@" />
<arg name="gcs_url" default="" />
<arg name="tgt_system" default="1" />
<arg name="tgt_component" default="1" />
<arg name="fcu_protocol" default="v2.0" />
<arg name="respawn_mavros" default="false" />
<include file="$(find mavros)/launch/node.launch">
<arg name="pluginlists_yaml" value="$(find mavros)/launch/apm_pluginlists.yaml" />
<arg name="config_yaml" value="$(find mavros)/launch/apm_config.yaml" />
<arg name="fcu_url" value="$(arg fcu_url)" />
<arg name="gcs_url" value="$(arg gcs_url)" />
<arg name="tgt_system" value="$(arg tgt_system)" />
<arg name="tgt_component" value="$(arg tgt_component)" />
<arg name="fcu_protocol" value="$(arg fcu_protocol)" />
<arg name="respawn_mavros" default="$(arg respawn_mavros)" />
</include>
</launch>
运行修改后的apm.launch。
开始SITL了。
1.2.可能错误处理
可能报错:
File not readable /usr/share/GeographicLib/geoids/egm96-5.pgm |
Run install_geographiclib_dataset.sh script in order to install Geoid Model dataset!
解决方法:从github下mavros源码。源码中找到install_geographiclib_dataset.sh 使用root用户执行此脚本。
$ find . -name install*
./mavros/scripts/install_geographiclib_datasets.sh
安装时间很长。安装好之后,再次遇到同样的错误。发现安装目录在/usr/local/share/GeographicLib/ 而 launch读取路径是/usr/share/GeographicLib。拷贝一份到/usr/share/GeographicLib路径下。OK。
第二章 SITL仿真笔记
2.1.修改固件ardusub代码,重新编译
尝试修改一些log 在仿真环境中查看log是否更新
将AP_NavEKF2_Control.cpp 303行,改为 :
gcs().send_text(MAV_SEVERITY_INFO, "EKF2 IMU%u is using 9999 GPS",(unsigned)imu_index);
$ sim_vehicle.py -v ArduSub -w
APM: EKF2 IMU0 is using 9999 GPS
APM: EKF2 IMU1 is using 9999 GPS
Flight battery 100 percent
Log已经生效。哈哈。
切换到ardusub stable 分支
$git checkout ArduSub-stable
https://www.ardusub.com/developers/sitl.html
https://www.ardusub.com/developers/developers.html
作者:caiyunfreedom
原文:https://blog.csdn.net/CAIYUNFREEDOM/article/details/98217566
2.2.发送mavros指令,让SITL运动
~$ roslaunch mavros apm.launch 、
其中apm.launch已经按照1.1修改。
zhangym@zhangym:~$ rosrun mavros mavparam set SYSID_MYGCS 1
1
zhangym@zhangym:~$ rosservice call /mavros/cmd/arming 1
ERROR: Unable to communicate with service [/mavros/cmd/arming], address [rosrpc://zhangym:54203]
zhangym@zhangym:~$ rosservice call /mavros/cmd/arming 1
/opt/ros/kinetic/lib/python2.7/dist-packages/rosservice/__init__.py:607: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
service_args.append(yaml.load(arg))
success: True
result: 0
zhangym@zhangym:~$ rosrun mavros mavparam set SYSID_MYGCS 255
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/mavros/mavparam", line 104, in <module>
main()
File "/opt/ros/kinetic/lib/mavros/mavparam", line 100, in main
args.func(args)
File "/opt/ros/kinetic/lib/mavros/mavparam", line 63, in do_set
print(param_set(args.param_id, val))
File "/opt/ros/kinetic/lib/python2.7/dist-packages/mavros/param.py", line 146, in param_set
raise IOError(str(ex))
IOError: service [/mavros/param/set] responded with an error:
遇到一些错误, 重启,重试好了。
上图是发送指令后, 位置和速度的变化。
1./mavros/rc/override
Message: mavros_msgs/OverrideRCIn, send RC override message to FCU.
Channel Meaning 1500+ 1500-
1 Pitch 抬头 低头
2 Roll 往右翻转 往左翻转
3 Throttle 上升 下潜
4 Yaw 顺时针 逆时针
5 Forward 向前 向后
6 Lateral 右移 左移
7 Camera Pan(No signal in BlueRov)
8 Camera Tilt 向上 向下
Mavros control BuleROV
1.Set SYSID_MYGCS to 1 to enable override, QGC will lose control when SYSID_MYGCS is 1, setback to 255 to change control rights to QGC
rosrun mavros mavparam set SYSID_MYGCS 1
2.Mavros change mode of mavlink, ('Available modes: ', ['STABILIZE', 'POSHOLD', 'AUTO', 'GUIDED', 'MANUAL', 'SURFACE', 'ALT_HOLD', 'CIRCLE', 'ACRO'])
rosservice call /mavros/set_mode "base_mode: 0 custom_mode: 'GUIDED'"
3.Arming/unarming
rosservice call /mavros/cmd/arming 0
rosservice call /mavros/cmd/arming 1
4.Publish override rc
rostopic pub -1 /mavros/rc/override mavros_msgs/OverrideRCIn '[1500, 1500, 1500, 1500, 1500, 2000, 1500, 1500]
2.3.Mavros 修改频率
http://ardupilot.org/dev/docs/ros-data-from-ap.html
APSync的用户可能会注意到APWeb每10秒将数据流速率重置为4hz。这是一个已知的问题,可以通过编辑/etc/rc.local文件并注释掉启动APWeb的行来解决。
/etc/rc.local文件 是树莓派里的的文件..