我正在使用Arduino ServoTimer2库(因为我也需要在同一个草图中使用VirtualWire库,我不知道这个问题是否也存在于常规的Servo库中,但我认为它附加Arduino伺服不移动
任何时候我打电话给servo.attach(pin)
,伺服器会从当前位置的任何位置移动到其范围的中间(1500微秒)。这是一个问题,因为我的Arduino需要定期连接和分离伺服器并重置回中心击败了我的项目的目的。
我读到那个调用servo.write(xxxx)
之前servo.attach(pin)
会导致它默认为xxxx而不是1500,但这似乎并不适用于我(我甚至不知道如何将工作,如果该引脚未连接...)。有任何想法吗?
*
编辑: 我的解决方案
由于djUniversal的答案,我得到它的工作,使附着在伺服不动。如果其他人想要做同样的事情,我所做的只是进入ServoTimer2.cpp
并注释掉initISR
方法的前三行。现在看起来是这样的:
static void initISR()
{
// for(uint8_t i=1; i <= NBR_CHANNELS; i++) { // channels start from 1
// writeChan(i, DEFAULT_PULSE_WIDTH); // store default values
// }
servos[FRAME_SYNC_INDEX].counter = FRAME_SYNC_DELAY; // store the frame sync period
Channel = 0; // clear the channel index
ISRCount = 0; // clear the value of the ISR counter;
/* setup for timer 2 */
TIMSK2 = 0; // disable interrupts
TCCR2A = 0; // normal counting mode
TCCR2B = _BV(CS21); // set prescaler of 8
TCNT2 = 0; // clear the timer2 count
TIFR2 = _BV(TOV2); // clear pending interrupts;
TIMSK2 = _BV(TOIE2) ; // enable the overflow interrupt
isStarted = true; // flag to indicate this initialisation code has been executed
}
只要我这样做并重新编译,伺服停止附着时立即移动和现在移动,只有当它被写入。
我很高兴为你工作。请记住,直到实际写入电机为止,您将不会有任何停止转矩,并且会在分离时手动将其推到的任何位置等待。 – djUniversal 2014-11-02 22:24:21
@dj通用谢谢,是的,这正是我想要它做的。 – Garrett 2014-11-03 14:30:19