Shop OBEX P1 Docs P2 Docs Learn Events
Please help me! How can I set the servo port P16 and P17 to drive PING))) and front servo? — Parallax Forums

Please help me! How can I set the servo port P16 and P17 to drive PING))) and front servo?

I am recently stuck on my project to develop a Smart Car with Activity Board. I built the car as indicated in pictures. I used servo port P12 and P13 for right and left high speed servos to drive wheels; and P14 and P15 to drive right and left encoders. In addition, I built a front servo to drive for the mounted PING))) at front, fed from servo port's regulated 5V. However my question is how can I set P16 and P17 on the servo ports to drive mounted PING))) and front servo? I looked in the 'abdrive.h' library and only find cal_encoderPins() and cal_servoPins() which are used only for the wheels and encoders.
1000 x 1000 - 1M
3024 x 4032 - 2M

Comments

  • kwinnkwinn Posts: 8,697
    You need to post the code you are using.
  • You should connect the 3 conductor cable from the servo to the P16 servo header, with it set for 5v. and use the servo tutorial to point the servo where you want. See: learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-devices/standard-servo

    Connect the Ping cable to the breadboard as shown in the ping tutorial:
    learn.parallax.com/tutorials/robot/activitybot/activitybot/navigate-ultrasound/build-and-test-ping-sensor-circuit

    Have your program turn the servo to point ping where you want. Wait until it moves to that position. take a ping reading. rotate again, ping again, etc.

    This is a link to a thread where I show code that I wrote to make a map of an area using the activitybot, ping, the ping servo, and an SD memory card to save the data. forums.parallax.com/discussion/161231/help-with-activity-bot-and-ping-bracket

    The program just combines programs from a number of the activitybot tutorials.

    It works as follows. Place the activitybot facing in direction you want to be a baseline. Start the program. The bot will turn to left 90 deg. It will then start to scan the area in 5 degree increments getting a ping measurement of any obstacles. When finished, it will save the data to the memory card, turn right 90 deg and move a distance along the baseline. It will then stop, rotate left 90 deg and repeat the scan from the new position, again saving the data. Once the data is saved the user can load the data into a plotting program (I used excel) to make a rudimentary map.

    That program should show you how to ue the ping and servo bracket. Note that it was written a few years ago when I was learning how to program the activitybot, so could be cleaned up. I also noticed that it used an early version of the simpleide library so there is a function that no longer exists (I explain how to fix it in the thread), but that is only used for storing data to the SD card so that section could be removed.

    Tom
  • Hello Tom, thank you so much for showing me the rope! I have re-edited your code with some minor changes. ALSO thanks for your excellent explanation on the itao() and sprint()! The code is follows:
    /*
    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); // Set PING))) servo's step by 1 degree/20 ms

    drive_goto(-25, 26); // Turn Left 90 deg & stop
    pause(2000); // Wait for 2 seconds
    //drive_ramp(0, 0);

    FILE* fp = fopen("test1.txt", "w"); // Open a file for writing

    servo_setramp(16, 40); // Ramp up the PING))) servo to 40 deg per update, faster moving servo to 0 deg
    servo_angle(16, 0); // Starts PING))) servo to 0 degree
    pause(1000); // Allow 1 second to get there
    servo_setramp(16, 10); // Set back PING))) servo to ramp down to 10 deg per update

    for(int deg = 0; deg <= 1800; deg += 50) // use for instead of while for PING))) servo degree update
    {
    servo_angle(16, deg); // Ramps PING))) servo from 0 to 180 deg
    pause(150); // Stay still for 0.15 sec after each time PING))) servo moves for ABOT to update PING)))

    int cmDist = ping_cm(0); // Get cm distance from Ping)))
    print("cmDist = %d\n", cmDist); // Display distance
    pause(100); // Wait 0.1 second

    // The next statements change a number to text and save it in a format that excel can use

    int n = sprinti(&adeg, "%d", deg); // Convert degree into strings format (of characters) to be input to text file
    //itoa(deg, adeg, 10);
    fwrite(&adeg, 5, 1, fp); // Write degree strings to SD card
    fwrite(",", 1, 1, fp); // Write comma separates columns

    int m = sprinti(&adist, "%d", cmDist); // Convert PING))) distance into strings format (of characters) to be input to text file
    //itoa(cmDist, adist, 10);
    fwrite(&adist, 5, 1, fp); // Write range formatted in strings to SD card
    fwrite("\n", 1, 1, fp); // Write newline next value will be in new row
    }

    servo_setramp(16, 40); // Reset PING))) servo to 40 deg per update
    servo_angle(16, 900); // Reset PING))) servo to 90 degree

    // end first scan
    drive_goto(26,-25);
    pause(2000); // Turn right 90 deg & stop
    //drive_ramp(0,0);

    drive_ramp(32,32); // Drive straight for 1 meter & stop
    pause(9900);
    drive_ramp(0,0);

    drive_goto(-25, 26); // Turn Left 90 deg & stop again
    pause(2000); // Stay still for 2 second
    //drive_ramp(0, 0);

    // start second scan
    servo_setramp(16, 40); // Ramp up the PING))) servo to 40 deg per update, faster moving servo to 0 deg
    servo_angle(16, 0); // Starts PING))) servo to 0 degree
    pause(1000); // Allow 1 second to get there
    servo_setramp(16, 10); // Set back PING))) servo to ramp down to 10 deg per update

    for(int deg = 0; deg <= 1800; deg += 50) // use for instead of while for PING))) servo degree update
    {
    servo_angle(16, deg); // Ramps PING))) servo from 0 to 180 deg
    pause(150); // Stay still for 0.15 sec after each time PING))) servo moves for ABOT to prepare to update PING)))

    int cmDist = ping_cm(0); // Get cm distance from Ping)))
    print("cmDist = %d\n", cmDist); // Display distance
    pause(100); // Wait 1/10 second for ABOT to prepare to convert integers to strings

    // The next statements change a number to text and save it in a format excel can use

    int o = sprinti(&adeg, "%d", deg); // Convert degree into strings format (of characters) to be input to text file
    //itoa(deg, adeg, 10);
    fwrite(&adeg, 5, 1, fp); // Write degrees to SD card
    fwrite(",", 1, 1, fp); // Write comma separates columns

    int p = sprinti(&adist, "%d", cmDist); // Convert PING))) distance into strings format (of characters) to be input to text file
    //itoa(cmDist, adist, 10);
    fwrite(&adist, 5, 1, fp); // Write range formatted in strings 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 PING))) servo to 20 deg per update
    servo_angle(16,900); // Ramp PING))) servo to 90 degrees
    pause(2500); // Stand still for 2.5 seconds
    servo_stop(); // Stop servo process
    }

  • I still have a question on how did you import the data to excel file and get the plot from SD card? How can I access the SD memory and read the blocks of data from ABOT?
  • twm47099twm47099 Posts: 867
    edited 2017-03-17 13:19
    I don't have the excel file or results on a computer that I have access to now. I'll try to re-write it this weekend. But here's the general idea.

    Remove the SD card from the bot and put it in a PC card reader.
    The SD file is a text file so you can import it into excel using "data", "get external data", "from text"

    Position the data however you want. I think I just put it into 2 columns deg & distance, the second data set (after the bot traveled) is under the first.

    Then just convert the degrees and distance into x & y .
    Then adjust the second measurement's x to bring it to the same origin as the first data set. (just subtract the distance traveled by the bot between data sets.) Then plot the x & y data. You will get an approximation of the shape of the obstacles. Try playing with the distance traveled by the bot, and the plotting method and maybe the number of data sets to try to improve the detail of the map.

    I'd like to see your results.
    Tom

  • hans90hans90 Posts: 29
    edited 2017-03-17 22:43
    Hello Tom, thanks for the reply! I have figured importing data from SD card to my PC.

    Included is my excel data analysis. Note the red plot is the first scan and blue plot is the second scan. Because the ABOT has traveled for 1m, I added the distance to the second scan's x column.

    Thanks!
  • Good work.
    When I did my scans, I had placed a couple of rounded objects in the rectangular area to be mapped that was surrounded by cabinets. I subtracted the distance traveled from the x-reading of the second scan. This brought the origin of the 2 scans together and gave an indication of the shape of the objects since the ultrasound would hit different aspects of the objects. (the differences in the x-distances of each showed the approximate width of the object and the y-values showed its depth dimension.)

    I took your spreadsheet and changed the +100 to -100 in the x calculation of the second set of data. It did bring one of the blue slanted lines together with part of the red slanted line (separated by about 10 to 20 cm).
    What did the area mapped look like? If you subtract 100 from x does the map resemble the actual area?

    Tom
  • hans90hans90 Posts: 29
    edited 2017-03-18 01:48
    I have also subtracted 100 from X and the plot looks like following:

    I actually started my ABOT along the wall on the left side. In the first scan, ABOT ran near a cart on the left side and the cart's bottom was scanned in. The ABOT then moved out of cart's sight and it scanned the long wall instead. I think the part of the plot actually fall in the same line, same as yours:)
Sign In or Register to comment.