Shop OBEX P1 Docs P2 Docs Learn Events
ActivityBot Bug — Parallax Forums

ActivityBot Bug

JessAJessA Posts: 2
edited 2014-04-27 21:37 in Learn with BlocklyProp
I have an activitybot. I am using the qti line sensors to make it follow a line. My servos wont run at the same speed in this program only. While running the programs off parallax.com the servos behave correctly. This is a school project. I called the help line they said to post on the forums for help.

Here is my code:

/*
http://learn.parallax.com/activitybot


*/


#include "simpletools.h" // Include simpletools header
#include "abdrive.h" // Include abdrive header




int qr, l, r;


int main() // main function
{




while(1)
{
high(4); //sets outputs high so capacitors will discharge
high(5);
high(6);
high(7);
//set_direction(4,1);
set_directions(4,7,1111); //pin set to output
pause(10);
//set_direction(4,1);
input(4);
input(5);
input(6);
input(7);
pause(10);
qr=get_states(4,7);


//print("%d ",qr);

if(qr==0) // Centered
{drive_ramp(0,0);
pause(1);
}


else if(qr==1) // Turn Right
{drive_speed(10,20);
pause(1);
}


else if(qr==2) // Centered
{drive_ramp(20,20);
pause(1);
}


else if(qr==3) // Turn Slight Right
{drive_speed(21,20);
pause(1);
}


else if(qr==4) // Turn Slight Left
{drive_speed(20,25);
pause(1);
}


else if(qr==5) // Centered
{drive_ramp(20,20);
pause(1);
}


else if(qr==6) // Centered
{drive_ramp(20,20);
pause(1);
}


else if(qr==7) // Turn Slight Right
{drive_ramp(20,10);
pause(1);
}


else if(qr==8) // Turn Left
{drive_ramp(0,25);
pause(1);
}


else if(qr==9) // Centered
{drive_ramp(15,20);
pause(1);
}


else if(qr==10) // Centered
{drive_ramp(15,20);
pause(1);
}


else if(qr==11) // Centered
{drive_ramp(10,25);
pause(1);
}


else if(qr==12) // Turn Slight Left
{drive_speed(15,30);
pause(1);
}


else if(qr==13) // Centered
{drive_ramp(15,20);
pause(1);
}


else if(qr==14) // Turn Slight Left
{drive_speed(15,20);
pause(1);
}


else if(qr==15);
{drive_ramp(0,0); //Stop
pause(1);
}




print("%d ",qr);


}
}

Comments

  • edited 2014-04-25 13:27
    I deleted my other two replies that had hints to getting the application working and replaced them with this. Reason being, you should really have the benefit of code examples equivalent to what the product docs provide for the BASIC Stamp. So, here are the example programs for our QTI Line follower product, ported to Propeller C for use with the ActivityBot.

    Mount all the QTIs so that they are edge-to-edge on the front of your ActivityBot, as shown in the product documentation: http://www.parallax.com/sites/default/files/downloads/28108-QTI-Line-Follower-Guide-v2.0.pdf.

    Use this program with the black line on page 5 of the product documentation, (or with black vinyl electrical tape on white paper or poster board). Keep in mind that the far-left QTI connected to P7 should be the one closest to the wheel by the Activity Board's servo ports. The middle-left QTI should be connected to P6, and mounted next to the far-left QTI. Then the P5 QTI is middle-right, and the P4 QTI is far-right, closest to the other wheel.

    * Click SimpleIDE's New Project button and save it as Test QTIs.

    * Paste the code in the box below over the template code that comes with New Project.

    * Use SimpleIDE's Run with Terminal button to run TestQTIs.

    * Verify that you see these patterns for the QTIs when a given sensor is over the black stripe:

    1000...Far-left only
    1100...Far-left and middle-left
    0110...Middle-left and middle-right
    0011...Middle-right and far right
    0001...Far-right only
    /* 
      Test QTIs.c
    */
    
    #include "simpletools.h"                       // Include libraries
    #include "abdrive.h"
    
    int getQTIs(int highPin, int lowPin);          // Forward declare function
    
    int main()                                     // Main function
    {
      while(1)                                     // Main loop
      {
        int qtis = getQTIs(7, 4);                  // Check QTIs
        print("%c       FMMF \n", HOME);           // Home, display (F)ar, (M)iddle
        print("       LLRR \n");                   // Display (L)eft, (R)ight 
        print("QTIs = %04b \n", qtis);             // QTI detections as binary val
        pause(200);                                // Repeat after 1/5 s
      }
    }
    
    int getQTIs(int highPin, int lowPin)           // Function - getQTIs
    {
      int dt = (CLKFREQ / 1000000) * 230;          // Set up 230 us time increment
      set_outputs(highPin, lowPin, 0b1111);        // highPin...lowPin set high
      set_directions(highPin, lowPin, 0b1111);     // highPin...lowPin set to output
      waitcnt(dt + CNT);                           // Wait 230 us
      set_directions(highPin, lowPin, 0b0000);     // highPin...lowPin st to input
      waitcnt(dt + CNT);                           // Wait 230 us
      int qtis = get_states(highPin, lowPin);      // Get 4-bit pattern QTIs apply 
      return qtis;                                 // Return val containing pattern
    }
    


    Assuming you have followed the instructions in the ActivityBot Tutorial (http://learn.parallax.com/activitybot) up through Calibration (http://learn.parallax.com/activitybot/calibrate-your-activitybot), this code should do a nice job of following a black vinyl electrical tape stripe on a white background.

    * Click SimpleIDE's Save Project As button, and set the File name to Line Follow with QTIs.

    * Paste the code in the box below over all the code that's currently in SimpleIDE.

    * Use SimpleIDE's Load EEPROM & Run button to load the program into the ActivityBot.

    * You can now disconnect the programming cable, set the PWR switch to 2, and set it on your line course.
    /* 
      Line Follow with QTIs.c
    */
    
    #include "simpletools.h"                       // Include libraries
    #include "abdrive.h"
    
    int getQTIs(int highPin, int lowPin);          // Forward declare function
    
    int main()                                     // Main function
    {
      while(1)                                     // Main loop
      {
        int qtis = getQTIs(7, 4);                  // Check stripe position
        if(qtis == 0b1000) drive_speed(-64, 64);   // Far left, rotate left
        if(qtis == 0b1100) drive_speed(0, 64);     // Left, pivot left
        if(qtis == 0b0100) drive_speed(32, 64);    // A little left, curve left
        if(qtis == 0b0110) drive_speed(64, 64);    // Stripe centered, forward
        if(qtis == 0b0010) drive_speed(64, 32);    // A little right, curve right
        if(qtis == 0b0011) drive_speed(64, 0);     // Right, pivot right
        if(qtis == 0b0001) drive_speed(64, -64);   // Far right, rotate right
      }
    }
    
    int getQTIs(int highPin, int lowPin)           // Function - getQTIs
    {
      int dt = (CLKFREQ / 1000000) * 230;          // Set up 230 us time increment
      set_outputs(highPin, lowPin, 0b1111);        // highPin...lowPin set high
      set_directions(highPin, lowPin, 0b1111);     // highPin...lowPin set to output
      waitcnt(dt + CNT);                           // Wait 230 us
      set_directions(highPin, lowPin, 0b0000);     // highPin...lowPin st to input
      waitcnt(dt + CNT);                           // Wait 230 us
      int qtis = get_states(highPin, lowPin);      // Get 4-bit pattern QTIs apply 
      return qtis;                                 // Return val containing pattern
    }
    


    Once your application is running, try experimenting with higher speeds (up to 128).
  • JessAJessA Posts: 2
    edited 2014-04-26 14:06
    Thanks, it worked perfectly.
  • Ken GraceyKen Gracey Posts: 7,389
    edited 2014-04-26 16:14
    JessA wrote: »
    Thanks, it worked perfectly.

    Andy Lindsay is an amazing, creative, silled contributor and we are all thankful to have him assist us with our learning.

    Thanks again, Andy!

    Ken
  • ercoerco Posts: 20,256
    edited 2014-04-27 21:37
    Ken Gracey wrote: »
    Andy Lindsay is an amazing, creative, silled contributor and we are all thankful to have him assist us with our learning.

    Thanks again, Andy!

    Ken

    Amen, Ken. Next day service by Brother Andy! Might have been same day service had JessA posted before 7 pm. :)
Sign In or Register to comment.