I'm starting using/playing with arduino since a month (Arduino starterkit). I would like to make an Hexapodes robot and for mecanical reason, I would like to use the freewheel mode of servos (0V on the input signal).
For that I found a first solution (on this forum I guess) which is to detach and attach again the servo witch I found not nice. Then I had a look at the library and added the function as follows:
In Servo.cpp, I added the function freewheel() at the end
void Servo::freewheel()
{
servos[this->servoIndex].Pin.isActive = false;
}
I had to modify the function writeMicroseconds() by adding the first 3 lines.
void Servo::writeMicroseconds(int value)
{
//if the servo was in freewheel before
if( servos[this->servoIndex].Pin.isActive == false )
servos[this->servoIndex].Pin.isActive = true;
// calculate and store the values for the given channel
byte channel = this->servoIndex;
if( (channel < MAX_SERVOS) ) // ensure channel is valid
{
if( value < SERVO_MIN() ) // ensure pulse width is valid
value = SERVO_MIN();
else if( value > SERVO_MAX() )
value = SERVO_MAX();
value = value - TRIM_DURATION;
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
uint8_t oldSREG = SREG;
cli();
servos[channel].ticks = value;
SREG = oldSREG;
}
}
Declare de function in the header Servo.h
void freewheel(); // set the servo freewheel
And add the keyword in the keywords.txt
freewheel KEYWORD2
This looks to work. Then first question: is it a nice way to do it. Second question: can we add (and how) the function in the code so it comes by default and i don't have to tweak the system. Seeing some topics (like here) it could be helpful for other people.
Ben