2

Author Topic: webbotlib question?  (Read 1061 times)

0 Members and 1 Guest are viewing this topic.

Offline mluciaTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
webbotlib question?
« 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


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: webbotlib question?
« Reply #1 on: December 18, 2009, 02:26:07 AM »

Offline mluciaTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: webbotlib question?
« Reply #2 on: December 18, 2009, 08:33:00 AM »
Perfect! - Thanks

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 109
Re: webbotlib question?
« Reply #3 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.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list