help with understanding "endTime" on the Rapiro Demo code

Can someone please explain to me what exactly is happening in this section of the demo code? I am under the impression that endTime should[?] make the Rapiro Robot stop doing his motion, but I can't seem to make that work.

if(endTime > millis()) {
remainingTime = (endTime - millis()) / 10;
for( i = 0; i < MAXSN; i++) {
nowAngle = targetAngle - (deltaAngle * remainingTime);
servo.write((nowAngle >> SHIFT) + trim*);*
}
for( i = 0; i < 3; i++) {
nowBright = targetBright - (deltaBright * remainingTime);
analogWrite(eyes_, nowBright >> SHIFT);
}
} else if(mode == 'M') {
nextFrame();
} else if(mode == 'P') {
if(bufferTime > 0){
nextPose();
} else if(endTime + 500 < millis()){
//digitalWrite(POWER, LOW);
}
}
}_

Hi ghatch2

The millis() function gives the current "time" (measured in milliseconds since the program started).

Somewhere before this part of the code, the variable endTime should have been set to what was then the current time plus the desired number of milliseconds until this code gets executed.

Could you post your complete program. Use the code tags (the "#" button above the smileys) to make it easier to read.

Thanks

Ray

It will not let me attach the full code because it is too long, but it can be found here: GitHub - Ishiwatari/RAPIRO: RAPIRO Project

Thanks for the code.

I need to correct what I said before. The first piece of code you posted is executed UNTIL the current time reaches the time set in endTime.

That happens in this code which is at the end of the nextPose() function:

  startTime = millis();
  endTime = startTime + (bufferTime * 100);
  bufferTime = 0;

And bufferTime is set in the nextFrame() function:

  bufferTime = motion[motionNumber][frameNumber][TIME];

Hope that helps

Ray