【发布时间】:2017-06-06 16:34:59
【问题描述】:
我正在从事一个涉及红外信号处理和控制伺服系统的 Arduino Mega 2560 项目。但是下面这个简单的草图会产生一个错误,说某个字段被多次定义。
重现错误的代码:
#include <Servo.h>
#include <IRremote.h>
void setup() { }
void loop() { }
错误描述:
libraries\IRremote\IRremote.cpp.o (symbol from plugin): In function `MATCH(int, int)':
(.text+0x0): multiple definition of `__vector_32'
libraries\Servo\avr\Servo.cpp.o (symbol from plugin):(.text+0x0): first defined here
c:/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
我该如何解决这个问题?
更新/解决方案:
伺服库在ServoTimers.h中有如下定义:
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t;
基本上,前 12 个舵机由 timer 5 控制。如果您需要更多舵机,还可咨询timer 1 以获取舵机 13-24 等。Arduino Mega 2560 上的标准舵机库最多可以控制 48 个舵机(每个定时器 12 个)。
IRremote 库使用定时器 2 来接收 IR 信号。这与Servo库基本不冲突。但是我已经将 IRremoteInt.h 更改为使用 timer 3 而不是 timer 2,因为我还使用了中断驱动的超声波传感器(在 timer 2 上)。这就是我遇到上述问题的原因。
由于我的项目使用的伺服系统不超过 12 个,我只是禁用了伺服库中的计时器 1、3、4,从而产生以下行(cp. 到上面的原始行):
typedef enum { _timer5, _Nbr_16timers } timer16_Sequence_t;
这会导致更多错误,因为枚举不再完整...如果您想这样做,只需注释掉尝试编译草图时弹出的错误代码行。然后重新编译,一切都会好起来的。
现在一切正常,超声波传感器、伺服系统和红外接收。谢谢。
【问题讨论】:
标签: arduino