Hardware Guides

  Home arrow Hardware Guides arrow Page 9 - Zip-Bam-Bot Version XK2
Watch our Tech Videos 
Dev Hardware Forums 
Computer Cases  
Computer Processors  
Computer Systems  
Digital Cameras  
Flat Panels  
Gaming  
Hardware Guides  
Hardware News  
Input Devices  
Memory  
Mobile Devices  
Motherboards  
Networking Hardware  
Opinions  
PC Cooling  
PC Speakers  
Peripherals  
Power Supply Units  
Software  
Sound Cards  
Storage Devices  
Tech Interviews  
User Experiences  
Video Cards  
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HARDWARE GUIDES

Zip-Bam-Bot Version XK2
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 13
    2004-09-29

    Table of Contents:
  • Zip-Bam-Bot Version XK2
  • Constructing Subassemblies for XK2
  • Head Subassembly
  • Back Skid Subassembly
  • Light Sensor Subassembly
  • Putting XK2 Together
  • Formulating a Solid Programming Solution for XK2
  • Programming XK2 with the Solution
  • Creating a Program for the Ram-and-Run Approach
  • Testing XK2
  • Considering the Pros and Cons of XK2ís Design

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     

    SEARCH DEV HARDWARE

    Zip-Bam-Bot Version XK2 - Creating a Program for the Ram-and-Run Approach


    (Page 9 of 11 )

    Whether you call it ram-and-run or hit-and-run, this approach resembles a sort of guerrilla warfare. Once the touch sensor has registered a hit, the program backs up the sumo-bot, and then turns it around. The effectiveness of this approach (in terms of winning the round) is debatable, but it sure beats getting beat!

    To start off, letís modify our attacking function. Remember that once the touch sensors have registered a hit, XK2 needs to run in the opposite direction. With the addition of a slight amount of waiting time to allow the momentum of XK2 to do its work, the new Win() function looks like this:

    // constants
    #define BACK_TIME 50
    #define TURN 40

    // this function avoids the other sumo-bot
    void Win()
    {
      Wait(20);
      Rev(Left+Right);
      Wait(BACK_TIME);
      Fwd(Right); // this turns XK2 in the other direction
      Wait(TURN);
      OnFwd(Left+Right);
      ClearTimer(0);
    }

    With this function, XK2 will not continually ram, but instead will ram and run. Now how about that line-avoiding function? Modifying it, too, would not be such a bad idea. Instead of turning right, letís turn left, just to do something different. With this change, hereís the new line-avoiding function:

    // constants
    #define LIGHT_BACK 40
    #define TURN 40

    // this function avoids the line
    void Avoid()
    {
      OnRev(Left+Right);
      Wait(LIGHT_BACK);
      Fwd(Right);
      Wait(TURN);
      OnFwd(Left+Right);
      ClearTimer(0);
    }

    Thatís interesting, but for good measure, letís also modify the maneuvering function. A little change of the motor direction, a little change of the random timing, and we have ourselves a new version of the Change() function:

    // constant
    #define TURN 40

    void Change()
    {
      Rev(Right);
      Wait(TURN+Random(30));
       Fwd(Right);
      ClearTimer(0);
    }

    Now that we have made these changes, the new functions are combined into the program XK2_Access_Control_Two.nqc, which gives us a completed ram-and-run NQC program. Listing 5-2 shows the new program.

    Listing 5-2. XK2_Access_Control_Two.nqc

    // XK2_Access_Control_Two.nqc
    // A sumo-bot program for Zip-Bam-Bot Version XK2

    // motors
    #define Left OUT_A
    #define Right OUT_C

    // sensors
    #define LBump SENSOR_1
    #define RBump SENSOR_3
    #define See SENSOR_2

    // constants
    #define BACK_TIME 50
    #define TURN 40
    #define AMOUNT 3
    #define LIMIT 25
    #define LIGHT_BACK 40

    // variables for calibration
    int line=0,threshold=0;

    task main()
    {
      // initialize sensors
      SetSensor(LBump,SENSOR_TOUCH);
      SetSensor(RBump,SENSOR_TOUCH);
      SetSensor(See,SENSOR_LIGHT);

      // calibrate light sensor
      Calibrate();

      // start motors
      OnFwd(Left+Right);

      // letís clear the timer we are going to use
      ClearTimer(0);

      // start tasks
      start LWatch;
      start Crash;
      start Maneuver; 
    }

    // this task watches for the line task
    LWatch()
    {
       // highest priority
      SetPriority(0);

      // infinite loop
      while(true)
      {
        until(See<=threshold); // until we see the line

          acquire(ACQUIRE_USER_1) 
          {
            Avoid(); // avoid the line
          }
       }
    }

    // this task watches the touch sensors
    task Crash()
    {
      // second highest priority
      SetPriority(1);

      // infinite loop
      while(true)
      {
        // until left or right touch sensors are pressed
        until(LBump|RBump==1);

          acquire(ACQUIRE_USER_1)
          {
            Win(); // take control and crash repeatedly 
          }
      }
    }

    // this task introduces some random turns
    task Maneuver()
    {
      // third highest priority
      SetPriority(2);

      // infinite loop
      while(true)
      {
        // until timer is >= 2.5 seconds which is determined by LIMIT
        until(Timer(0)>=LIMIT);

          acquire(ACQUIRE_USER_1)
          {
            Change(); // execute our new function
          }
       }
    }

    // this function avoids the other sumo-bot
    void Win()
    {
       Wait(20);
      Rev(Left+Right);
      Wait(BACK_TIME);
      Fwd(Right); // this turns XK2 in the other direction
      Wait(TURN);
      OnFwd(Left+Right);
      ClearTimer(0);
    }

    // this function avoids the line
    void Avoid()
    {
      OnRev(Left+Right);
      Wait(LIGHT_BACK);
      Fwd(Right);
      Wait(TURN);
      OnFwd(Left+Right);
      ClearTimer(0);
    }

    // this function changes the direction of the robot
    void Change()
    {
      Rev(Right);
      Wait(TURN+Random(30));
      Fwd(Right);
      ClearTimer(0);
    }

    // this is the calibrating function
    void Calibrate()
    {
      until(RBump==1);
      line=See;
      threshold=line+AMOUNT;
      until(RBump==0);
      PlaySound(SOUND_CLICK);
      until(RBump==1);
      until(RBump==0);
      PlaySound(SOUND_CLICK);
      Wait(TURN);
    }

    There you have it: the essence of the ram-and-run approach. As you can see, the ram-and-run behavior itself is actually fairly simple. And watching it in action is quite interestingóso why don't we do some testing?

    This chapter is from Competitive MINDSTORMS: A Complete Guide to Robotic Sumo Using LEGO MINDSTORMS, by David Perdue (Apress, 2004, ISBN: 1590593758). Check it out at your favorite bookstore today. Buy this book now.

    More Hardware Guides Articles
    More By Apress Publishing

    blog comments powered by Disqus

    HARDWARE GUIDES ARTICLES

    - Top 10 Valentine`s Tech Gifts for Men
    - Top 10 Women`s Tech Gifts for Valentine`s Day
    - Intro to RAIDS
    - 2012`s Most Anticipated Tech Releases
    - Top Tech Stocking Stuffers for 2011
    - The Top Tech Gifts Under $100 for 2011
    - How to Improve Your Smartphone`s Battery Life
    - Top Holiday Tech Gifts for 2011
    - Quick Tips for PC Beginners
    - How To Overclock Your CPU
    - TrueCrypt Hidden OS: Completing the Decoy
    - TrueCrypt: Hiding Your Operating System
    - Creating a Hidden OS with TrueCrypt
    - Cloning Your Hard Drive: Implementing SysPre...
    - Cloning Hard Drives: Part Three

    Developer Shed Affiliates

     




    © 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
    KEITHLEE2zdeconfigurator/configs/INFUSIONSOFT_OVERLAY.phpzdeconfigurator/configs/ OFFLOADING INFUSIONSOFTLOADING INFUSIONSOFT 1debug:overlay status: OFF
    overlay not displayed overlay cookie defined: TI_CAMPAIGN_1012_D OVERLAY COOKIE set:
    status off