在搭建用gazebo防真APM环境是需要安装ardupilot_gazebo插件,按照官网指南上的方法:
Plugin installation
The following plugin is a pure Gazebo plugin, so ROS is not needed to use it. You can still use ROS with Gazebo with normal gazebo-ros packages. We have two version of the plugin : khancyr and SwiftGust one’s. The one from khancyr is the original one. It is stable and only has necessary file to work. The one from SwiftGust has more examples and a little bit more documentation. Both use the same plugin, they only differ in the documentation and examples they provide.
We will be using khancyr plugin for the following exaplation. First clone it somewhere in your home directory. (If you need help with git, please see installed git, forked and cloned.)
git clone https://github.com/khancyr/ardupilot_gazebo
cd ardupilot_gazebo
mkdir build
cd build
cmake ..
make -j4 //当我进行到这一步时,报错了
sudo make install
报错结果
peter@peter-ThinkPad-X250:~/ardupilot_gazebo/bu$ make -j4
Scanning dependencies of target ArduCopterIRLockPlugin
Scanning dependencies of target ArduPilotPlugin
[ 25%] Building CXX object CMakeFiles/ArduCopterIRLockPlugin.dir/src/ArduCopterIRLockPlugin.cc.o
[ 50%] Building CXX object CMakeFiles/ArduPilotPlugin.dir/src/ArduPilotPlugin.cc.o
In file included from /usr/include/boost/type_index/stl_type_index.hpp:32:0,
from /usr/include/boost/type_index.hpp:29,
from /usr/include/boost/any.hpp:20,
from /usr/include/sdformat-6.2/sdf/Param.hh:21,
from /usr/include/sdformat-6.2/sdf/Element.hh:25,
from /usr/include/sdformat-6.2/sdf/sdf.hh:4,
from /home/peter/ardupilot_gazebo/src/ArduPilotPlugin.cc:41:
/usr/include/boost/variant/get.hpp: In instantiation of ‘typename boost::add_reference<T>::type boost::strict_get(boost::variant<T0, TN ...>&) [with U = short unsigned int; T0 = bool; TN = {char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, long unsigned int, unsigned int, double, float, sdf::Time, ignition::math::v4::Color, ignition::math::v4::Vector2<int>, ignition::math::v4::Vector2<double>, ignition::math::v4::Vector3<double>, ignition::math::v4::Quaternion<double>, ignition::math::v4::Pose3<double>}; typename boost::add_reference<T>::type = short unsigned int&]’:
/usr/include/boost/variant/get.hpp:284:25: required from ‘typename boost::add_reference<T>::type boost::get(boost::variant<T0, TN ...>&) [with U = short unsigned int; T0 = bool; TN = {char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, long unsigned int, unsigned int, double, float, sdf::Time, ignition::math::v4::Color, ignition::math::v4::Vector2<int>, ignition::math::v4::Vector2<double>, ignition::math::v4::Vector3<double>, ignition::math::v4::Quaternion<double>, ignition::math::v4::Pose3<double>}; typename boost::add_reference<T>::type = short unsigned int&]’
/usr/include/sdformat-6.2/sdf/Param.hh:300:31: required from ‘bool sdf::Param::Get(T&) const [with T = short unsigned int]’
/usr/include/sdformat-6.2/sdf/Element.hh:454:7: required from ‘std::pair<T, bool> sdf::Element::Get(const string&, const T&) const [with T = short unsigned int; std::__cxx11::string = std::__cxx11::basic_string<char>]’
/home/peter/ardupilot_gazebo/src/ArduPilotPlugin.cc:879:57: required from here
/usr/include/boost/variant/get.hpp:212:5: error: static assertion failed: boost::variant does not contain specified type U, call to boost::get<U>(boost::variant<T...>&) will always throw boost::bad_get exception
BOOST_STATIC_ASSERT_MSG(
^
CMakeFiles/ArduPilotPlugin.dir/build.make:62: recipe for target 'CMakeFiles/ArduPilotPlugin.dir/src/ArduPilotPlugin.cc.o' failed
make[2]: *** [CMakeFiles/ArduPilotPlugin.dir/src/ArduPilotPlugin.cc.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/ArduPilotPlugin.dir/all' failed
make[1]: *** [CMakeFiles/ArduPilotPlugin.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[ 75%] Linking CXX shared library libArduCopterIRLockPlugin.so
[ 75%] Built target ArduCopterIRLockPlugin
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
解决办法
在查询相关资料后发现这个编译错误是ubuntu 16.04自带的BOOST版本低导致的,笔者想尝试了升级BOOST版本,但是不敢卸载老版本(之前卸载gcc的惨痛教训)
之后在github里看到有人说升级到18.04LTS就可以解决,但是笔者需要用ros kinetic,所以这个办法也行不通。
最后在那个帖子下面发现了一种很简单的解决办法
The problem seems to be the Boost Version, no idea how to fix it but as a workaround I modified the following file /usr/include/sdformat-6.2/sdf/Param.hh in line 300 as follows.
//更改Param.hh(只读文件)需要加权限
cd /usr/include/sdformat-6.2/sdf
sudo chmod a+w Param.hh
//终端运行以上命令,之后打开Param.hh文件修改以下内容
299 #if BOOST_VERSION < 105800
300 // _value = boost::get(this->dataPtr->value);
301 _value = boost::relaxed_get(this->dataPtr->value);
302 #else
303 _value = boost::relaxed_get(this->dataPtr->value);
304 #endif
随后问题解决