我正在使用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