And that is what I did.
Within gaitRunnerProcess():
// Update the current time with the new interval
int16_t currentTime = runner->currentTime + interval;
if(currentTime >= runner->totalTime){
// We have finished playing the animation
if(pgm_read_byte(&animation->sweep)==FALSE){
currentTime %= runner->totalTime; // Set back to start of loop
if(runner->repeatCount){
runner->repeatCount -= 1; // One less frame to go
if(runner->repeatCount==0){
runner->playing = FALSE; // we have reached the end
currentTime = 0; // set servos to final position
}
}
///////NEW CODE
}else if(pgm_read_byte(&animation->sweep)==2){
currentTime = runner->totalTime;
///////END NEW CODE
}else{
// Start going backwards through the animation
currentTime = runner->totalTime - (currentTime - runner->totalTime);
runner->backwards = TRUE;
}
And then at the end of that function I added:
if( currentTime == runner->totalTime && pgm_read_byte(&animation->sweep) == 2) {
runner->playing = FALSE; // we have reached the end
}
It seems to work, for both forward and backward play of the gait. I have to modify the gait.h file, but I'm already doing that with a python script anyways.
-------------
An efficiency question... In C, (I tried looking on Stack Overflow, but probably didn't have the best search terms)
Assuming that
if(int8var)is faster to evaluate than
if(int16var)is it faster to do:
if(int8var && int16var)than
if(int16var && int8var)Which is to say, does the compiled bytecode know to skip on to the next piece of logic if the first comparison in an && statement is false? I know that Python does this, but I'm unaware of whether this is a high-level language thing or not.
More concretely, should I reverse the comparison order in that if statement in
if( currentTime == runner->totalTime && pgm_read_byte(&animation->sweep) == 2)? (This is more curiosity than the efficiency actually mattering in this case, I think)