Society of Robots - Robot Forum

Software => Software => Topic started by: mlucia on December 17, 2009, 10:19:21 AM

Title: webbotlib question?
Post by: mlucia on December 17, 2009, 10:19:21 AM
Can someone point me to additional examples of working code using weblibbot?

I've gotten the $50 version to run, and now I want to do something new, but don't quite grasp how webbotlib would be used.

For example, let's say that I add a couple of bumper switches. Do I need to poll for those changes? Let assume that the right front bumper switch closes while driving forward. I want to:

stop
drive both left and right reverse for x time units
stop
drive right forward y units
drive both left and right forward
continue with previous task

Is that all accomplished in the appControl function with delays to manage the 'do this for x units of time' stuff?

Sorry for asking what is likely a really silly question, but thanks for any help.

-Mark

Title: Re: webbotlib question?
Post by: Admin on December 18, 2009, 02:26:07 AM
My Axon II uses WebbotLib. Tons of examples here:

http://www.societyofrobots.com/axon2/downloads/Axon_WebbotLib_examples.zip (http://www.societyofrobots.com/axon2/downloads/Axon_WebbotLib_examples.zip)
Title: Re: webbotlib question?
Post by: mlucia on December 18, 2009, 08:33:00 AM
Perfect! - Thanks
Title: Re: webbotlib question?
Post by: Webbot on December 18, 2009, 11:15:00 AM
Personally - I'd do it something like this.......

Code: [Select]
// Define some constants for each state
#define STATE_FORWARDS 0
#define STATE_REVERSING 1

// Global variable that indicates the current state
uint8_t state;

// How long to reverse for in microseconds ie this = 5 seconds
#define TIME_TO_REVERSE ((TICK_COUNT)5000000)

TICK_COUNT timer;

// Initialise the state to a known setting
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
  state = STATE_FORWARDS;
  return 0;
}

// Main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
    if(state == STATE_FORWARDS){
         .... Add code to set motors to go forwards
   
         if(bumped into something){
              state = STATE_REVERSE;
              timer = loopStart;   // Remember when we started reversing
         }
    }else if(state == STATE_REVERSE){
       ... Add code to set motors to go backwards
       if(clockHasElapsed(timer, TIME_TO_REVERSE ){
          ... We have reversed for 5 seconds so start going fwds again
          state = STATE_FORWARDS;
       }
    }

}

You will need to expand the code so that once reversing has finished then it uses another state to turn right for a given time before going forwards again but hopefully the above gives you a clue.