Help with activity bot and ping bracket

dsomashedsomashe Posts: 19
edited June 2015 in Propeller 1 Vote Up0Vote Down
I am new to the activity bot but love it so far. I installed the ping bracket, but didn't have any idea how to begin having the bot sweep and ping to avoid obstacles. I was wondering if anyone knew where to find some example source code to help me get started with the ping bracket setup. I saw PINGDAR but I think that is for the STAMP microcontroller, not the propeller board. Is this correct? Thanks so much for any help!

Comments

  • 5 Comments sorted by Date Added Votes
  • twm47099twm47099 Posts: 553
    edited June 2015 Vote Up0Vote Down
    dsomashe wrote: »
    I am new to the activity bot but love it so far. I installed the ping bracket, but didn't have any idea how to begin having the bot sweep and ping to avoid obstacles. I was wondering if anyone knew where to find some example source code to help me get started with the ping bracket setup. I saw PINGDAR but I think that is for the STAMP microcontroller, not the propeller board. Is this correct? Thanks so much for any help!

    Look in the Learn sections of the Parallax website. In the C - Learning simple devices there is a section on Standard Servo. That will show how to sweep the Ping Bracket.

    In the ActivityBot section of Learn, there is a tutorial on Navigating using ultra sound.

    It is easy to navigate with the Ping in a fixed position. Using the bracket and rotating it requires that you rotate the bracket a few degrees. Stop the rotation. Take a ping reading, and then figure out what you want to do next.

    Be sure to read the tutorials show how much area ping covers and how the ultrasound reflects from an object. If the angle is too shallow, the reflection might not return directly to the Ping.

    When I got my bracket, the first program I wrote just mapped the area around the ABot.

    Hope this helps you get started.

    Tom
  • cavelambcavelamb Posts: 645
    edited June 2015 Vote Up0Vote Down
    Tom,

    Do you have an example of mapping the area around the bot that you could share?
  • twm47099twm47099 Posts: 553
    edited June 2015 Vote Up0Vote Down
    cavelamb wrote: »
    Tom,

    Do you have an example of mapping the area around the bot that you could share?

    I don't have access to my computers with the programs on it today, but I'll try to post them later this week.
    Briefly, l place the ActivityBot in the direction I want to have a baseline and start the program. The ActivityBot turns 90 degrees to the left. The Ping is rotated 90 degrees to the right (pointing in the direction of the baseline). It the takes a distance reading, rotates a few degrees left, takes another reading, and repeats for a full 180 degrees. The data (angle and distance to whatever object is detected) is stored in a file on the SD card. The the ActivityBot turns 90 degrees to the right, travels along the baseline for a specific distance, stops, turns left 90 degrees, and repeats the measurements. That data is saved in another file on the SD card.

    Then I import the data files into an excel spreadsheet, do some calculations combining the data from both locations and plot the data. By taking measurements from 2 locations you can get some idea of the location and shape of the objects.

    One of these days, I want to use ROBOT BASIC together with XBEE radios to transfer the data live from the ActivityBot to the PC and plot with ROBOT BASIC. But I have a lot to learn regarding the BASIC, and with my current list of robot projects and commitments at home and work, it will be a while before I get a chance to do that.

    Tom
  • twm47099twm47099 Posts: 553
    edited June 2015 Vote Up0Vote Down
    I've inserted the C code for my mapping program. It was one of my early learning experiences, and the code is not optimized, but it worked. I noticed that it uses the itoa() function which, based on another thread in this forum, is no longer supported by the latest Simple Libraries. The sprint() or sprinti() function would have to be substituted for itoa() where ever it is called. I'd also have to look at the parameters each function uses to make sure they are used correctly.

    atoi parameters are integer to convert, character string to hold converted digits, number base of the integer.

    int n = sprinti(buffer, "%d", x); // convert number to string, n is length, buffer is character array long enough to hold the integer digits, x is the integer, %d is the formatting which converts the decimal (base 10) representation of x. sprinti only works with integers and saves significant code space.

    The excel spreadsheet with a sample of the data is also attached. My earlier post where I stated that I used 2 SD files was incorrect. I just used one file and added the second scan data to the end of the first. Note in the spreadsheet where the 2nd scan begins (row 39 where the angle is zero), the formula for "x" changes by adding 86. That is to account for the distance moved by the Bot between scans. This was an early version of the spreadsheet, and I don't recall why I used 86, possibly that was the actual distance traveled?? The plot didn't turn out as well as I had hoped, I recall that I did improve on that somewhat. But I haven't been able to locate the disks where I had saved the spreadsheet.

    I hope that this gives you a starting point to work from if you are interested.

    Tom
    /*
     ping scan 0 - 180 save to sd.c
    
      Version 0.94 for use with SimpleIDE 9.40 and its Simple Libraries
      
      Moves servo to 0, to 180 degrees with 5 deg increments.  
      Measure distance w ping at each increment,
      Save degrees and distance to SD
    
      Uses ramping to gradually move the 
      servo to the target.
      
      learn.parallax.com/propeller-c-tutorials  
    */
    
    #include "abdrive.h"
    #include "simpletools.h"                      // Include simpletools header
    #include "servo.h"                            // Include servo header
    #include "ping.h"                             // Include ping header
    
    int DO = 22, CLK = 23, DI = 24, CS = 25;      // SD card pins on Propeller ABOT
    char adeg[5];                               // variables for text representation of numbers
    char adist[5];
    
    int main()                                    // main function
    {
      freqout(4, 2000, 3000);                       // Speaker tone: 2 s, 3 kHz
    
      sd_mount(DO, CLK, DI, CS);                  // Mount SD card
    
      servo_setramp(16, 10);                       // Change by up to 1 degree/20 ms 
    
      drive_ramp(-13, 13);                             //  Turn Left 90 deg & stop
      pause(2000);
      drive_ramp(0, 0);
    
    FILE* fp = fopen("test1.txt", "w");          // Open a file for writing
     
      servo_setramp(16, 40);
      servo_angle(16, 0);                         // P16 servo to 0 degrees
      pause(1000);                                    // Allow 1 second to get there
      servo_setramp(16, 10);
    
      for(int deg = 0; deg <= 1800;  deg += 50)   // use for instead of while
      {
        servo_angle(16, deg);                      // P16 servo to deg degrees
        pause(150);
    
        int cmDist = ping_cm(5);                 // Get cm distance from Ping)))
    //    print("cmDist = %d\n", cmDist);           // Display distance
        pause(100);                               // Wait 1/10 second
    
    // The next statements change a number to text and save it in a format excel can use
    
        itoa(deg, adeg, 10);
        fwrite(&adeg, 5, 1, fp);                              // Write degrees to SD card
        fwrite(",", 1, 1, fp);                              // Write comma  separates columns
    
        itoa(cmDist, adist, 10);
        fwrite(&adist, 5, 1, fp);                     // Write range to SD card
        fwrite("\n", 1, 1, fp);                              // Write newline  next value will be in new row
       }
                                                        // end first scan
      drive_ramp(13,-13);
      pause(2000);                                // Turn right 90 deg & stop
      drive_ramp(0,0);
    
      drive_ramp(32,32);                      //  Drive straight for 1 meter
      pause(9900);
      drive_ramp(0,0);
    
      drive_ramp(-13, 13);                       //  Turn Left 90 deg & stop
      pause(2000);                                  // for second scan
      drive_ramp(0, 0);
     
                                                      // start second scan
      servo_setramp(16, 40);
      servo_angle(16, 0);                         // P16 servo to 0 degrees
      pause(1000);                                    // Allow 1 second to get there
      servo_setramp(16, 10);
    
      for(int deg = 0; deg <= 1800;  deg += 50)   // use for instead of while
      {
        servo_angle(16, deg);                      // P16 servo to deg degrees
        pause(150);
    
        int cmDist = ping_cm(5);                 // Get cm distance from Ping)))
    //    print("cmDist = %d\n", cmDist);           // Display distance
        pause(100);                               // Wait 1/10 second
    
    // The next statements change a number to text and save it in a format excel can use
    
        itoa(deg, adeg, 10);
        fwrite(&adeg, 5, 1, fp);                              // Write degrees to SD card
        fwrite(",", 1, 1, fp);                              // Write comma  separates columns
    
        itoa(cmDist, adist, 10);
        fwrite(&adist, 5, 1, fp);                     // Write range to SD card
        fwrite("\n", 1, 1, fp);                              // Write newline  next value will be in new row
      }
    
      fclose(fp);                                 // Close file test
      servo_setramp(16, 20);              // speed up servo
      servo_angle(16,900);
      pause(2500);
      servo_stop();                               // Stop servo process  
    }
    
    
    

    TEST2.xls
  • a possible extension to this could be a two fold scenario:
    - record of a labyrinth at slow speed
    - exit the maze at full speed with data recorded.
Sign In or Register to comment.