在 Arduino DUE 上编译 EKfilter C++ 库时出现问题

Trouble Compiling EKfilter C++ Library on Arduino DUE

更新:通过将 operator[] 实际替换为 this->operator[] 来修复最终错误。

更新 2:logic_error 已修复! _P 错误就是剩下的一切! (它只出现在 DUE 中,而不是 UNO 或其他板...)

更新 3:将临时矩阵的名称更改为 _Pt 有效,可能是保留的宏?

新错误:

Arduino: 1.6.1 (Mac OS X), Board: "Arduino Due (Programming Port)"

/Users/zackbright/Documents/Arduino/libraries/StandardCplusplus-master/func_exception.cpp: In function 'void std::__throw_bad_alloc()':
/Users/zackbright/Documents/Arduino/libraries/StandardCplusplus-master/func_exception.cpp:30:18: error: exception handling disabled, use -fexceptions to enable
        throw bad_alloc();
                       ^
Error compiling.

看来我需要使用 -fexceptions...

这份报告将包含更多信息 "Show verbose output during compilation" 在文件 > 首选项中启用。

这里有很多,但我希望付出一切是我应该做的,才能得到一个好的答案。

在 OSX.

上使用 Arduino 1.6.1 for arduino DUE

使用这个库来获取 std 命名空间 'https://github.com/maniacbug/StandardCplusplus/'

这是我在编译时遇到问题的库: 'http://kalman.sourceforge.net/index.php'

我已经将过滤器库移动到这种格式以便能够在 arduino 上使用它,现在至少可以在没有找到 header 文件的情况下进行包含:

如您所见,我不得不将文件重命名为 .h headers(不确定这到底有多么必要),并将文件夹重命名为与我的 .cpp 和 .h 相同的标题,当然,编辑所有随附的文件以不同方式引用文件: 例子

#include "kalman/ekfilter.hpp"
//the "kalman/" is because these used to be in a separate include folder

现在是这个:

#include "ekfilter.h"

所以,现在,当我尝试编译时:

#include <StandardCplusplus.h>
#include <ekfilter.h>

void setup() {
  // put your setup code here, to run once:
}

void loop() {
 // put your main code here, to run repeatedly:
}

我收到如下所示的一堆错误。

第一个错误真的让我抓狂,因为这个 StandardCplusplus 库应该处理 std:: 命名空间,而且我在该代码库中的实现没有任何明显的错误。

据我所知,_P 之后的大部分内容都是第一个错误阻止将 _P 变量转换为 kmatrix.h 中定义的矩阵的问题。奇怪的是,这可能指向一个解决方案,当我为 Arduino UNO 编译时,这些错误没有出现。

最后一对错误我什至不清楚它到底是什么意思。

Arduino: 1.6.1 (Mac OS X), Board: "Arduino Due (Programming Port)"

In file included from /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/kvector.h:37:0, from /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter.h:33, from TestKalmanLibrary.ino:2:

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ktypes.h:74:48: error: expected class-name before '{' token

struct KalmanError : public std::logic_error {
                                            ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ktypes.h: In constructor 'Kalman::KalmanError::KalmanError(const string&)': /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ktypes.h:82:9: error:

class 'Kalman::KalmanError' does not have any field named 'logic_error'

   : logic_error(message) {}
     ^

In file included from /Users/insertnamehere/Documents/Arduino/libraries/StandardCplusplus-master/cctype:19:0, from /Users/insertnamehere/Documents/Arduino/libraries/StandardCplusplus-master/istream:21, from /Users/insertnamehere/Documents/Arduino/libraries/StandardCplusplus-master/iostream:27, from /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/kvector.h:35, from /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter.h:33, from TestKalmanLibrary.ino:2: /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter.h: At global scope:

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter.h:807:20:

error: expected unqualified-id before numeric constant

 mutable Matrix _P;  //!< Temporary matrix.
                ^

In file included from /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter.h:817:0, from TestKalmanLibrary.ino:2: /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h: In member function 'void Kalman::EKFilter::init(Kalman::EKFilter::Vector&, Kalman::EKFilter::Matrix&)':

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:196:8: error:

request for member 'swap' in '16', which is of non-class type 'int'

 _P.swap(P_);
    ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h: In member function 'const Matrix& Kalman::EKFilter::calculateP() const': /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:435:10: error: request for member 'resize' in '16', which is of non-class type 'int'

   _P.resize(n, n);         // keep this resize
      ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:439:15: error: expression cannot be used as a function

     _P(i,i) = U(i,i);
           ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:443:17: error: expression cannot be used as a function

       _P(i,j)  = U(i,j)*U(j,j);
             ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:444:17: error: expression cannot be used as a function

       _P(i,i) += U(i,j)*_P(i,j);
             ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:444:35: error: expression cannot be used as a function

       _P(i,i) += U(i,j)*_P(i,j);
                               ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:447:19: error: expression cannot be used as a function

         _P(i,j) += U(i,k)*U(j,k)*U(k,k);
               ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:450:17: error: expression cannot be used as a function

       _P(j,i) = _P(i,j);
             ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:450:27: error: expression cannot be used as a function

       _P(j,i) = _P(i,j);
                       ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h: In member function 'virtual void Kalman::EKFilter::sizeUpdate()': /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:572:26: error: expression cannot be used as a function

       U(i,j) = _P(i,j);
                      ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:583:10: error: request for member 'resize' in '16', which is of non-class type 'int'

   _P.resize(n, nn);
      ^

/Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter_impl.h:586:17: error: expression cannot be used as a function

       _P(i,j) = U(i,j);
             ^

In file included from /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/kvector.h:34:0, from /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/ekfilter.h:33, from TestKalmanLibrary.ino:2: /Users/insertnamehere/Documents/Arduino/libraries/StandardCplusplus-master/string: In instantiation of 'std::basic_string::size_type std::basic_string::find_first_not_of(const std::basic_string&, std::basic_string::size_type) const [with Ch = char; Tr = std::char_traits; A = std::allocator; std::basic_string::size_type = unsigned int]': /Users/insertnamehere/Documents/Arduino/libraries/ekfilter/kvector_impl.h:66:42: required from here /Users/insertnamehere/Documents/Arduino/libraries/StandardCplusplus-master/string:518:64: note: declarations in dependent base 'std::vector >' are not found by unqualified lookup

                             if( Tr::eq(str[j], operator[](i)) ){
                                                            ^

/Users/insertnamehere/Documents/Arduino/libraries/StandardCplusplus-master/string:518:64: note: use 'this->operator[]' instead Error compiling.

所以这里有很多需要解决的问题,但这是我解决了库格式化方式的一些问题之后的全部内容:

我必须将 -fpermissive 添加到“/boards.txt”编译首选项

他们的代码中有一个无法编译的奇怪实现,我更改了这个:

// These are explicitly GNU C++ specific.

// This is the exception class we report -- "GNUCC++[=31=]".

const _Unwind_Exception_Class __gxx_exception_class
= ((((((((_Unwind_Exception_Class) 'G' 
  << 8 | (_Unwind_Exception_Class) 'N')
 << 8 | (_Unwind_Exception_Class) 'U')
    << 8 | (_Unwind_Exception_Class) 'C')
   << 8 | (_Unwind_Exception_Class) 'C')
  << 8 | (_Unwind_Exception_Class) '+')
 << 8 | (_Unwind_Exception_Class) '+')
<< 8 | (_Unwind_Exception_Class) '[=31=]');

对此:

const _Unwind_Exception_Class __gxx_exception_class = "GNUCC++[=32=]";

所有问题现已解决。

最后一个错误是通过在我的编译器标志中包含 -fexceptions 解决的。

感谢大家的帮助。