Author Topic: [Solved] Gait Designer for changing final position at end of gait  (Read 1045 times)

0 Members and 1 Guest are viewing this topic.

Offline GertlexTopic starter

  • Supreme Robot
  • *****
  • Posts: 747
  • Helpful? 23
  • Nuclear Engineer Roboticist
With Gait Designer + GaitPlayer.h, etc., I'm trying to figure out how to do a gait that changes the final position of the bot.  For example, my bot starts standing on both 'feet'.  I want it to raise one foot, and then just stay that way.

However I'm not sure how this can be done.  The repeat setting has the Side-to-Side and Cycle settings.  With the former, you can set beginning and end positions differently, but when you do a single loop of the gait on the robot it goes from start position to end position and back to start position.  With the Cycle setting, your start and end positions are the same.

Am I missing something obvious?  I'd prefer to smoothly move the servo(s) to the desired position with a gait rather than have a separate chunk of code for this feature.

Thanks!
« Last Edit: August 27, 2012, 10:52:21 AM by Gertlex »
I

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,154
  • Helpful? 110
Re: Gait Designer for changing position
« Reply #1 on: August 26, 2012, 05:27:06 PM »
Can't you use gaitRunnerStop so that it stops running at the last frame in the animation
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline GertlexTopic starter

  • Supreme Robot
  • *****
  • Posts: 747
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Gait Designer for changing position
« Reply #2 on: August 26, 2012, 06:09:35 PM »
Dang. Thanks :)  Forgot that method was there, and might not have made the connection right away if I'd seen it.

Edit: Upon testing, I don't think this is the solution.  My interpretation of the code is that the gaitRunnerStop method isn't any different from already having repeatCount = 1...

In Cycle mode, repeat count 1 will play the gait and set the starting position at the end.  In Side-To-Side, with repeat count 1, you play gait forward and backward and end up at starting position.

I'm poking around in the code, and might change the sweep variable in a G8_ANIMATION struct to be 0,1,2 rather than true/false.
« Last Edit: August 26, 2012, 06:54:14 PM by Gertlex »
I

Offline GertlexTopic starter

  • Supreme Robot
  • *****
  • Posts: 747
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Gait Designer for changing position
« Reply #3 on: August 26, 2012, 07:56:20 PM »
And that is what I did.

Within gaitRunnerProcess():
Code: [Select]
// 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:
Code: [Select]
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
Code: [Select]
if(int8var)is faster to evaluate than
Code: [Select]
if(int16var)is it faster to do:
Code: [Select]
if(int8var && int16var)than
Code: [Select]
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
Code: [Select]
if( currentTime == runner->totalTime && pgm_read_byte(&animation->sweep) == 2)?  (This is more curiosity than the efficiency actually mattering in this case, I think)
I

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,154
  • Helpful? 110
Re: Gait Designer for changing position
« Reply #4 on: August 27, 2012, 06:34:22 AM »
Glad you got it going.

re efficiency. What you're saying makes  sense in that most compilers will turn the code into:
Code: [Select]
if (!firstPart) goto end
if(!secondPart) goto end
..both are true
:end
BUT unlike a scripting language the C compiler can do optimization so what is actually generated may well depend on the optimization setting you have given.  The only way to see what its doing is to look at the listing file ( normally ends with .lss or .lst) to see the assembly code the compiler has created.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline GertlexTopic starter

  • Supreme Robot
  • *****
  • Posts: 747
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: [Solved] Gait Designer for changing final position at end of gait
« Reply #5 on: September 18, 2012, 10:58:18 PM »
A quick update. My modifications above were incomplete.  I initially neglected to handle the case where the gait is played backwards.

Both parts of the nested if statement need to be modified:
Code: [Select]
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; //Triggers block at end of this function
///END NEW CODE
}else{
// Start going backwards through the animation
currentTime = runner->totalTime - (currentTime - runner->totalTime);
runner->backwards = TRUE;
}
}else if(currentTime < 0){
// We have moved before the start
if(pgm_read_byte(&animation->sweep)==FALSE){
currentTime = runner->totalTime + currentTime;
if(runner->repeatCount){
runner->repeatCount += 1; // One more frame to go
if(runner->repeatCount==0){
runner->playing = FALSE; // we have reached the end
currentTime = 0; // set servos to start position
}
}
///NEW CODE
}else if(pgm_read_byte(&animation->sweep)==2){
currentTime = 0; //Triggers block at end of this function
///END NEW CODE
}else{
// We have completed a sweep
runner->backwards = FALSE;
currentTime = -currentTime;

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 initial position
}
}
}
}

And then the bit at the end of the function grows to this:
Code: [Select]
///Stops gait when we get to the end of a sweep == 2 animation
if( pgm_read_byte(&animation->sweep) == 2) {
if( currentTime == runner->totalTime || currentTime == 0) {
// if (currentTime == runner->totalTime) {
// led = 1;
// }
// currentTime = 0; // affects nothing.
runner->playing = FALSE; // we have reached the end
runner->animation = NO_GAIT;

// if (currentPos != SIT_POS) {
// currentPos = START_POS;
// }

// led = 1;
}
}

I just spliced the above together. Should work... If not, similar working code can be found in this code: https://github.com/erelson/wixel-sdk/blob/master/apps/wireless_serial_twitch/wireless_serial.c
« Last Edit: September 18, 2012, 10:59:44 PM by Gertlex »
I

 


Get Your Ad Here

data_list